views:

100

answers:

1

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

A: 

Are you by any chance calling the function with reference variables, where $keys and $menu are identical (share the same address)? You have to be very careful when using references.

Alexander