Edit report at http://bugs.php.net/bug.php?id=52225&edit=1
ID: 52225
Comment by: + at ni-po dot com
Reported by: lucato at gmail dot com
Summary: __get() and __set() for static classes
Status: Open
Type: Feature/Change Request
Package: Class/Object related
Operating System: Any
PHP Version: 5.3.2
Block user comment: N
New Comment:
@henrik: This is about static property overloading, not about late
static binding ;)
Previous Comments:
------------------------------------------------------------------------
[2010-07-08 14:45:42] henrik at bearwoods dot dk
In 5.3 it works if you change self:: to static:: like this
Test:
<?php
class A {
static $data = array('bar' => 99, 'foo' => 101);
function __get($name) {
if (isset(static::$data[$name]))
return static::$data[$name];
return null;
}
}
class B extends A {
}
$object = new B();
print $object->foo;
Result
------
101
------------------------------------------------------------------------
[2010-07-01 19:51:00] lucato at gmail dot com
Description:
------------
Would it be possible to have magic setter/getter functions available on
static
context ?
The documentation says "Property overloading only works in object
context. These
magic methods will not be triggered in static context."
I would find it useful on a static context where I have a class A
extending
another class B, to access
Test script:
---------------
Example:
Class A {
static $data = array('bar' => 99, 'foo' => 101);
function __get($name) {
if (isset(self::$data[$name]))
return self::$data[$name];
return null;
}
}
Class B extends A {
}
echo B::$foo;
Expected result:
----------------
echo B::$foo;
In the example should return 101.
Actual result:
--------------
In the example it triggers a fatal error.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52225&edit=1