fork download
  1. <?php
  2.  
  3. class Someclass
  4. {
  5. function methodPrint($x, $y)
  6. {
  7. return $x + $y;
  8. }
  9. }
  10.  
  11. function functionPrint($x, $y)
  12. {
  13. return $x + $y;
  14. }
  15.  
  16. function myFunction(callable $f)
  17. {
  18. $args = func_get_args();
  19. array_shift($args);
  20. return call_user_func_array($f, $args);
  21. }
  22.  
  23. $object = new Someclass();
  24. $x = 1;
  25. $y = 2;
  26.  
  27. echo myFunction([$object, 'methodPrint'], 1, 2);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
3