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: Duplicate
Type: Bug
Package: Class/Object related
Operating System: linux
PHP Version: 5.6.20
Block user comment: N
Private report: N
New Comment:
Correct, there are currently no plans to backport this change to PHP 5.6. It's a pretty subtle
behavior difference in an edge-case that was not very relevant before PHP 7.0.
Previous Comments:
------------------------------------------------------------------------
[2016-04-23 14:26:37] jarnix at jarnix dot com
If it's a duplicate and it's fixed in 7.0.6, does it mean it won't be fixed in the
5.6 branch ?
------------------------------------------------------------------------
[2016-04-23 14:26:34] jarnix at jarnix dot com
If it's a duplicate and it's fixed in 7.0.6, does it mean it won't be fixed in the
5.6 branch ?
------------------------------------------------------------------------
[2016-04-22 22:55:13] nikic@php.net
Duplicate of #72056, which is already fixed in 7.0.6.
------------------------------------------------------------------------
[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