Edit report at https://bugs.php.net/bug.php?id=52225&edit=1

 ID:                 52225
 Comment by:         mkutschker-php at yahoo 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
 Private report:     N

 New Comment:

Now that we have __callStatic() a pair a setter/getter pair 
__getStatic()/__setStatic() would be the next logical step to take.


Previous Comments:
------------------------------------------------------------------------
[2010-10-03 19:00:15] + at ni-po dot com

@henrik: This is about static property overloading, not about late static 
binding ;)

------------------------------------------------------------------------
[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 https://bugs.php.net/bug.php?id=52225&edit=1

Reply via email to