Bug #72081 [NEW]: __get called before __isset

From: Date: Fri, 22 Apr 2016 22:46:57 +0000
Subject: Bug #72081 [NEW]: __get called before __isset
Groups: php.standards 
Request: Send a blank email to standards-+get-1073@lists.php.net to get a copy of this message
From:             jarnix at jarnix dot com
Operating system: linux
PHP version:      5.6.20
Package:          PHP Language Specification
Bug Type:         Bug
Bug description:__get called before __isset

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 bug report at https://bugs.php.net/bug.php?id=72081&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72081&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72081&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72081&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72081&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72081&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72081&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72081&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72081&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72081&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72081&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72081&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72081&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72081&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72081&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72081&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72081&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72081&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72081&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72081&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72081&r=mysqlcfg



Thread (1 message)

  • jarnix at jarnix dot com
« previous php.standards (#1073) next »