|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-04-22 22:50 UTC] jarnix at jarnix dot com
-Package: PHP Language Specification
+Package: Class/Object related
[2016-04-22 22:50 UTC] jarnix at jarnix dot com
[2016-04-22 22:55 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2016-04-22 22:55 UTC] nikic@php.net
[2016-04-23 14:26 UTC] jarnix at jarnix dot com
[2016-04-23 14:26 UTC] jarnix at jarnix dot com
[2016-04-23 14:37 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
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.