mirror of
https://github.com/php/php-src.git
synced 2026-10-29 02:07:35 +08:00
RFC: https://wiki.php.net/rfc/partial_function_application_v2 Co-authored-by: Joe Watkins <krakjoe@php.net>
44 lines
686 B
PHP
44 lines
686 B
PHP
--TEST--
|
|
PFA: instance polymorphism
|
|
--FILE--
|
|
<?php
|
|
|
|
class P {
|
|
public function m(string $a): void {
|
|
echo __METHOD__, PHP_EOL;
|
|
var_dump($a);
|
|
}
|
|
|
|
|
|
public function get() {
|
|
/* The method is resolved before creating the PFA, and captured by the
|
|
* PFA. We use the signature of the resolved method. */
|
|
return $this->m(?);
|
|
}
|
|
}
|
|
|
|
class C extends P {
|
|
public function m(string|array $b): void {
|
|
echo __METHOD__, PHP_EOL;
|
|
var_dump($b);
|
|
}
|
|
}
|
|
|
|
for ($i = 0; $i < 2; $i++) {
|
|
(new P())->get()(a: 'a');
|
|
(new C())->get()(b: []);
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
P::m
|
|
string(1) "a"
|
|
C::m
|
|
array(0) {
|
|
}
|
|
P::m
|
|
string(1) "a"
|
|
C::m
|
|
array(0) {
|
|
}
|