Bug #72117 [Opn->Nab]: Magic __isset applied wrong

From: Date: Thu, 28 Apr 2016 10:02:47 +0000
Subject: Bug #72117 [Opn->Nab]: Magic __isset applied wrong
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200803@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 Updated by: bwoebi@php.net Reported by: rullzer at owncloud dot com Summary: Magic __isset applied wrong -Status: Open +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: 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 Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#200803) next »