Bug #61084 [Nab]: incorrect work with class variable (declared as static)
| From: | rasmus@php.net | Date: | Tue, 14 Feb 2012 17:19:52 +0000 |
| Subject: | Bug #61084 [Nab]: incorrect work with class variable (declared as static) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-167506@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61084&edit=1
ID: 61084
Updated by: rasmus@php.net
Reported by: lx at webactives dot ru
Summary: incorrect work with class variable (declared as
static)
Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Windows
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
I still don't see what is wrong. Forget the fact that you are calling a non-
static method statically. That has nothing to do with the inner access to the
static property. Because of Late-Static-Binding (see http://php.net/lsb)
static::$v will be late-bound to class C so you get the static value from C.
This is perfectly correct. If you use self::$v you will be early-bound to A
instead.
Other than the E_STRICT about calling a non-static method statically, you should
get no errors here because you are accessing a static property statically
correctly.
Previous Comments:
------------------------------------------------------------------------
[2012-02-14 17:01:15] lx at webactives dot ru
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.
?>
------------------------------------------------------------------------
[2012-02-14 16:24:44] rasmus@php.net
In PHP 5.3 E_STRICT is not included in E_ALL. Your code does give you an
E_STRICT. Use error_reporting(-1); at the top.
------------------------------------------------------------------------
[2012-02-14 15:19:12] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61084&edit=1