__call.phpt 751 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. Check that __call() and __callStatic() work with named parameters
  3. --FILE--
  4. <?php
  5. class Test {
  6. public function __call(string $method, array $args) {
  7. $this->{'_'.$method}(...$args);
  8. }
  9. public static function __callStatic(string $method, array $args) {
  10. (new static)->{'_'.$method}(...$args);
  11. }
  12. private function _method($a = 'a', $b = 'b') {
  13. echo "a: $a, b: $b\n";
  14. }
  15. }
  16. $obj = new class { public function __toString() { return "STR"; } };
  17. $test = new Test;
  18. $test->method(a: 'A', b: 'B');
  19. $test->method(b: 'B');
  20. $test->method(b: $obj);
  21. Test::method(a: 'A', b: 'B');
  22. Test::method(b: 'B');
  23. Test::method(b: $obj);
  24. ?>
  25. --EXPECT--
  26. a: A, b: B
  27. a: a, b: B
  28. a: a, b: STR
  29. a: A, b: B
  30. a: a, b: B
  31. a: a, b: STR