note 109988 added to function.func-get-args

From: Date: Sat, 08 Sep 2012 05:39:56 +0000
Subject: note 109988 added to function.func-get-args
Groups: php.notes 
Request: Send a blank email to php-notes+get-190584@lists.php.net to get a copy of this message
I vote for a func_get_args_byRef() function in the next version of php. It would be beneficial for users to be able to create functions with variable arguments by reference like unset(). The only way I found to code a function like that which I can call with this code: <?php fixArrayKeys($arr1,$arr2,$arr3...) ?> is by using an ugly function declaration like so... <?php function fixArrayKeys(array &$arr1,array &$arr2=null,array &$arr3=null,array &$arr4=null,array &$arr5=null,array &$arr6=null,array &$arr7=null,array &$arr8=null,array &$arr9=null,array &$arr10=null) { $args = func_get_args(); if(count($args)>10) trigger_error("fixArrayKeys() can only except up to ten arguments", E_USER_ERROR); foreach($args as &$arg) { $Arr=array(); $i=0; foreach($arg as $val) { $Arr[$i]=$val; $i++; } $arg = $Arr; } return $newArray; } ?> you can also use debug_backtrace() to get a similar effect, but that seems like a lot of overhead just to get access to function arguments to me. ---- Server IP: 69.147.83.197 Probable Submitter: 24.98.82.185 ---- Manual Page -- http://www.php.net/manual/en/function.func-get-args.php Edit -- https://master.php.net/note/edit/109988 Del: integrated -- https://master.php.net/note/delete/109988/integrated Del: useless -- https://master.php.net/note/delete/109988/useless Del: bad code -- https://master.php.net/note/delete/109988/bad+code Del: spam -- https://master.php.net/note/delete/109988/spam Del: non-english -- https://master.php.net/note/delete/109988/non-english Del: in docs -- https://master.php.net/note/delete/109988/in+docs Del: other reasons-- https://master.php.net/note/delete/109988 Reject -- https://master.php.net/note/reject/109988 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190584) next »