Doc #65870 [Opn->Nab]: Wrong documentation about magic methods __get and __isset
| From: | cmb@php.net | Date: | Sat, 25 Jun 2016 16:45:24 +0000 |
| Subject: | Doc #65870 [Opn->Nab]: Wrong documentation about magic methods __get and __isset | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13615@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65870&edit=1
ID: 65870
Updated by: cmb@php.net
Reported by: v dot matsuk at tut dot by
Summary: Wrong documentation about magic methods __get and
__isset
-Status: Open
+Status: Not a bug
Type: Documentation Problem
Package: Documentation problem
Operating System: Windows 7 x64
PHP Version: 5.4.20
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> __get() is called when chaining assignments together like this:
> $a = $obj->b = 8.
No, see <https://3v4l.org/Gq9PP>.
> English version doesn't contain this text.
If translations deviate from the original, report that as bug of
type translation problem, or consider to submit a patch via
<https://edit.php.net/>.
Previous Comments:
------------------------------------------------------------------------
[2013-10-09 14:19:26] v dot matsuk at tut dot by
Description:
------------
http://www.php.net/manual/en/language.oop5.overloading.php
states:
>Note:
The return value of __set() is ignored because of the way PHP processes the assignment operator.
Similarly, __get() is never called when chaining assignments together like this:
$a = $obj->b = 8;
But it's wrong for __get()! __get() is called when chaining assignments together like this: $a
= $obj->b = 8.
The Russian version of documentation (http://www.php.net/manual/ru/language.oop5.overloading.php)
states:
> ÐамеÑание:
Ðевозможно иÑполÑзоваÑÑ
пеÑегÑÑженнÑе ÑвойÑÑва в
дÑÑгиÑ
ÑзÑковÑÑ
конÑÑÑÑкÑиÑÑ
, кÑоме isset(). ÐÑо
ознаÑаеÑ, ÑÑо еÑли на
пеÑегÑÑженном ÑвойÑÑве
бÑÐ´ÐµÑ Ð²Ñзвана конÑÑÑÑкÑиÑ
empty(), Ñо пеÑегÑÑженнÑй меÑод не
бÑÐ´ÐµÑ Ð²Ñзван.
ÐÐ»Ñ Ð¾Ð±Ñ
ода ÑÑого
огÑаниÑÐµÐ½Ð¸Ñ Ð¼Ð¾Ð¶Ð½Ð¾
ÑкопиÑоваÑÑ Ð¿ÐµÑегÑÑженное
ÑвойÑÑво в локалÑнÑÑ
пеÑеменнÑÑ Ð¸ заÑем
пÑимениÑÑ Ðº ней empty().
English version doesn't contain this text. It's also wrong because if method __isset was
realised, the empty() will call it if property not found.
Test script:
---------------
class A {
protected $_vars = array();
public function __get($var){return $this->_vars[$var];}
public function __set($var, $val){$this->_vars[$var] = $val; }
public function __isset($var){return isset($this->_vars[$var]);}
}
$o = new A();
$o->a = 1;
$o->b = 2;
$c = $o->b = 3;
var_dump($c); //3
var_dump($o->b); //3
var_dump(empty($o->b)); //false
Expected result:
----------------
null
int (3)
true (if i beleive the russian version of documentation)
Actual result:
--------------
int (3)
int (3)
false
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65870&edit=1