| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2010-07-01 19:51 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 00:00:01 2025 UTC | 
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