| Line 1... |
Line 1... |
| 1 |
<?php |
1 |
<?php |
| 2 |
// +----------------------------------------------------------------------+ |
2 |
// +----------------------------------------------------------------------+ |
| 3 |
// | PHP Version 4 | |
3 |
// | PHP Version 4 | |
| 4 |
// +----------------------------------------------------------------------+ |
4 |
// +----------------------------------------------------------------------+ |
| 5 |
// | Copyright (c) 1997-2004 The PHP Group | |
5 |
// | Copyright (c) 1997-2004 The PHP Group | |
| 6 |
// +----------------------------------------------------------------------+ |
6 |
// +----------------------------------------------------------------------+ |
| 7 |
// | This source file is subject to version 3.0 of the PHP license, | |
7 |
// | This source file is subject to version 3.0 of the PHP license, | |
| 8 |
// | that is bundled with this package in the file LICENSE, and is | |
8 |
// | that is bundled with this package in the file LICENSE, and is | |
| 9 |
// | available at through the world-wide-web at | |
9 |
// | available at through the world-wide-web at | |
| 10 |
// | http://www.php.net/license/3_0.txt. | |
10 |
// | http://www.php.net/license/3_0.txt. | |
| 11 |
// | If you did not receive a copy of the PHP license and are unable to | |
11 |
// | If you did not receive a copy of the PHP license and are unable to | |
| 12 |
// | obtain it through the world-wide-web, please send a note to | |
12 |
// | obtain it through the world-wide-web, please send a note to | |
| 13 |
// | license@php.net so we can mail you a copy immediately. | |
13 |
// | license@php.net so we can mail you a copy immediately. | |
| 14 |
// +----------------------------------------------------------------------+ |
14 |
// +----------------------------------------------------------------------+ |
| 15 |
// | Authors: Aidan Lister <aidan@php.net> | |
15 |
// | Authors: Aidan Lister <aidan@php.net> | |
| 16 |
// +----------------------------------------------------------------------+ |
16 |
// +----------------------------------------------------------------------+ |
| 17 |
// |
17 |
// |
| 18 |
// $Id: call_user_func_array.php,v 1.13 2005/01/26 04:55:13 aidan Exp $ |
18 |
// $Id: call_user_func_array.php,v 1.13 2005/01/26 04:55:13 aidan Exp $ |
| 19 |
|
19 |
|
| 20 |
|
20 |
|
| 21 |
/** |
21 |
/** |
| 22 |
* Replace call_user_func_array() |
22 |
* Replace call_user_func_array() |
| 23 |
* |
23 |
* |
| 24 |
* @category PHP |
24 |
* @category PHP |
| 25 |
* @package PHP_Compat |
25 |
* @package PHP_Compat |
| 26 |
* @link http://php.net/function.call_user_func_array |
26 |
* @link http://php.net/function.call_user_func_array |
| 27 |
* @author Aidan Lister <aidan@php.net> |
27 |
* @author Aidan Lister <aidan@php.net> |
| 28 |
* @version $Revision: 1.13 $ |
28 |
* @version $Revision: 1.13 $ |
| 29 |
* @since PHP 4.0.4 |
29 |
* @since PHP 4.0.4 |
| 30 |
* @require PHP 4.0.0 (user_error) |
30 |
* @require PHP 4.0.0 (user_error) |
| 31 |
*/ |
31 |
*/ |
| 32 |
if (!function_exists('call_user_func_array')) { |
32 |
if (!function_exists('call_user_func_array')) { |
| 33 |
function call_user_func_array($function, $param_arr) |
33 |
function call_user_func_array($function, $param_arr) |
| 34 |
{ |
34 |
{ |
| 35 |
$param_arr = array_values((array) $param_arr); |
35 |
$param_arr = array_values((array) $param_arr); |
| 36 |
|
36 |
|
| 37 |
// Sanity check |
37 |
// Sanity check |
| 38 |
if (!is_callable($function)) { |
38 |
if (!is_callable($function)) { |
| 39 |
if (is_array($function) && count($function) > 2) { |
39 |
if (is_array($function) && count($function) > 2) { |
| 40 |
$function = $function[0] . '::' . $function[1]; |
40 |
$function = $function[0] . '::' . $function[1]; |
| 41 |
} |
41 |
} |
| 42 |
$error = sprintf('call_user_func_array() First argument is expected ' . |
42 |
$error = sprintf('call_user_func_array() First argument is expected ' . |
| 43 |
'to be a valid callback, \'%s\' was given', $function); |
43 |
'to be a valid callback, \'%s\' was given', $function); |
| 44 |
user_error($error, E_USER_WARNING); |
44 |
user_error($error, E_USER_WARNING); |
| 45 |
return; |
45 |
return; |
| 46 |
} |
46 |
} |
| 47 |
|
47 |
|
| 48 |
// Build argument string |
48 |
// Build argument string |
| 49 |
$arg_string = ''; |
49 |
$arg_string = ''; |
| 50 |
$comma = ''; |
50 |
$comma = ''; |
| 51 |
for ($i = 0, $x = count($param_arr); $i < $x; $i++) { |
51 |
for ($i = 0, $x = count($param_arr); $i < $x; $i++) { |
| 52 |
$arg_string .= $comma . "\$param_arr[$i]"; |
52 |
$arg_string .= $comma . "\$param_arr[$i]"; |
| 53 |
$comma = ', '; |
53 |
$comma = ', '; |
| 54 |
} |
54 |
} |
| 55 |
|
55 |
|
| 56 |
// Determine method of calling function |
56 |
// Determine method of calling function |
| 57 |
if (is_array($function)) { |
57 |
if (is_array($function)) { |
| 58 |
$object =& $function[0]; |
58 |
$object =& $function[0]; |
| 59 |
$method = $function[1]; |
59 |
$method = $function[1]; |
| 60 |
|
60 |
|
| 61 |
// Static vs method call |
61 |
// Static vs method call |
| 62 |
if (is_string($function[0])) { |
62 |
if (is_string($function[0])) { |
| 63 |
eval("\$retval = $object::\$method($arg_string);"); |
63 |
eval("\$retval = $object::\$method($arg_string);"); |
| 64 |
} else { |
64 |
} else { |
| 65 |
eval("\$retval = \$object->\$method($arg_string);"); |
65 |
eval("\$retval = \$object->\$method($arg_string);"); |
| 66 |
} |
66 |
} |
| 67 |
} else { |
67 |
} else { |
| 68 |
eval("\$retval = \$function($arg_string);"); |
68 |
eval("\$retval = \$function($arg_string);"); |
| 69 |
} |
69 |
} |
| 70 |
|
70 |
|
| 71 |
return $retval; |
71 |
return $retval; |
| 72 |
} |
72 |
} |
| 73 |
} |
73 |
} |
| 74 |
|
74 |
|
| 75 |
?> |
75 |
?> |
| 76 |
|
76 |
|