Bug #68110 [Opn->Dup]: undefined variable error not being triggered for undefined array index
| From: | nikic@php.net | Date: | Tue, 07 Oct 2014 13:24:46 +0000 |
| Subject: | Bug #68110 [Opn->Dup]: undefined variable error not being triggered for undefined array index | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187916@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68110&edit=1
ID: 68110
Updated by: nikic@php.net
Reported by: mathiasgrimm at gmail dot com
Summary: undefined variable error not being triggered for
undefined array index
-Status: Open
+Status: Duplicate
Type: Bug
Package: Scripting Engine problem
Operating System: OSX, Windows, Linux
PHP Version: 5.5, 5.4
Block user comment: N
Private report: N
New Comment:
Duplicate of https://bugs.php.net/bug.php?id=54556.
Previous Comments:
------------------------------------------------------------------------
[2014-09-26 21:34:52] 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) . "'];";
eval($sEval);
return !isset($php_errormsg);
}
------------------------------------------------------------------------
[2014-09-26 21:25:29] 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:24:03] mathiasgrimm at gmail dot com
Description:
------------
according to the manual(http://ie1.php.net/manual/en/language.types.array.php):
Note:
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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68110&edit=1