Skip to content

Commit 88ff9da

Browse files
committed
Add tests
1 parent 1f7054a commit 88ff9da

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
PFA: instance polymorphism
3+
--FILE--
4+
<?php
5+
6+
class P {
7+
public function m(string $a): void {
8+
echo __METHOD__, PHP_EOL;
9+
var_dump($a);
10+
}
11+
12+
13+
public function get() {
14+
/* The method is resolved before creating the PFA, and captured by the
15+
* PFA. We use the signature of the resolved method. */
16+
return $this->m(?);
17+
}
18+
}
19+
20+
class C extends P {
21+
public function m(string|array $b): void {
22+
echo __METHOD__, PHP_EOL;
23+
var_dump($b);
24+
}
25+
}
26+
27+
for ($i = 0; $i < 2; $i++) {
28+
(new P())->get()(a: 'a');
29+
(new C())->get()(b: []);
30+
}
31+
32+
?>
33+
--EXPECT--
34+
P::m
35+
string(1) "a"
36+
C::m
37+
array(0) {
38+
}
39+
P::m
40+
string(1) "a"
41+
C::m
42+
array(0) {
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
PFA: static polymorphism
3+
--FILE--
4+
<?php
5+
6+
class P {
7+
public static function m(string $a): void {
8+
echo __METHOD__, PHP_EOL;
9+
var_dump($a);
10+
}
11+
12+
13+
public static function get() {
14+
/* The method is resolved before creating the PFA, and captured by the
15+
* PFA. We use the signature of the resolved method. */
16+
return static::m(?);
17+
}
18+
}
19+
20+
class C extends P {
21+
public static function m(string|array $b): void {
22+
echo __METHOD__, PHP_EOL;
23+
var_dump($b);
24+
}
25+
}
26+
27+
for ($i = 0; $i < 2; $i++) {
28+
P::get()(a: 'a');
29+
C::get()(b: []);
30+
}
31+
32+
?>
33+
--EXPECT--
34+
P::m
35+
string(1) "a"
36+
C::m
37+
array(0) {
38+
}
39+
P::m
40+
string(1) "a"
41+
C::m
42+
array(0) {
43+
}

0 commit comments

Comments
 (0)