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