From:
Operating system: linux
PHP version: 5.4SVN-2011-11-23 (SVN)
Package: Arrays related
Bug Type: Bug
Bug description:non-existent sub-sub keys should not have values
Description:
------------
In an array, a sub-sub-key of an existing key is now returning a letter of
the value indexed by the main key. This is a regression in 5.4. PHP 5.3
still operates as expected. I suspect this is related to the array
dereferencing changes.
Test script:
---------------
$arr = array('exists' => 'foo');
if (isset($arr['exists']['non_existent'])) {
echo "expected: sub-key 'non_existent' is set: ";
var_dump($arr['exists']['non_existent']);
} else {
echo "BEHAVIOR CHANGED: sub-key 'non_existent' is not set.\n";
}
if (isset($arr['exists'][1])) {
echo "expected: sub-key 1 is set: ";
var_dump($arr['exists'][1]);
} else {
echo "BEHAVIOR CHANGED: sub-key 1 is not set.\n";
}
echo "-------------------\n";
if (isset($arr['exists']['non_existent']['sub_sub'])) {
echo "BEHAVIOR CHANGED: sub-key 'sub_sub' is set: ";
var_dump($arr['exists']['non_existent']['sub_sub']);
} else {
echo "good: sub-sub-key 'sub_sub' is not set.\n";
}
if (isset($arr['exists'][1][0])) {
echo "BEHAVIOR CHANGED: sub-sub-key 0 is set: ";
var_dump($arr['exists'][1][0]);
} else {
echo "good: sub-sub-key 0 is not set.\n";
}
echo "-------------------\n";
if (empty($arr['exists']['non_existent'])) {
echo "BEHAVIOR CHANGED: sub-key 'non_existent' is empty.\n";
} else {
echo "expected: sub-key 'non_existent' is not empty: ";
var_dump($arr['exists']['non_existent']);
}
if (empty($arr['exists'][1])) {
echo "BEHAVIOR CHANGED: sub-key 1 is empty.\n";
} else {
echo "expected: sub-key 1 is NOT empty: ";
var_dump($arr['exists'][1]);
}
echo "-------------------\n";
if (empty($arr['exists']['non_existent']['sub_sub'])) {
echo "good: sub-sub-key 'sub_sub' is empty.\n";
} else {
echo "BEHAVIOR CHANGED: sub-sub-key 'sub_sub' is not empty: ";
var_dump($arr['exists']['non_existent']['sub_sub']);
}
if (empty($arr['exists'][1][0])) {
echo "good: sub-sub-key 0 is empty.\n";
} else {
echo "BEHAVIOR CHANGED: sub-sub-key 0 is not empty: ";
var_dump($arr['exists'][1][0]);
}
Expected result:
----------------
expected: sub-key 'non_existent' is set: string(1) "f"
expected: sub-key 1 is set: string(1) "o"
-------------------
good: sub-sub-key 'sub_sub' is not set.
good: sub-sub-key 0 is not set.
-------------------
expected: sub-key 'non_existent' is not empty: string(1) "f"
expected: sub-key 1 is NOT empty: string(1) "o"
-------------------
good: sub-sub-key 'sub_sub' is empty.
good: sub-sub-key 0 is empty.
Actual result:
--------------
expected: sub-key 'non_existent' is set: string(1) "f"
expected: sub-key 1 is set: string(1) "o"
-------------------
BEHAVIOR CHANGED: sub-key 'sub_sub' is set: string(1) "f"
BEHAVIOR CHANGED: sub-sub-key 0 is set: string(1) "o"
-------------------
expected: sub-key 'non_existent' is not empty: string(1) "f"
expected: sub-key 1 is NOT empty: string(1) "o"
-------------------
BEHAVIOR CHANGED: sub-sub-key 'sub_sub' is not empty: string(1) "f"
BEHAVIOR CHANGED: sub-sub-key 0 is not empty: string(1) "o"
--
Edit bug report at https://bugs.php.net/bug.php?id=60362&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=60362&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=60362&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=60362&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=60362&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=60362&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=60362&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=60362&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=60362&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=60362&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=60362&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=60362&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=60362&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=60362&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=60362&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=60362&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=60362&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=60362&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=60362&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=60362&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=60362&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=60362&r=mysqlcfg