note 20582 added to keyword.parent
| From: | php at earthside dot arg | Date: | Tue, 09 Apr 2002 02:05:56 +0000 |
| Subject: | note 20582 added to keyword.parent | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28985@lists.php.net to get a copy of this message | ||
Trying the technique shown above for chaining constructors. Below is a minimal example. Additional
tests (move 'echo $cls' above the '$this->$par()' call) show recursive calls
to bar(), since get_parent_class($this) always seems to resolve to baz....
#cat test.php
<?php
class foo {
function foo() {
$cls = get_class($this);
echo $cls."\n";
}
}
class bar extends foo {
function bar() {
$cls = get_class($this);
$par = get_parent_class($this);
$this->$par();
echo $cls."\n";
}
}
class baz extends bar {
function baz() {
$cls = get_class($this);
$par = get_parent_class($this);
$this->$par();
echo $cls."\n";
}
}
$o = new baz;
?>
#php test.php
Segmentation fault (core dumped)
#
It seemed like a good idea, but ... help?
--
change the 'a' to 'o' in the TLD to email
--
http://www.php.net/manual/en/keyword.parent.php
http://master.php.net/manage/user-notes.php?action=edit+20582
http://master.php.net/manage/user-notes.php?action=delete+20582
http://master.php.net/manage/user-notes.php?action=reject+20582