1
0
mirror of https://github.com/php/php-src.git synced 2026-04-26 01:18:19 +02:00
Files
archived-php-src/Zend/tests/named_params/__call.phpt
T
Nikita Popov d92229d8c7 Implement named parameters
From an engine perspective, named parameters mainly add three
concepts:

 * The SEND_* opcodes now accept a CONST op2, which is the
   argument name. For now, it is looked up by linear scan and
   runtime cached.
 * This may leave UNDEF arguments on the stack. To avoid having
   to deal with them in other places, a CHECK_UNDEF_ARGS opcode
   is used to either replace them with defaults, or error.
 * For variadic functions, EX(extra_named_params) are collected
   and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS.

RFC: https://wiki.php.net/rfc/named_params

Closes GH-5357.
2020-07-31 15:53:36 +02:00

38 lines
751 B
PHP

--TEST--
Check that __call() and __callStatic() work with named parameters
--FILE--
<?php
class Test {
public function __call(string $method, array $args) {
$this->{'_'.$method}(...$args);
}
public static function __callStatic(string $method, array $args) {
(new static)->{'_'.$method}(...$args);
}
private function _method($a = 'a', $b = 'b') {
echo "a: $a, b: $b\n";
}
}
$obj = new class { public function __toString() { return "STR"; } };
$test = new Test;
$test->method(a: 'A', b: 'B');
$test->method(b: 'B');
$test->method(b: $obj);
Test::method(a: 'A', b: 'B');
Test::method(b: 'B');
Test::method(b: $obj);
?>
--EXPECT--
a: A, b: B
a: a, b: B
a: a, b: STR
a: A, b: B
a: a, b: B
a: a, b: STR