vurentjie Posted May 30, 2009 Share Posted May 30, 2009 hi just a quick question, some code for what I am trying... further up ..... self::$_menus['test'] = array(); self::loadLinks($links,'test'); public static function loadLinks($links){ $linkmark = false; $where = array_slice( func_get_args(), 1 ); foreach($where as $resource){ $linkmark=($linkmark===false)?self::$_menus[$resource]:$linkmark[$resource]; } $linkmark['newlink']='testinglink'; var_dump($linkmark); var_dump(self::$_menus); } it seems the menu array is not being passed by reference, if I convert all static class vars and use &$this->.... I can reference properly.... $this->_menus['test'] = array(); $this->loadLinks($links,'test'); public function loadLinks($links){ $linkmark = false; $where = array_slice( func_get_args(), 1 ); foreach($where as $resource){ $linkmark=($linkmark===false)?&$this->_menus[$resource]:&$linkmark[$resource]; } $linkmark['newlink']='testinglink'; var_dump($linkmark); var_dump($this->_menus); } I thought php5 would handle this as reference? Can anyone give me a why? Quote Link to comment Share on other sites More sharing options...
vurentjie Posted May 30, 2009 Author Share Posted May 30, 2009 well i ended up just sticking to the follwing...works fine... public function loadLinks($links){ $linkmark = false; $where = array_slice( func_get_args(), 1 ); foreach($where as $resource)($linkmark===false)? $linkmark = &$this->_menus[$resource] : $linkmark = &$linkmark[$resource]; $linkmark = ( is_array($linkmark) ) ? array_merge($linkmark,$links) : $links; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.