From aa40af0766b990fbe052d6efe89382d6df2ae641 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 21 Sep 2016 18:40:48 +0200 Subject: [PATCH] Helpers::autowireArguments() can handle PHP 7.1 nullable types --- src/DI/Helpers.php | 2 +- tests/DI/Helpers.autowireArguments.php71.phpt | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/DI/Helpers.autowireArguments.php71.phpt diff --git a/src/DI/Helpers.php b/src/DI/Helpers.php index 968d38710..c906ba7fe 100644 --- a/src/DI/Helpers.php +++ b/src/DI/Helpers.php @@ -119,7 +119,7 @@ public static function autowireArguments(\ReflectionFunctionAbstract $method, ar $optCount = 0; } - } elseif ($parameter->isOptional() || $parameter->isDefaultValueAvailable()) { + } elseif (($class && $parameter->allowsNull()) || $parameter->isOptional() || $parameter->isDefaultValueAvailable()) { // !optional + defaultAvailable = func($a = NULL, $b) since 5.4.7 // optional + !defaultAvailable = i.e. Exception::__construct, mysqli::mysqli, ... $res[$num] = $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : NULL; diff --git a/tests/DI/Helpers.autowireArguments.php71.phpt b/tests/DI/Helpers.autowireArguments.php71.phpt new file mode 100644 index 000000000..2d5eb3749 --- /dev/null +++ b/tests/DI/Helpers.autowireArguments.php71.phpt @@ -0,0 +1,42 @@ +