note 117655 added to function.call-user-func-array
| From: | admin at torntech dot com | Date: | Wed, 15 Jul 2015 14:06:38 +0000 |
| Subject: | note 117655 added to function.call-user-func-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203114@lists.php.net to get a copy of this message | ||
As of PHP 5.6 you can utilize argument unpacking as an alternative to call_user_func_array, and is
often 3 to 4 times faster.
<?php
function foo ($a, $b) {
return $a + $b;
}
$func = 'foo';
$values = array(1, 2);
call_user_func_array($func, $values);
//returns 3
$func(...$values);
//returns 3
?>
Benchmarks from https://gist.github.com/nikic/6390366
cufa with 0 args took 0.43453288078308
switch with 0 args took 0.24134302139282
unpack with 0 args took 0.12418699264526
cufa with 5 args took 0.73408579826355
switch with 5 args took 0.49595499038696
unpack with 5 args took 0.18640494346619
cufa with 100 args took 5.0327250957489
switch with 100 args took 5.291127204895
unpack with 100 args took 1.2362589836121
----
Server IP: 72.52.91.14
Probable Submitter: 50.79.80.225
----
Manual Page -- http://php.net/manual/en/function.call-user-func-array.php
Edit -- https://master.php.net/note/edit/117655
Del: integrated -- https://master.php.net/note/delete/117655/integrated
Del: useless -- https://master.php.net/note/delete/117655/useless
Del: bad code -- https://master.php.net/note/delete/117655/bad+code
Del: spam -- https://master.php.net/note/delete/117655/spam
Del: non-english -- https://master.php.net/note/delete/117655/non-english
Del: in docs -- https://master.php.net/note/delete/117655/in+docs
Del: other reasons-- https://master.php.net/note/delete/117655
Reject -- https://master.php.net/note/reject/117655
Search -- https://master.php.net/manage/user-notes.php