note 91503 added to function.call-user-func-array

From: Date: Sat, 13 Jun 2009 07:06:53 +0000
Subject: note 91503 added to function.call-user-func-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-156837@lists.php.net to get a copy of this message
Those having the passing by reference issue can use this simple hack. I´m really not sure WHY this works, but it does, and it does not make use of EVAL or other questionable functions. <?php function executeHook($name, $type='hooks'){ $args = func_get_args(); array_shift($args); array_shift($args); //Rather stupid Hack for the call_user_func_array(); $Args = array(); foreach($args as $k => &$arg){ $Args[$k] = &$arg; //Why do we specify the key? Because PHP may change to disallow [] sometime in the future! } //End Hack $hooks = &$this->$type; if(!isset($hooks[$name])) return false; $hook = $hooks[$name]; call_user_func_array($hook, $Args); } ?> All it´s doing is copying the args ($args) into a new array ($Args) by reference, which i would think would be identical to the original array in every way (that matters). Note the code here is an example of usage. The actual hack is denoted by comments. If someone knows a better alternative, by all means, i would love to see it. ---- Server IP: 69.147.83.197 Probable Submitter: 24.102.58.146 (proxied: 127.0.0.1) ---- Manual Page -- http://www.php.net/manual/en/function.call-user-func-array.php Edit -- https://master.php.net/note/edit/91503 Del: integrated -- https://master.php.net/note/delete/91503/integrated Del: useless -- https://master.php.net/note/delete/91503/useless Del: bad code -- https://master.php.net/note/delete/91503/bad+code Del: spam -- https://master.php.net/note/delete/91503/spam Del: non-english -- https://master.php.net/note/delete/91503/non-english Del: in docs -- https://master.php.net/note/delete/91503/in+docs Del: other reasons-- https://master.php.net/note/delete/91503 Reject -- https://master.php.net/note/reject/91503 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156837) next »