Jump to content

Calling Parent Class Problem HELP!!!!!!!!


nvidia

Recommended Posts

Hi, i have created a class A & B, where B extends A. What i am trying to do is call the parent class function, operation with the given code


<html>
    <head>
        <title> Classname </title>
    </head>
<body>
<?php
  class A
  {
    var $attribute = "default value";
    
    function operation()
    {
        echo "Something <br />";
        echo "The value of \$attribute is $this->attribute <br />";
    }
  }
  
  class B extends A
  {
    
    var $attribute = 'different value';
    
    function operation()
    {
        
        echo "Something else<br />";
        echo "The value of \$attribute is $this->attribute";
        
    }
   parent::operation(); 
    
  }
  
  $a = new A();
  $a->operation();
  
  $b = new B();
  $b->operation();
  
  
  
?>
    
</body> 
</html>

 

But evertime i run the script i get the following error message

 


Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\wamp\www\php_sandbox\OOP\classname.php on line 30

 

can somebody tell me why this is happening and what i need to do to rectify it please.

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.