indirect_call_string_001.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. Indirect call with 'Class::method' syntax with class in namespace
  3. --FILE--
  4. <?php
  5. namespace TestNamespace
  6. {
  7. class TestClass
  8. {
  9. public static function staticMethod()
  10. {
  11. echo "Static method called!\n";
  12. }
  13. public static function staticMethodWithArgs($arg1, $arg2, $arg3)
  14. {
  15. printf("Static method called with args: %s, %s, %s\n", $arg1, $arg2, $arg3);
  16. }
  17. }
  18. }
  19. namespace CallNamespace
  20. {
  21. // Test basic call using Class::method syntax.
  22. $callback = 'TestNamespace\TestClass::staticMethod';
  23. $callback();
  24. // Case should not matter.
  25. $callback = 'testnamespace\testclass::staticmethod';
  26. $callback();
  27. $args = ['arg1', 'arg2', 'arg3'];
  28. $callback = 'TestNamespace\TestClass::staticMethodWithArgs';
  29. // Test call with args.
  30. $callback($args[0], $args[1], $args[2]);
  31. // Test call with splat operator.
  32. $callback(...$args);
  33. }
  34. ?>
  35. --EXPECT--
  36. Static method called!
  37. Static method called!
  38. Static method called with args: arg1, arg2, arg3
  39. Static method called with args: arg1, arg2, arg3