#50961 [Opn->Csd]: Overloading: magic __get method can be created static in older PHP versions
| From: | kalle@php.net | Date: | Tue, 16 Feb 2010 07:39:08 +0000 |
| Subject: | #50961 [Opn->Csd]: Overloading: magic __get method can be created static in older PHP versions | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3898@lists.php.net to get a copy of this message | ||
ID: 50961
Updated by: kalle@php.net
Reported By: n-roeser at gmx dot net
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: Gentoo Base System release 2.0.1
PHP Version: 5.2.12
-Assigned To:
+Assigned To: kalle
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-02-16 07:39:03] 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-08 07:21:55] 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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50961&edit=1