-
-
Notifications
You must be signed in to change notification settings - Fork 74
PhpReflection::getParameterType() can handle PHP 7.1 nullable types #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/DI/PhpReflection.php
Outdated
| if ($param->hasType()) { | ||
| return (PHP_VERSION_ID >= 70100) ? $param->getType()->getName() : (string) $param->getType(); | ||
| } | ||
| return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using more shallow condition structure?
if (PHP_VERSION_ID >= 70100) {
return $param->hasType() ? $param->getType()->getName() : NULL;
} elseif (PHP_VERSION_ID >= 70000) {
return $param->hasType() ? (string) $param->getType() : NULL;
}| Assert::same('array', PhpReflection::getParameterType($params[2])); | ||
| Assert::same('callable', PhpReflection::getParameterType($params[3])); | ||
| Assert::null(PhpReflection::getParameterType($params[4])); | ||
| Assert::same('Test\B', PhpReflection::getParameterType($params[5])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add tests/DI/PhpReflection.getParameterType.php71.phpt (with @phpversion >= 7.1 annotation) with real nullable types.
c424cc3 to
4dc1822
Compare
4dc1822 to
6a27b1d
Compare
|
Updated by JanTvrdik's suggestions. Thanks! |
|
Thank you |
|
What about return type? |
|
Yep, it should be updated as well. I'll prepare another PR. |
Nullable parameter types are prefixed by
?in Reflection in PHP 7.1 which causes that Nette autowiring doesn't work. Even though this behaviour has changed many times in PHP 7.1 ( php/php-src@622d2f4 , php/php-src@8855a2c , php/php-src@f4e68a3 ) this fix uses new preferred way ReflectionNamedType::getName() which looks pretty stable.