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 :)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php