|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68110 undefined variable error not being triggered for undefined array index
Submitted: 2014-09-26 21:24 UTC Modified: 2014-10-07 13:24 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mathiasgrimm at gmail dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.5, 5.4 OS: OSX, Windows, Linux
Private report: No CVE-ID: None
 [2014-09-26 21:24 UTC] mathiasgrimm at gmail dot com
according to the manual(

Attempting to access an array key which has not been defined is the same as accessing any other undefined variable: an E_NOTICE-level error message will be issued, and the result will be NULL.

Test script:
        $a ['a'] = null;

        $tmp = $a['a']['b']; // nothing
        $tmp = $a['a']['b']['c']; // nothing

// this works (throw an E_NOTICE) fine
$a ['a'] = array();
$tmp = $a['a']['b']; // Undefined index: b
$tmp = $a['a']['b']['c']; // Undefined index: b

Expected result:
assert(isset($php_errormsg) === true);

Actual result:
Undefined index: b


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-26 21:25 UTC] mathiasgrimm at gmail dot com
actually the expected result is Undefined index: b... or to have the variable $php_errormsg defined.
 [2014-09-26 21:34 UTC] mathiasgrimm at gmail dot com
-PHP Version: 5.5.17 +PHP Version: 5.5, 5.4
 [2014-09-26 21:34 UTC] mathiasgrimm at gmail dot com
Discovered this problem when using the @ sign to suppress errors when trying to access an undefined array index and checking the $php_errormsg but for my surprise that never happens if the assigned value is NULL... and according to the documentation this should happen.

I was implementing an array_key_exist_recursive ...

public static function exists($mIndex, $aSource)
        $aPath   = explode(self::$sSeparator, $mIndex);
        $sEval   = "\$bExists = @\$aSource['" . implode("']['", $aPath) . "'];";
        return !isset($php_errormsg);
 [2014-09-26 21:45 UTC]
-Package: PHP Language Specification +Package: Scripting Engine problem
 [2014-10-07 13:24 UTC]
-Status: Open +Status: Duplicate
 [2014-10-07 13:24 UTC]
Duplicate of
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 03:01:27 2024 UTC