Bug #72117 [Com]: Magic __isset applied wrong
| From: | koubel at seznam dot cz | Date: | Mon, 16 May 2016 15:02:26 +0000 |
| Subject: | Bug #72117 [Com]: Magic __isset applied wrong | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201130@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72117&edit=1
ID: 72117
Comment by: koubel at seznam dot cz
Reported by: rullzer at owncloud dot com
Summary: Magic __isset applied wrong
Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: Next Minor Version
Block user comment: N
Private report: N
New Comment:
Maybe it's duplicate of https://bugs.php.net/bug.php?id=72223,
It seems that you make the BC break in patch release, which can be relative big problem in migration
from PHP 5.6 to PHP 7.0. It's necessary to document this in migration guide at least.
Previous Comments:
------------------------------------------------------------------------
[2016-05-04 20:24:16] nikic@php.net
Related To: Bug #72160
------------------------------------------------------------------------
[2016-04-28 10:06:33] bwoebi@php.net
See also bug #69659
------------------------------------------------------------------------
[2016-04-28 10:02:42] bwoebi@php.net
This is a bugfix in 7.0.6, __isset() never had been called there even if it should have been:
https://3v4l.org/J0Lkk
To check if something is isset(), you generally need to check every dimension.
Is $this->a set? No it isn't (according to __isset()). isset() thus returns false.
If it were set, then isset() checks the next dimension and calls __get() to get the next dimension.
This is necessary to avoid failures in legitimate cases like (https://3v4l.org/r8U7T):
class A {
private $foo = ["a" => [1, 2, 3]];
function __get($a) {
if (isset($this->foo[$a])) {
return $this->foo[$a];
}
throw new Exception("Invalid key accessed! Check with isset() first!");
}
function __isset($a) {
return isset($this->foo[$a]);
}
}
$obj = new A;
var_dump(isset($obj->a[1]));
var_dump(isset($obj->b[1])); // exception in versions before 7.0.6
------------------------------------------------------------------------
[2016-04-28 09:39:58] rullzer at owncloud dot com
Description:
------------
The code example makes is pretty clear.
When using the magic __get method and __isset method in 7.0.6 things break. The __isset is called
with the wrong argument.
Tested this the 7.0.6 tag.
Test script:
---------------
https://3v4l.org/r9QFk
Expected result:
----------------
The argument to isset is first evaluated as much as possible and only then is isset called.
Actual result:
--------------
Isset seems to be greedy in 7.0.6 and call with the first argument it can find. Which can fail.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72117&edit=1