PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/pear/PHP/Compat/Function/call_user_func_array.php

http://akelosframework.googlecode.com/
PHP | 75 lines | 35 code | 8 blank | 32 comment | 9 complexity | 7ca73e01d3140be4634d46a9041a1015 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2004 The PHP Group |
  6. // +----------------------------------------------------------------------+
  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 |
  9. // | available at through the world-wide-web at |
  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 |
  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. |
  14. // +----------------------------------------------------------------------+
  15. // | Authors: Aidan Lister <aidan@php.net> |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: call_user_func_array.php,v 1.13 2005/01/26 04:55:13 aidan Exp $
  19. /**
  20. * Replace call_user_func_array()
  21. *
  22. * @category PHP
  23. * @package PHP_Compat
  24. * @link http://php.net/function.call_user_func_array
  25. * @author Aidan Lister <aidan@php.net>
  26. * @version $Revision: 1.13 $
  27. * @since PHP 4.0.4
  28. * @require PHP 4.0.0 (user_error)
  29. */
  30. if (!function_exists('call_user_func_array')) {
  31. function call_user_func_array($function, $param_arr)
  32. {
  33. $param_arr = array_values((array) $param_arr);
  34. // Sanity check
  35. if (!is_callable($function)) {
  36. if (is_array($function) && count($function) > 2) {
  37. $function = $function[0] . '::' . $function[1];
  38. }
  39. $error = sprintf('call_user_func_array() First argument is expected ' .
  40. 'to be a valid callback, \'%s\' was given', $function);
  41. user_error($error, E_USER_WARNING);
  42. return;
  43. }
  44. // Build argument string
  45. $arg_string = '';
  46. $comma = '';
  47. for ($i = 0, $x = count($param_arr); $i < $x; $i++) {
  48. $arg_string .= $comma . "\$param_arr[$i]";
  49. $comma = ', ';
  50. }
  51. // Determine method of calling function
  52. if (is_array($function)) {
  53. $object =& $function[0];
  54. $method = $function[1];
  55. // Static vs method call
  56. if (is_string($function[0])) {
  57. eval("\$retval = $object::\$method($arg_string);");
  58. } else {
  59. eval("\$retval = \$object->\$method($arg_string);");
  60. }
  61. } else {
  62. eval("\$retval = \$function($arg_string);");
  63. }
  64. return $retval;
  65. }
  66. }
  67. ?>