Method inheritance and parent classes
| From: | Christian Weiske | Date: | Fri, 04 Aug 2006 16:46:28 +0000 |
| Subject: | Method inheritance and parent classes | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-25200@lists.php.net to get a copy of this message | ||
Hello all,
I recently had a problem that could be solved, but in an ugly way:
Class B extended Class A. Both classes define a method with the same
name. B called A's constructor, and A called $this->method(). This
executed B::method(), not A::method() as you would expect it.
<?php
class A {
function __construct() {
$this->build();
}
function build() {
echo "buildA ";
}
}
class B extends A {
function __construct() {
parent::__construct();
$this->build();
}
function build() {
echo "buildB ";
}
}
new B();
?>
output is: "buildB buildB "
expected would be: "buildA buildB "
I suggest changing the behavior of php to never call methods of classes
that are added by subclasses, only own ones or inherited ones.
--
Regards/MfG,
Christian Weiske
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc