php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50813 __isset() not called for uninitialized array offsets $obj->test[0]
Submitted: 2010-01-21 09:10 UTC Modified: 2016-03-26 11:17 UTC
Votes:2
Avg. Score:2.5 ± 1.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: marc dot bennewitz at giata dot de Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID: None
 [2010-01-21 09:10 UTC] marc dot bennewitz at giata dot de
Description:
------------
On testing if an array key is available on an overloaded object variable it doesn't check __isset before calling __get to get the variable for checking the array key.

Reproduce code:
---------------
class MyClass
{

    public function __isset($varname)
    {
        echo 'isset' . PHP_EOL;
        return false;
    }

    public function __get($varname)
    {
        trigger_error('Key "' . $varname . '" does not exist', E_USER_NOTICE);
    }

}

$obj = new MyClass();
var_dump( isset($obj->test[0]) );

Expected result:
----------------
isset
bool(false)

Actual result:
--------------
PHP Notice:  Key "test" does not exist in /tmp/test.php on line 14

Notice: Key "test" does not exist in /tmp/test.php on line 14
bool(false)

Patches

31Jan2011_50813.diff_zend_object_handlers.c (last revision 2011-02-01 06:53 UTC by mjk at emmjaykay dot org)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-21 09:59 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2010-01-21 12:03 UTC] marc dot bennewitz at giata dot de
Thats the same:

>php -v
PHP 5.3.3-dev (cli) (built: Jan 21 2010 12:52:05)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

>php test.php
PHP Notice:  Key "test" does not exist in /tmp/test.php on line 14

Notice: Key "test" does not exist in /tmp/test.php on line 14
bool(false)
 [2011-02-01 07:55 UTC] mjk at emmjaykay dot org
I'm not so sure this patch is kosher since it checks the return value's lval from the call to zend_std_call_issetter(). I don't see it in other code.
 [2011-02-01 08:40 UTC] mjk at emmjaykay dot org
In my change, if I comment out the __isset definition, I get

Fatal error: Couldn't find implementation for method MyClass::__isset in Unknown on line 0

where as on the unchanged code, I get 

Notice: Key "test" does not exist in /home/mjk/php-5.3.5.orig/e.php on line 22
bool(false)

I'm not sure if that's correct or not.
 [2016-03-26 11:17 UTC] nikic@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2016-05-04 23:15 UTC] sm0ke999 at yandex dot ru
Here valid link: https://github.com/php/php-src/commit/373da7aa6f5e7bf57d434fd449f97770fb479d3e

Dot in the end made link invalid in previous comment.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Mar 02 12:01:23 2021 UTC