Edit report at https://bugs.php.net/bug.php?id=60362&edit=1
ID: 60362 Patch added by: larue...@php.net 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: The following patch has been added/updated: Patch Name: string_offset_trigger_notice.patch Revision: 1323019601 URL: https://bugs.php.net/patch-display.php?bug=60362&patch=string_offset_trigger_notice.patch&revision=1323019601 Previous Comments: ------------------------------------------------------------------------ [2011-12-04 16:43:41] larue...@php.net update patch, only change the code style, and fix one test faild, thanks ------------------------------------------------------------------------ [2011-12-04 16:43:01] larue...@php.net The following patch has been added/updated: Patch Name: fix_disabling_bad_string_offsets Revision: 1323016981 URL: https://bugs.php.net/patch-display.php?bug=60362&patch=fix_disabling_bad_string_offsets&revision=1323016981 ------------------------------------------------------------------------ [2011-12-04 12:52:52] alan at akbkhome dot com 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" ------------------------------------------------------------------------ [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