#33615 [NEW]: Foreach and arrays stored in session

From: Date: Fri, 08 Jul 2005 10:25:39 +0000
Subject: #33615 [NEW]: Foreach and arrays stored in session
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-81583@lists.php.net to get a copy of this message
From: Wojciech dot Szela at gmail dot com Operating system: Windows XP Professional SP2 PHP version: 5.0.4 PHP Bug Type: Arrays related Bug description: Foreach and arrays stored in session Description: ------------ 1. Create array and store it in $_SESSION, eg. 2. Write method which goes trough all elements of new structure searching for particular element (use foreach), and when founds it, call very same function looking for other element. Take a look at a code. Work perfectly on Linux. On Windows function looses state (index) of foreach, so you have to change line: foreach($_SESSION['application'] as $key => $value) { to $foo = $_SESSION; foreach($foo as $key => $value) { Reproduce code: --------------- $_SESSION['application'] = array( array( 'name' => 'l1', 'symbol' => 'l1', 'father' => 'root'), array( 'name' => 'l1-1', 'symbol' => 'l1-1', 'father' => 'l1'), array( 'name' => 'l1-2', 'symbol' => 'l1-2', 'father' => 'l1'), array( 'name' => 'l2', 'symbol' => 'l2', 'father' => 'root'), ); function getTreeNodes($father) { $ret = array(); foreach($_SESSION['application'] as $key => $value) { if($value['father'] == $father) { $child = array( 'symbol' => $key, 'name' => $value['name'], 'child' => array()); $child['child'] = $this->getTreeNodes($key); $ret[] = $child; } } return $ret; } $tree = array(); $tree[] = array( 'symbol' => 'root', 'name' => 'Aplikacje', 'child' => array() ); $tree[0]['child'] = $this->getTreeNodes('root'); print_r($tree); Expected result: ---------------- array of arrays (tree) root - l1 - l1-1 - l1-2 - l2 Actual result: -------------- array of arrays (one branch) root - l1 - l1-1 -- Edit bug report at http://bugs.php.net/?id=33615&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33615&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33615&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33615&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33615&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33615&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33615&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33615&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33615&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33615&r=support Expected behavior: http://bugs.php.net/fix.php?id=33615&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33615&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33615&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33615&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33615&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33615&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33615&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33615&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33615&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33615&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33615&r=mysqlcfg

« previous php.bugs (#81583) next »