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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.