#43499 [Fbk->Opn]: Inproper use of extending class method from extended class.

From: Date: Wed, 05 Dec 2007 16:41:54 +0000
Subject: #43499 [Fbk->Opn]: Inproper use of extending class method from extended class.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-120396@lists.php.net to get a copy of this message
ID: 43499 User updated by: bholbrook at servillian dot com Reported By: bholbrook at servillian dot com -Status: Feedback +Status: Open Bug Type: Scripting Engine problem Operating System: Linux Cent OS PHP Version: 5.2.5 New Comment: $oB->method2() should work, but the call $this->method3() from A::method1() should cause the same fatal error seen when calling it through $oC->method4(); Class A should have no knowledge of it's extending classes methods. Previous Comments: ------------------------------------------------------------------------ [2007-12-05 10:59:36] jani@php.net Output: I am method B::method2 I am method A::method1 I am method B::method3 I am method C::method4 I am method A::method1 Fatal error: Call to undefined method C::method3() in /home/jani/t.php on line 6 Exactly what is wrong in this? AFAICT, it works exactly how it's supposed to work. ------------------------------------------------------------------------ [2007-12-04 22:36:54] bholbrook at servillian dot com Description: ------------ In the example, class A gains a knowledge of it's extending classes functions. By allowing the call from the entended class to an extending class method, the extended class method becomes unavailable to any other extending class. The only time this makes sense is if class A were an abstract class and defined method3 as an abstract function. Reproduce code: --------------- <?php class A { public function method1(){ echo "I am method A::method1<br/>"; $this->method3(); } } class B extends A{ public function method2(){ echo "I am method B::method2<br/>"; $this->method1(); } public function method3(){ echo "I am method B::method3<br/>"; } } class C extends A{ public function method4(){ echo "I am method C::method4<br/>"; $this->method1(); } } $oB = new B(); $oB->method2(); $oC = new C(); $oC->method4(); ?> Expected result: ---------------- The expected result of $oB->method2(); is the current results of $oC->method4(); Actual result: -------------- Currently, $oB->method2() calls A::method1() (correct) which in turn calls B::method3() (incorrect). ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43499&edit=1

« previous php.bugs (#120396) next »