Doc #62446 [Com]: static call of non-static function breaks context of late static binding

From: Date: Fri, 29 Jun 2012 08:15:00 +0000
Subject: Doc #62446 [Com]: static call of non-static function breaks context of late static binding
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8513@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62446&edit=1 ID: 62446 Comment by: kantert at eventit dot ag Reported by: picht at eventit dot ag Summary: static call of non-static function breaks context of late static binding Status: Open Type: Documentation Problem Package: Documentation problem Operating System: ubuntu 2.6.32-41-server PHP Version: 5.3.14 Block user comment: N Private report: N New Comment: This is a simpler example: <?php class Inner { public static function internalStatic() { } public function NonStaticCalledStaticLate() { static::internalStatic(); } public function NonStaticCalledStaticSelf() { self::internalStatic(); } } class Outer { public function testWorking() { Inner::NonStaticCalledStaticSelf(); } public function testBroken() { Inner::NonStaticCalledStaticLate(); } } // Working Inner::NonStaticCalledStaticLate(); // Working Inner::NonStaticCalledStaticSelf(); $obj = new Outer(); // Working $obj->testWorking(); // Broken $obj->testBroken(); // PHP Fatal error: Call to undefined method Outer::internalStatic() in test.php on line 9 echo "Worked"; ?> Previous Comments: ------------------------------------------------------------------------ [2012-06-29 08:03:11] picht at eventit dot ag I mixed up "Expected result" and "Actual result". They should be the other way around. Sorry for that! ------------------------------------------------------------------------ [2012-06-29 08:00:28] picht at eventit dot ag Description: ------------ When calling a non-static function statically the late static binding context still points to the calling class context. This should be documented on the static keyword page. Test script: --------------- <?php class a { public static function foo() { echo 'foo a'; } public function bar() { // expecting to call a::foo or b::foo // calls c::foo instead static::foo(); } } class b extends a { public static function foo() { echo 'foo b'; } } class c { public function test() { b::bar(); } public static function foo() { echo 'foo c'; } } $c = new c(); $c->test(); Expected result: ---------------- Documentation suggest b::foo will be called Actual result: -------------- Documentation warns about c::foo getting called ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62446&edit=1

« previous php.doc.bugs (#8513) next »