|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65870 Wrong documentation about magic methods __get and __isset
Submitted: 2013-10-09 14:19 UTC Modified: 2016-06-25 16:45 UTC
From: v dot matsuk at tut dot by Assigned: cmb (profile)
Status: Not a bug Package: Documentation problem
PHP Version: 5.4.20 OS: Windows 7 x64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
2 + 28 = ?
Subscribe to this entry?

 [2013-10-09 14:19 UTC] v dot matsuk at tut dot by
------------ states:
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 ( 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:
int (3)
true (if i beleive the russian version of documentation)

Actual result:
int (3)
int (3)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-25 16:45 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-06-25 16:45 UTC]
> __get() is called when chaining assignments together like this:
> $a = $obj->b = 8.

No, see <>.

> 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
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 12:01:23 2020 UTC