# kelly.terry.jones@xxxxxxxxx / 2007-01-03 19:14:31 -0700: > I'm trying to implement what I think is called a "virtual method": my > abstract parent class ParentClass defines a method xxx that calls > method yyy, but yyy is defined only in ParentClass's children. > > I can't get this to work (PHP5.0.4). Sample code: > > === start sample code === > > abstract class ParentClass { > // xxx just returns 5 + whatever yyy() returns > public static function xxx () {return 5 + yyy();} > // all my children must define yyy() > abstract static function yyy(); > } > > abstract class ChildClass extends ParentClass { > public static function yyy () {return 7;} > } > > echo ChildClass::xxx(); > > === end sample code === > > When I run the above, I get this error: > > Fatal error: Call to undefined function yyy() in <file> on line 9 > > Changing the call from yyy() to self::yyy() gives a different error: > > Fatal error: Cannot call abstract method ParentClass::yyy() in <file> on > line 9 > > How to do this correctly? Without "static". Chances are the code would be better served by an instance anyway (static methods deprive you of polymorphism, as you just found out. -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php