Re: Re: Classes and parents.

From: Date: Sat, 22 Jan 2005 18:28:05 +0000
Subject: Re: Re: Classes and parents.
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-207047@lists.php.net to get a copy of this message
Jochem Maas wrote:
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();
class a { function say() { echo "A"; } function run() { self::say(); } } class b { function say() { echo "B"; } function run() {
      parent::run();
} } would work fine though, I think :)

« previous php.general (#207047) next »