Doc #65870 [NEW]: Wrong documentation about magic methods __get and __isset
| From: | v dot matsuk at tut dot by | Date: | Wed, 09 Oct 2013 14:19:27 +0000 |
| Subject: | Doc #65870 [NEW]: Wrong documentation about magic methods __get and __isset | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-10466@lists.php.net to get a copy of this message | ||
From: v dot matsuk at tut dot by
Operating system: Windows 7 x64
PHP version: 5.4.20
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Wrong documentation about magic methods __get and __isset
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 bug report at https://bugs.php.net/bug.php?id=65870&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65870&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=65870&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65870&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65870&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65870&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65870&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65870&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65870&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65870&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65870&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65870&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65870&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65870&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65870&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65870&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65870&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65870&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65870&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65870&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65870&r=mysqlcfg