Skip to content

Commit 075bc50

Browse files
committed
Resolver::autowireArgument() fixed handling of new-initializer with typehint [Closes #302]
1 parent e74563d commit 075bc50

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/DI/Resolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ private static function autowireArgument(\ReflectionParameter $parameter, callab
642642
throw new ServiceCreationException("{$e->getMessage()} (required by $desc)", 0, $e);
643643
}
644644

645-
if ($res !== null || $parameter->allowsNull()) {
645+
if ($res !== null || $parameter->allowsNull() || $parameter->isOptional()) {
646646
return $res;
647647
} elseif (class_exists($class) || interface_exists($class)) {
648648
throw new ServiceCreationException(sprintf(

tests/DI/Resolver.autowireArguments.81.phpt

+10
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,13 @@ Assert::same(
4141
function () {}
4242
),
4343
);
44+
45+
// object as default with typehint
46+
Assert::same(
47+
['b' => 10],
48+
Resolver::autowireArguments(
49+
new ReflectionFunction(function (stdClass $a = new stdClass, $b = null) {}),
50+
[1 => 10],
51+
function () {}
52+
),
53+
);

0 commit comments

Comments
 (0)