|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-04-08 05:30 UTC] rasmus@php.net
-Status: Open
+Status: Bogus
[2010-04-08 05:30 UTC] rasmus@php.net
[2010-04-08 05:45 UTC] phoenix at twistersfury dot com
[2010-04-08 05:58 UTC] rasmus@php.net
[2010-04-08 06:10 UTC] phoenix at twistersfury dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 08:00:01 2025 UTC |
Description: ------------ If you have a child class that overrides a parent class method, and call that method within the context of the parent, the parent's method is called first, then the child class. This always happens. If you call the method outside of the class, then the child's method is called, and the parent's method is only ran if you tell it to using parent:: If you add a third level of inheritance, under the same conditions, the parent class will still call first, but the lowest child is called, skipping those in between. Adding: ... class bar2 extends bar { public function foo() { echo 'in_child_2:'; } } $objClass = new bar(); ... Results in in_parent:in_child_2: Test script: --------------- <?php class foo { public function foo() { echo 'in_parent:'; } public function bar() { $this->foo(); } } class bar extends foo { public function foo() { echo 'in_child:'; } } $objClass = new bar(); $objClass->bar(); $objClass->foo(); ?> Expected result: ---------------- in_child:in_child: Actual result: -------------- in_parent:in_child:in_child: