#50961 [NEW]: Overloading: magic __get method can be created static in older PHP versions

From: Date: Mon, 08 Feb 2010 07:21:55 +0000
Subject: #50961 [NEW]: Overloading: magic __get method can be created static in older PHP versions
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3837@lists.php.net to get a copy of this message
From: n-roeser at gmx dot net Operating system: Gentoo Base System release 2.0.1 PHP version: 5.2.12 PHP Bug Type: Documentation problem Bug description: Overloading: magic __get method can be created static in older PHP versions 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. -- Edit bug report at http://bugs.php.net/?id=50961&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50961&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50961&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50961&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=50961&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50961&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=50961&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=50961&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=50961&r=needscript Try newer version: http://bugs.php.net/fix.php?id=50961&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=50961&r=support Expected behavior: http://bugs.php.net/fix.php?id=50961&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=50961&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=50961&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=50961&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50961&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=50961&r=dst IIS Stability: http://bugs.php.net/fix.php?id=50961&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=50961&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=50961&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=50961&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=50961&r=mysqlcfg

« previous php.doc.bugs (#3837) next »