Re: Re: Classes and parents.

From: Date: Sat, 22 Jan 2005 17:02:18 +0000
Subject: Re: Re: Classes and parents.
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-207044@lists.php.net to get a copy of this message
Dmitry wrote:
Thanks, but I think that this code more easy. class a { function say() { echo "A"; } function run() { $this->say(); } } class b { function say() { echo "B"; } function run() {
    $a = new a;
    $a->run();
for starters b doesn't even extend a and secondly the b::run() method is creating an object on each invocation - not exactly good use of OO. besides which b::run() is creating an object of an arbitrary class, assuming b was supposed to extend a in your example above the you have hardcoded the parent into the subclass, thats plain wrong... my example wasn't a specific solution to your problem but an example of 3 ways to acomplish the goal of calling the version of a method in the super class. if you didn't understand something just ask.
    }
} $obj = new b; $obj->run();


« previous php.general (#207044) next »