Re: Polymorphism in PHP

From: Date: Mon, 18 Feb 2002 20:12:34 +0000
Subject: Re: Polymorphism in PHP
Groups: php.general 
Request: Send a blank email to php-general+get-85265@lists.php.net to get a copy of this message
That's right, the difference between C++ "pure virtual" and "virtual" is that a virtual function has an implementation but pure virtual only defines an interface. But can we get back to my original PHP question: Can I do something like the following in php: class Base { function Foo() { echo "Base"; } } class Derived1 extends Base { function Foo() { echo "Derived1"; } } class Derived2 extends Base { function Foo() { echo "Derived2"; } } function Example ( $objvar ) { $objvar->Foo(); } ... $obj1 = new Base(); $obj2 = new Derived1(); $obj3 = new Derived2(); Example($obj1); Example($obj2); Example($obj3); I think what I am asking is, is there any concept of a virtual function in PHP, with a virtual function table? Rich -----Original Message----- From: Martin Towell [mailto:martin.towell@world.net] Sent: Sunday, February 17, 2002 5:31 PM To: php-general@lists.php.net Subject: RE: [PHP] Polymorphism question A bit late in replying - but what the hay (or is that "hey"??) oh well... >From my understanding of virtual functions (and it's been at least 3 to 4 years since I've done C++) is that a "virtual function" has basic functionality and a "pure virtual function" has no, and can't have, and code. Please correct me if I'm wrong Martin

« previous php.general (#85265) next »