php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33615 Foreach and arrays stored in session
Submitted: 2005-07-08 12:25 UTC Modified: 2005-08-23 13:25 UTC
From: Wojciech dot Szela at gmail dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.0.4 OS: Windows XP Professional SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Wojciech dot Szela at gmail dot com
New email:
PHP Version: OS:

 

 [2005-07-08 12:25 UTC] Wojciech dot Szela at gmail dot com
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-08 12:31 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-08-23 10:21 UTC] Wojciech dot Szela at gmail dot com
Work fine with CVS version.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 11:01:37 2024 UTC