You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Match typed arguments by type regardless of position
resolve() now binds typed parameters in a first pass: a positional object is
claimed by the parameter declaring its type wherever it appears, so a leading
untyped (scalar) parameter can no longer consume an object meant for a typed
parameter declared after it. Untyped parameters then take the remaining
positional arguments in declaration order.
Add tests for out-of-order typed matching and update the README resolution
order and a type-first example accordingly.
1. An explicit **named** argument (keyed by parameter name)
18
-
2.A **positional**argument already matching the parameter **type**
18
+
2.An argument matching the parameter **type**
19
19
3. The **container**, matched by **type** (non-builtin)
20
-
4. The next **positional** argument
20
+
4. The next remaining **positional** argument
21
21
5. The parameter's **default value**
22
22
6.`null`
23
23
24
-
A trailing **variadic** parameter receives a matching named argument (if any) followed by every remaining positional argument.
24
+
Typed parameters are bound first (steps 1–3), so a positional object is matched by type wherever it sits and an earlier untyped parameter can't consume it; untyped parameters then take the leftover positional arguments in declaration order (step 4). A trailing **variadic** parameter receives a matching named argument (if any) followed by every remaining positional argument.
25
25
26
26
```php
27
27
use Respect\Parameter\ContainerResolver;
@@ -43,6 +43,20 @@ notify(...$args);
43
43
$reflection->newInstanceArgs($args);
44
44
```
45
45
46
+
### Type-first matching
47
+
48
+
A positional object is bound to the parameter that declares its type, wherever each sits in the list —
49
+
so an untyped parameter never accidentally swallows it:
50
+
51
+
```php
52
+
function notify(string $subject, Mailer $mailer) {
0 commit comments