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
https://forums.phpfreaks.com/topic/80208-calling-parent-class-problem-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.