Re: 5.4 regression: non-existent sub-sub keys now have values
| From: | Daniel Convissor | Date: | Fri, 25 Nov 2011 03:07:15 +0000 |
| Subject: | Re: 5.4 regression: non-existent sub-sub keys now have values | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-56611@lists.php.net to get a copy of this message | ||
Hi Anthony:
> isset($foo['bar'][1]['baz']) && is_array($foo['bar'][1])
>
> You don't need to check each level. Only the one above the key you're
> looking at.
Excellent thinking. One hitch... that goes fatal in 5.3 if $foo is a string.
Here's how to write the test so it works the same way under 5.3 and 5.4:
<?php
function test2($id, $foo) {
echo "ID $id -- ";
var_dump(is_array($foo)
&& isset($foo['bar'][1]['baz']) &&
is_array($foo['bar'][1]));
// The following goes fatal on test 80.
//var_dump(isset($foo['bar'][1]['baz']) &&
is_array($foo['bar'][1]));
}
test2(10, array('bar' => array(1 => array('baz' =>
'string'))));
test2(20, array('bar' => array(1 => array('boo' =>
'string'))));
test2(30, array('bar' => array(1 => 'string')));
test2(40, array('bar' => array(2 => 'string')));
test2(50, array('boo' => array(1 => 'string')));
test2(60, array('bar' => 'string'));
test2(70, array('boo' => 'string'));
test2(80, 'string');
?>
Thanks,
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409