bug68475.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. Bug #68475 Calling function using $callable() syntax with strings of form 'Class::method'
  3. --FILE--
  4. <?php
  5. class TestClass
  6. {
  7. public static function staticMethod()
  8. {
  9. echo "Static method called!\n";
  10. }
  11. public static function staticMethodWithArgs($arg1, $arg2, $arg3)
  12. {
  13. printf("Static method called with args: %s, %s, %s\n", $arg1, $arg2, $arg3);
  14. }
  15. }
  16. // Test basic call using Class::method syntax.
  17. $callback = 'TestClass::staticMethod';
  18. $callback();
  19. // Case should not matter.
  20. $callback = 'testclass::staticmethod';
  21. $callback();
  22. $args = ['arg1', 'arg2', 'arg3'];
  23. $callback = 'TestClass::staticMethodWithArgs';
  24. // Test call with args.
  25. $callback($args[0], $args[1], $args[2]);
  26. // Test call with splat operator.
  27. $callback(...$args);
  28. // Reference undefined method.
  29. $callback = 'TestClass::undefinedMethod';
  30. try {
  31. $callback();
  32. } catch (Error $e) {
  33. echo $e->getMessage() . "\n";
  34. }
  35. // Reference undefined class.
  36. $callback = 'UndefinedClass::testMethod';
  37. try {
  38. $callback();
  39. } catch (Error $e) {
  40. echo $e->getMessage() . "\n";
  41. }
  42. ?>
  43. --EXPECT--
  44. Static method called!
  45. Static method called!
  46. Static method called with args: arg1, arg2, arg3
  47. Static method called with args: arg1, arg2, arg3
  48. Call to undefined method TestClass::undefinedMethod()
  49. Class "UndefinedClass" not found