note 31858 modified in function.call-user-func-array by aidan

From: Date: Thu, 03 Jun 2004 08:18:58 +0000
Subject: note 31858 modified in function.call-user-func-array by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-70767@lists.php.net to get a copy of this message
If you need to call object and class methods in PHP < 4.0.4, the following code ought to do the trick: <?php if (!function_exists('call_user_func_array')) { function call_user_func_array($func, $args) { $argString = ''; $comma = ''; for ($i = 0; $i < count($args); $i ++) { $argString .= $comma . "\$args[$i]"; $comma = ', '; } if (is_array($func)) { $obj =& $func[0]; $meth = $func[1]; if (is_string($func[0])) { eval("\$retval = $obj::\$meth($argString);"); } else { eval("\$retval = \$obj->\$meth($argString);"); } } else { eval("\$retval = \$func($argString);"); } return $retval; } } ?> --was-- If you need to call object and class methods in PHP < 4.0.4, the following code ought to do the trick: if (!function_exists('call_user_func_array')) { function call_user_func_array($func, $args) { $argString = ''; $comma = ''; for ($i = 0; $i < count($args); $i ++) { $argString .= $comma . "\$args[$i]"; $comma = ', '; } if (is_array($func)) { $obj =& $func[0]; $meth = $func[1]; if (is_string($func[0])) { eval("\$retval = $obj::\$meth($argString);"); } else { eval("\$retval = \$obj->\$meth($argString);"); } } else { eval("\$retval = \$func($argString);"); } return $retval; } } http://www.php.net/manual/en/function.call-user-func-array.php

« previous php.notes (#70767) next »