|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-02-14 15:19 UTC] lx at webactives dot ru
Description:
------------
All configuration standard.
Test script:
---------------
<?
error_reporting(E_ALL);
class A {
static $v = '123';
function m(){
echo 'var is '.(static::$v);
}
}
class C {
function test(){
A::m();
}
}
$test = new C();
$test->test();
?>
Expected result:
----------------
PHP Fatal error: Access to undeclared static method: A::m() in test.php on line 11
OR
STRICT CLASSIC ERROR ONLY
Actual result:
--------------
PHP Fatal error: Access to undeclared static property: C::$v in test.php on line 6
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 03:00:01 2025 UTC |
I'm known it, but error message incorrect. You can see it on this code: <? error_reporting(E_ALL); class A { static $v = 'A'; function m(){ echo 'var is '.(static::$v); } } class C { static $v = 'C'; function test(){ A::m(); } } $test = new C(); $test->test(); //display incorrect "var is C" without any error. ?>yes, i'm use Late-Static-Binding, but why engine bind variable to class C in context of class A? I'm not extend C from A. I can modify my code for demonstrate necessity late binding: <? error_reporting(E_ALL); class A { static $v = 'A'; function m(){ echo 'var is '.(static::$v); } } class B extends A{ // for use Late-Static-Binding static $v = 'B'; } class C { static $v = 'C'; function test(){ B::m(); } } $test = new C(); $test->test(); ?> Of course, I'm can correctly use static keyword before method m() and problem have solved. But current engine behavior make work logic unpredictable. In doc I have read: "In case of static method calls, this is the class explicitly named (usually the one on the left of the :: operator);" Why PHP engine bind variable context for object caller class and not for class method owner?