note 38891 added to keyword.parent
| From: | JamesSleeman at rn2 dot php dot net | Date: | Sat, 10 Jan 2004 11:27:25 +0000 |
| Subject: | note 38891 added to keyword.parent | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63250@lists.php.net to get a copy of this message | ||
It should be noted that when using parent:: you are able to call a method defined within the parent,
or any class that the parent is extending.. for example.
<?php
class A
{
function test()
{
echo 'Hello ';
}
}
class B extends A
{
}
class C extends B
{
function test()
{
parent::test();
echo 'Bobby.';
}
}
$D =& new C();
$D->test();
?>
Outputs "Hello Bobby.", the fact that B does not define test() means that A's test()
is called, it should also be noted that test() is called in the context of an 'A' class,
so if you try and call parent:: in A's test() it will correctly fail.
It's also worth noting that parent:: also works fine in a static method, eg <?php
C::test(); ?> still outputs "Hello Bobby.", and you can even do <?php B::test();
?> which correctly outputs "Hello ", even though we're calling a static method
that lives in an ancestor class!
----
Manual Page -- http://www.php.net/manual/en/keyword.parent.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38891
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38891&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38891&report=yes
Search -- http://master.php.net/manage/user-notes.php