File tree Expand file tree Collapse file tree 2 files changed +86
-0
lines changed
Zend/tests/partial_application Expand file tree Collapse file tree 2 files changed +86
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments