Skip to content

Commit 01d28e1

Browse files
committed
Fix edge cases when passing null
1 parent 4878bb0 commit 01d28e1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/php/lang/reflection/Routine.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public static function pass($reflect, $args) {
9999
if ($param->isVariadic()) {
100100
while ($args) $pass[]= array_shift($args);
101101
break;
102-
} else if (isset($args[$param->name])) {
102+
} else if (array_key_exists($param->name, $args)) {
103103
$pass[]= $args[$param->name];
104104
unset($args[$param->name]);
105-
} else if (isset($args[$i])) {
105+
} else if (array_key_exists($i, $args)) {
106106
$pass[]= $args[$i];
107107
unset($args[$i]);
108108
} else if ($param->isOptional()) {

src/test/php/lang/reflection/unittest/ArgumentPassingTest.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public function pass_ordered() {
1313
Assert::equals([1, 2], Routine::pass($f, [1, 2]));
1414
}
1515

16+
#[Test]
17+
public function pass_ordered_null() {
18+
$f= new ReflectionFunction(fn($a, $b) => null);
19+
Assert::equals([null, 2], Routine::pass($f, [null, 2]));
20+
}
21+
1622
#[Test, Expect(class: Error::class, message: 'Missing parameter $a')]
1723
public function missing() {
1824
$f= new ReflectionFunction(fn($a, $b) => null);
@@ -31,6 +37,12 @@ public function pass_named() {
3137
Assert::equals([1, 2], Routine::pass($f, ['a' => 1, 'b' => 2]));
3238
}
3339

40+
#[Test]
41+
public function pass_named_null() {
42+
$f= new ReflectionFunction(fn($a, $b) => null);
43+
Assert::equals([null, 2], Routine::pass($f, ['a' => null, 'b' => 2]));
44+
}
45+
3446
#[Test]
3547
public function pass_named_out_of_order() {
3648
$f= new ReflectionFunction(fn($a, $b) => null);

0 commit comments

Comments
 (0)