nvidia Posted December 5, 2007 Share Posted December 5, 2007 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 More sharing options...
trq Posted December 5, 2007 Share Posted December 5, 2007 This line... parent::operation(); needs to be within the operation() method. Link to comment https://forums.phpfreaks.com/topic/80208-calling-parent-class-problem-help/#findComment-406541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.