php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45002 __get() and __set() don't work for static variable calls
Submitted: 2008-05-15 08:42 UTC Modified: 2021-08-10 16:36 UTC
Votes:201
Avg. Score:4.7 ± 0.7
Reproduced:173 of 173 (100.0%)
Same Version:71 (41.0%)
Same OS:129 (74.6%)
From: jb2386 at hotmail dot com Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: 5.2.6 OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jb2386 at hotmail dot com
New email:
PHP Version: OS:

 

 [2008-05-15 08:42 UTC] jb2386 at hotmail dot com
Description:
------------
As per bug report: http://bugs.php.net/bug.php?id=39678

"Static class attributes cannot be accessed using __get and 
__set methods."

Also, for reference to "__callStatic" see: http://bugs.php.net/bug.php?id=26739

With the implementation of __callStatic in PHP 5.3, will there be an implementation of similar functions __getStatic() and __setStatic()?

For example, so replacing __get and __set with __getStatic() and __setStatic() respectively will produce the "Expected Output" below?

Reproduce code:
---------------
class myClass {

        public function __set($name,$value) {
                echo "Setting: " . $name . " to " . $value."\n";
                self::$$name = $value;
        }

        public function __get($name) {
                echo "Getting: " . $name . "\n";
        }
}

myClass::$myStaticVar = "test";
echo myClass::$myStaticVar;

Expected result:
----------------
Setting: myStaticVar to test
Getting: myStaticVar

Actual result:
--------------
Fatal error: Access to undeclared static property:  
myClass::$myStaticVar

Patches

Fix (last revision 2011-05-19 10:01 UTC by allesbesser at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-13 14:42 UTC] thekid@php.net
There is a patch available at 

  http://sitten-polizei.de/php/getstatic.diff
 [2008-11-25 03:50 UTC] cleeder at gmail dot com
How long until we can expect to see this patch in the production version of PHP?
 [2009-01-08 08:51 UTC] jeremie dot bordier at gmail dot com
Could this patch be reviewed and committed ? It's been a long time now for a such little feature...
 [2009-05-13 15:38 UTC] rcavallari at hotmail dot com
Any news about __{get,set}Static in the mainline?
 [2009-07-30 21:21 UTC] some at email dot com
When to expect resolving this bug
 [2009-08-01 15:25 UTC] atrauzzi at gmail dot com
I'd have to say I'm waiting on this feature as well.

Is there a snapshot I could be using to test it out?
 [2009-09-24 10:23 UTC] peter dot rother at gmail dot com
'Twould be seriously nice to have this feature…please let us know if 
anything can be done soon.
 [2010-05-14 09:13 UTC] vincentbab at gmail dot com
I would really apreciate this feature too
 [2010-06-25 12:22 UTC] temporary dot hole at googlemail dot com
I have an idea to use this for a static registry class, would be really useful for keeping 'application-wide' data out of global variables.

I have no idea how to apply this patch, is it possible to use the above mentioned .diff on PHP 5.3.1 ?
 [2011-03-30 19:26 UTC] marious dot alex at gmail dot com
This would be a really useful feature that I have been wishing for, for at least 
two years.
How come this has not been implemented when it is such a simple feature that has 
also been requested since 2008?
 [2011-05-19 12:03 UTC] allesbesser at gmail dot com
Please use the patch by thekid for the next release.  We really need this.
 [2012-07-21 09:57 UTC] zsolt94 at gmail dot com
Please import this feature into mainline PHP. We are still looking for this patch.
 [2013-10-02 16:51 UTC] grotlek at hotmail dot com
Well, it looks like there are at least 3 feature requests for this; but this one is the most popular and has had a patch linked against it since a comment posted in Sept 2008.

I've looked at the patch, it seems complete enough; the amount of code added is pretty tiny, and has test cases to test the functions too.

So I guess the question is how to get the developers to pick this up and put the code into the main development line. Do devs even pay attention to user requests?

(It may be a tiny feature but it would make a whole bunch of code much easier to maintain).
 [2014-05-08 17:57 UTC] levim@php.net
-Package: Feature/Change Request +Package: Scripting Engine problem
 [2021-01-20 00:11 UTC] alex at zierhut-it dot de
+1 Would love to have this functionality added. Any news?
 [2021-08-10 16:36 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2021-08-10 16:36 UTC] cmb@php.net
Even if this feature request had a billion upvotes and as much
comments, it won't be implemented, unless someone cared to go
through the RFC process[1].  For the time being I'm suspending
this ticket.

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 05:01:29 2024 UTC