php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39678 __set and __get not called where a class attribute is called statically
Submitted: 2006-11-29 10:03 UTC Modified: 2006-11-29 10:21 UTC
From: denis at edistar dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.0 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: denis at edistar dot com
New email:
PHP Version: OS:

 

 [2006-11-29 10:03 UTC] denis at edistar dot com
Description:
------------
Static class attributes cannot be accessed using __get and 
__set methods.

I think probably because they are resolved at compile time 
and not at runtime. If not, it is a bug. 

According to the documentation it should be possibile to 
access static class attributes using __get and __get.



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
test

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-29 10:21 UTC] tony2001@php.net
This is expected behaviour.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC