Skip to content
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

PhpReflection::getParameterType() can handle PHP 7.1 nullable types #126

Merged
merged 1 commit into from Sep 21, 2016

Conversation

@MartinMajor
Copy link
Contributor

MartinMajor commented Sep 21, 2016

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.

if ($param->hasType()) {
return (PHP_VERSION_ID >= 70100) ? $param->getType()->getName() : (string) $param->getType();
}
return NULL;

This comment has been minimized.

Copy link
@JanTvrdik

JanTvrdik Sep 21, 2016

Contributor

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;
}
@@ -27,3 +27,4 @@ Assert::same('Test\B', PhpReflection::getParameterType($params[1]));
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]));

This comment has been minimized.

Copy link
@JanTvrdik

JanTvrdik Sep 21, 2016

Contributor

You should add tests/DI/PhpReflection.getParameterType.php71.phpt (with @phpversion >= 7.1 annotation) with real nullable types.

@MartinMajor MartinMajor force-pushed the MartinMajor:nullable-types branch from c424cc3 to 4dc1822 Sep 21, 2016
@MartinMajor MartinMajor force-pushed the MartinMajor:nullable-types branch from 4dc1822 to 6a27b1d Sep 21, 2016
@MartinMajor

This comment has been minimized.

Copy link
Contributor Author

MartinMajor commented Sep 21, 2016

Updated by JanTvrdik's suggestions. Thanks!

@dg

This comment has been minimized.

Copy link
Member

dg commented Sep 21, 2016

Thank you

@dg dg merged commit e62128f into nette:master Sep 21, 2016
1 of 2 checks passed
1 of 2 checks passed
coverage/coveralls Coverage decreased (-0.05%) to 90.753%
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@dg

This comment has been minimized.

Copy link
Member

dg commented Sep 21, 2016

What about return type?

@MartinMajor MartinMajor deleted the MartinMajor:nullable-types branch Sep 21, 2016
@MartinMajor

This comment has been minimized.

Copy link
Contributor Author

MartinMajor commented Sep 21, 2016

Yep, it should be updated as well. I'll prepare another PR.

dg added a commit that referenced this pull request Dec 21, 2016
…pes"

Revert "PhpReflection::getParameterType() can handle PHP 7.1 nullable types (#126)"

This reverts commit 7d1385a and 9fcfe47.

Behavior in 7.1.0 stable has been changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.