Edit report at https://bugs.php.net/bug.php?id=60362&edit=1
ID: 60362
Comment by: alan at akbkhome dot com
Reported by: danielc at analysisandsolutions dot com
Summary: non-existent sub-sub keys should not have values
Status: Open
Type: Bug
Package: Arrays related
Operating System: linux
PHP Version: 5.4SVN-2011-11-23 (SVN)
Block user comment: N
Private report: N
New Comment:
This is the test output after the changes:
- most of this makes sense - string offsets of strings are now invalid, and the
dereferencing of strings with numerical indexes is 'fixed' and a behaviour
change.
BEHAVIOR CHANGED: sub-key 'non_existent' is not set.
expected: sub-key 1 is set: string(1) "o"
-------------------
good: sub-sub-key 'sub_sub' is not set.
BEHAVIOR CHANGED: sub-sub-key 0 is set: string(1) "o"
-------------------
BEHAVIOR CHANGED: sub-key 'non_existent' is empty.
expected: sub-key 1 is NOT empty: string(1) "o"
-------------------
good: sub-sub-key 'sub_sub' is empty.
BEHAVIOR CHANGED: sub-sub-key 0 is not empty: string(1) "o"
Previous Comments:
------------------------------------------------------------------------
[2011-11-23 01:37:51] danielc at analysisandsolutions dot com
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 this bug report at https://bugs.php.net/bug.php?id=60362&edit=1