|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-05-25 22:25 UTC] danieln at javanet dot com
-Status: Open
+Status: Closed
[2010-05-25 22:25 UTC] danieln at javanet dot com
[2010-05-26 10:03 UTC] mike@php.net
-Status: Closed
+Status: Bogus
[2010-05-26 10:03 UTC] mike@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 01:00:01 2025 UTC |
Description: ------------ I'd appreciate confirmation that the following is a bug with PHP 5.2.13, and apologies if I'm mistaken. The following complete PHP script crashes the 3rd time it is run. The foreach() loop seems to have an (improper) side effect which wipes out the nested $_SESSION array because the internal variable used in the loop matches the name of the nested $_SESSION array. Simply changing the name of the internal foreach() variable to something different fixes the problem. Note: clear session variables before running script 3 times. Again, changing "$breadcrumb" to "$the_breadcrumb" fixes the problem. But the foreach() loop should have no side effects. Note: since the scope of $breadcrumb is not the same as the scope of $_SESSION["breadcrumb"], there should be no collision. Note that doing a print_r() on the array shows the array as (correctly) empty the first time, (correctly) populated the second time, and erroneously set as "Array ( [breadcrumb] => trail )" the third time (the nested array has been wiped out). The error in the PHP error log from the 3rd run: PHP Fatal error: Cannot use string offset as an array on line 5 The issue is not a problem on PHP 5.3 - only PHP 5.2.13. I could not find any note regarding this issue in the PHP changelog, and I must use 5.2.13 on my live site, so I'm posting here for confirmation that this is a PHP 5.2 bug. Thanks, Dan Nissenbaum Test script: --------------- <?php session_start(); if (!is_array($_SESSION["breadcrumb"]["trail"])) { $_SESSION["breadcrumb"]["trail"][] = "trail"; } foreach ($_SESSION["breadcrumb"]["trail"] as $breadcrumb) { echo $breadcrumb; } ?> Expected result: ---------------- No PHP 5.2.13 crash on line 5. Actual result: -------------- PHP 5.2.13 crashes on line 5.