Repository navigation
Turn a NAN float type into the 'NAN' string type without casting it - #6992
Merged
Merged
Conversation
PHP 8.5 warns "unexpected NAN value was coerced to string" when NAN is cast to string, and zend_double_to_str() in the turbo mirror warns the same way. That made PHPStan report a phpstan.php error while analysing code where a float narrows to NAN, such as $x >= 10 || ... . Amp-Thread-ID: https://ampcode.com/threads/T-01a1ad6c-dec2-72ff-bbe8-5b3b62746c94
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On PHP 8.5,
(string) NANwarns "unexpected NAN value was coerced to string".ConstantFloatType::toString()cast its value directly, and the turbo mirror'szend_double_to_str()warns the same way. So analysing code where a float narrows toNANmade PHPStan report aphpstan.phperror at ConstantFloatType.php:111.It shows up in self-analysis of #6974: in
BenchmarkReport::formatPercent(),$percent >= 10 || $percent === round($percent) ? ... : sprintf('%.1f', $percent)narrows$percentto a type that includesNAN, andmake phpstanfails on PHP 8.5 and 8.6, with and without the turbo extension.Both implementations now return the
'NAN'string type for a NAN before casting, the same string PHP produces.INFand-INFdon't warn and are unchanged.Tests:
nsrt/nan-to-string.phpfails on 2.3.x with the warning (PHPUnit'sfailOnWarning), both without and with the turbo extension, and passes with this change. The full paratest suite passes on PHP 8.5 without and with the extension, exceptOverridingMethodRuleConfigPhpTest::testTentativeReturnTypesInPhpVersionRange, which fails the same way in this environment without the change, and oneDirectoryWalkerTestflake. turbo-extsmoke.phpandsignature-parity.phppass.This isn't a performance change, so it has no timings.