php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50961 Overloading: magic __get method can be created static in older PHP versions
Submitted: 2010-02-08 07:21 UTC Modified: 2010-02-16 07:39 UTC
From: n-roeser at gmx dot net Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.12 OS: Gentoo Base System release 2.0.1
Private report: No CVE-ID: None
 [2010-02-08 07:21 UTC] n-roeser at gmx dot net
Description:
------------
The documentation <URL:http://php.net/manual/en/language.oop5.overloading.php> says that the __get method cannot be declared static. My PHP installation shows behavior which suggests otherwise.

From reading the documentation page, it is not clear enough that the magic method could theoretically be declared static in older PHP versions, but that this is discouraged.

Reproduce code:
---------------
$ php --version|head -n 1;php -r 'class A{}class B{public function __get($n){}}class C{public static function __get($n){}}$a=new A;$b=new B;$c=new C;$a->d;$b->d;$c->d;'
PHP 5.2.12-pl0-gentoo with Suhosin-Patch 0.9.7 (cli) (built: Jan 23 2010 22:38:48) 
Notice: Undefined property: A::$d in Command line code on line 1


If you like another example, you can also try:
<?php
class A
{
    // expect warning/error message, but do not get any
    public static function __get($name) {
        return 'test';
    }
}

$a = new A();
echo $a->b . "\n";

Expected result:
----------------
I suggest adding something like the following after the text “Therefore these methods can not be declared static.”:
“*Note:* Before PHP 5.3.0, it was possible to declare these methods static. This is strictly discouraged, and relying on this behavior is deprecated.”

Actual result:
--------------
Note that the code example gives the same reaction (no warning) for accesses to $b *and* $c. So it does not matter whether the __get method is declared static or not.

The documentation changelog mentions:
“Added __callStatic(). Added warning to enforce public visibility and non-static declaration.” for version 5.3.0.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-16 07:39 UTC] svn@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=295144
Log: Fixed bug #50961 (Overloading: magic __get method can be created static in older PHP versions)
 [2010-02-16 07:39 UTC] kalle@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=2c2e8773722b97b3936d9a5ad6692ae56841bb50
Log: Fixed bug #50961 (Overloading: magic __get method can be created static in older PHP versions)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Fri Oct 09 00:00:01 2026 UTC