Strange PHP reference bug

Posted by Roland Soós on Stack Overflow See other posts from Stack Overflow or by Roland Soós
Published on 2010-04-08T08:51:46Z Indexed on 2010/04/08 8:53 UTC
Read the original article Hit count: 427

Filed under:
|
|

Hello,

I have a really strange bug with my PHP code. I have a recursive code which build up a menu tree with object and one of my customers server can't make it work.

Contructor:

        function Menu(&$menus, &$keys , &$parent, &$menu){
    ...
        if($keys === NULL){
          $keys = array_keys($menus);
        }
   ...
        for($x = 0; $x < count($keys); $x++) {
           var_dump($keys);
           $menu = $menus[$keys[$x]];
           var_dump($keys);
           if($this->id == $menu->pid){
              $keys[$x] = NULL;
              $this->submenus[] = new Menu($menus, $keys, $this, $menu);
           }
        }

First var_dump give me back the array, the second give back the first element of $menus. Do you have any idea what causes this?

PHP version 5.2.3

© Stack Overflow or respective owner

Related posts about php

Related posts about recursion