Bug #72081 [Opn->Dup]: __get called before __isset

From: Date: Fri, 22 Apr 2016 22:55:14 +0000
Subject: Bug #72081 [Opn->Dup]: __get called before __isset
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200699@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72081&edit=1 ID: 72081 Updated by: nikic@php.net Reported by: jarnix at jarnix dot com Summary: __get called before __isset -Status: Open +Status: Duplicate Type: Bug Package: Class/Object related Operating System: linux PHP Version: 5.6.20 Block user comment: N Private report: N New Comment: Duplicate of #72056, which is already fixed in 7.0.6. Previous Comments: ------------------------------------------------------------------------ [2016-04-22 22:50:59] jarnix at jarnix dot com wrong package ------------------------------------------------------------------------ [2016-04-22 22:46:54] jarnix at jarnix dot com Description: ------------ I have an object when I override __get and __isset. I try to use __isset but it seems that the __get is called before __isset. It's not the same thing with arrays (I can do isset($someArray['existingParentKey']['notExistingChildKey']) or isset($someArray['notExistingParentKey']['notExistingChildKey']) without problem. I added multiple examples and comments to show it. Maybe it's the expected behaviour. The __get should try __iset before trying to get the value, but it doesn't seem logical. It might be a duplicate of #72056 (__get is called for testing if chained property is set) Test script: --------------- <?php class Config { protected static $data; public static function init() { self::$data = new \StdClass(); self::$data->parent = new \StdClass(); } public function __get($key) { return self::$data->$key; } public function __isset($key) { return(isset(self::$data->$key)); } } $config = new Config(); // prints "is set", as expected if(isset($config->parent)) { echo 'is set' . PHP_EOL; } else { echo 'not set' . PHP_EOL; } // should print "not set" but throws an exception before if(isset($config->parent->notChild)) { echo 'isset' . PHP_EOL; } else { echo 'not set' . PHP_EOL; } // prints "not set" if(isset($config->notParent)) { echo 'is set' . PHP_EOL; } else { echo 'not set' . PHP_EOL; } // should write "not set" but throws an exception before if(isset($config->notParent->test)) { echo 'is set' . PHP_EOL; } else { echo 'not set' . PHP_EOL; } Expected result: ---------------- The __isset should be called recursively before trying to __get the child element. Actual result: -------------- An exception is thrown, making the __isset useless. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72081&edit=1

« previous php.bugs (#200699) next »