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

From: Date: Sun, 07 Nov 2010 05:07:40 +0000
Subject: note 100794 added to function.call-user-func-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-173826@lists.php.net to get a copy of this message
This function is relatively slow (as of PHP 5.3.3) and if you are calling a method with a known number of parameters it is much faster to call it this way: $class->{$method}($param1, $param2); vs call_user_func_array (array($class, $method), array($param1, $param2)); But if you don't know how many parameters... The wrapper function below is slightly faster, but the problem now is that you are making two function calls. One to the wrapper and one to the function. However, If you are able to take this code out of the function and use it inline it is nearly twice as fast (in most cases) as calling call_user_func_array natively. function wrap_call_user_func_array($c, $a, $p) { switch(count($p)) { case 0: $c->{$a}(); break; case 1: $c->{$a}($p[0]); break; case 2: $c->{$a}($p[0], $p[1]); break; case 3: $c->{$a}($p[0], $p[1], $p[2]); break; case 4: $c->{$a}($p[0], $p[1], $p[2], $p[3]); break; case 5: $c->{$a}($p[0], $p[1], $p[2], $p[3], $p[4]); break; default: call_user_func_array(array($c, $a), $p); break; } } ---- Server IP: 64.71.164.2 Probable Submitter: 96.38.116.112 ---- Manual Page -- http://www.php.net/manual/en/function.call-user-func-array.php Edit -- https://master.php.net/note/edit/100794 Del: integrated -- https://master.php.net/note/delete/100794/integrated Del: useless -- https://master.php.net/note/delete/100794/useless Del: bad code -- https://master.php.net/note/delete/100794/bad+code Del: spam -- https://master.php.net/note/delete/100794/spam Del: non-english -- https://master.php.net/note/delete/100794/non-english Del: in docs -- https://master.php.net/note/delete/100794/in+docs Del: other reasons-- https://master.php.net/note/delete/100794 Reject -- https://master.php.net/note/reject/100794 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173826) next »