Skip to content

Commit 9fee741

Browse files
committed
Additional test cases
1 parent 3e2eac9 commit 9fee741

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

Zend/tests/named_params/lsp_no_conflict.phpt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,41 @@ class D implements I, J, K {
4545
(new D)->method(j: 42);
4646
(new D)->method(k: 42);
4747
(new D)->method(d: 42);
48+
echo "\n";
49+
50+
trait T {
51+
abstract public function method($t);
52+
}
53+
class X {
54+
public function method($x) {
55+
echo __METHOD__ . ": $x\n";
56+
}
57+
}
58+
class Y extends X {
59+
use T;
60+
61+
public function method($y) {
62+
echo __METHOD__ . ": $y\n";
63+
}
64+
}
65+
66+
(new Y)->method(t: 42);
67+
(new Y)->method(x: 42);
68+
(new Y)->method(y: 42);
69+
echo "\n";
70+
71+
// TODO: This case currently leaks.
72+
/*trait T2 {
73+
public function method($t) {
74+
echo __METHOD__ . ": $t\n";
75+
}
76+
}
77+
class Z extends X {
78+
use T2;
79+
}
80+
81+
(new Z)->method(x: 42);
82+
(new Z)->method(t: 42);*/
4883

4984
?>
5085
--EXPECT--
@@ -58,3 +93,7 @@ D::method: 42
5893
D::method: 42
5994
D::method: 42
6095
D::method: 42
96+
97+
Y::method: 42
98+
Y::method: 42
99+
Y::method: 42
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
Can use parameter names from proto methods (variadic behavior)
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
public function method($a) {
8+
echo __METHOD__ . ": $a\n";
9+
}
10+
}
11+
class B extends A {
12+
public function method(...$args) {
13+
echo __METHOD__ . ": " . json_encode($args) . "\n";
14+
}
15+
}
16+
class C extends B {
17+
public function method($c = null, ...$args) {
18+
echo __METHOD__ . ": " . json_encode($c) . ", " . json_encode($args) . "\n";
19+
}
20+
}
21+
class D extends B {
22+
// #2 $a does not conflict with #1 $a because it has been shadowed variadically
23+
public function method($c = null, $a = null, ...$args) {
24+
echo __METHOD__ . ": " . json_encode($c) . ", " . json_encode($a)
25+
. ", " . json_encode($args) . "\n";
26+
}
27+
}
28+
29+
(new B)->method(a: 42);
30+
(new B)->method(b: 42);
31+
echo "\n";
32+
(new C)->method(a: 42);
33+
(new C)->method(b: 42);
34+
(new C)->method(c: 42);
35+
echo "\n";
36+
(new D)->method(a: 42);
37+
(new D)->method(b: 42);
38+
(new D)->method(c: 42);
39+
40+
?>
41+
--EXPECT--
42+
B::method: {"a":42}
43+
B::method: {"b":42}
44+
45+
C::method: null, {"a":42}
46+
C::method: null, {"b":42}
47+
C::method: 42, []
48+
49+
D::method: null, 42, []
50+
D::method: null, null, {"b":42}
51+
D::method: 42, null, []

Zend/zend_execute.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4302,7 +4302,7 @@ static zend_always_inline uint32_t zend_get_arg_offset_by_name(
43024302
*(uintptr_t *)(cache_slot + 1) = Z_LVAL_P(zv);
43034303
return Z_LVAL_P(zv);
43044304
}
4305-
return (uint32_t) - 1;
4305+
goto not_found;
43064306
}
43074307

43084308
uint32_t num_args = fbc->common.num_args;
@@ -4327,6 +4327,7 @@ static zend_always_inline uint32_t zend_get_arg_offset_by_name(
43274327
}
43284328
}
43294329

4330+
not_found:
43304331
if (fbc->common.fn_flags & ZEND_ACC_VARIADIC) {
43314332
*cache_slot = fbc;
43324333
*(uintptr_t *)(cache_slot + 1) = fbc->common.num_args;

0 commit comments

Comments
 (0)