You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The Not ! operator in combination with NAN fails with OPcache enabled #15773
While identity comparison (=== and !==) can be applied to arbitrary values, the other comparison operators should only be applied to comparable values. The result of comparing incomparable values is undefined, and should not be relied upon.
That's the easy way out.
Maybe its possible to show warnings if given pattern is used.
Yeah, a warning would be less intrusive than throwing, but would also be a BC break. It seems to me that this warrants the RFC process.
Might be something for static type checkers.
A static type checker may not be able to detect all cases, especially as NaN is a float, and can be the result of a couple of operations.
changed the title [-]The Not ! opperator in componation with NAN fails with OPcache enabled[/-][+]The Not ! operator in combination with NAN fails with OPcache enabled[/+]on Jan 28, 2025
Clearing only bit 0x10 (pass 5, the CFG block pass) from the default 0x7FFEBFFF gives the unoptimized result back.
!($x < y), !($x > y) and !($x <= y) are all affected. That holds for a returned value and for an if condition, and with untyped operands too.
With the default opcache.file_update_protection=2, a script modified in the last 2 s is not cached, so it is not optimized. Running a repro right after saving it prints the correct result, which looks like a fix.
opcache.enable_cli defaults to 0, so a CLI test suite runs such code unoptimized and passes. We had a guard written as if ( ! ( abs( $x ) < 1e12 ) ) that was meant to send NAN and huge values to a float path. Under opcache NAN skipped that path and reached an (int) cast. The guard is now written is_nan( $x ) || abs( $x ) >= 1e12.
Activity
cmb69 commentedon Sep 6, 2024
This is likely due to the optimizer converting
!($a > $b)to$a <= $b.If I remember correctly, this has been reported before. Well, might have had https://bugs.php.net/bug.php?id=80701 in mind.
cmb69 commentedon Sep 6, 2024
Indeed (simplified script):
Might be wontfix, since the optimization is generally useful, and
NaNis very special anyway. Maybe PHP should throw on anyNaNcomparisons.jsiefer commentedon Sep 6, 2024
I found it super mean to debug, but I am with you on the performance optimization.
Maybe its possible to show warnings if given pattern is used. Might be something for static type checkers.... just thinking loud
cmb69 commentedon Sep 6, 2024
Well, actually
NaNis a somewhat special case of incomparable values, and the [documentation](language.operators.comparison.incomparable states:That's the easy way out.
Yeah, a warning would be less intrusive than throwing, but would also be a BC break. It seems to me that this warrants the RFC process.
A static type checker may not be able to detect all cases, especially as
NaNis a float, and can be the result of a couple of operations.[-]The Not ! opperator in componation with NAN fails with OPcache enabled[/-][+]The Not ! operator in combination with NAN fails with OPcache enabled[/+]mvalasis commentedon Nov 22, 2026
Still reproduces on PHP 8.5.8 and 8.6.0 (CLI,
-n, opcache built in):0x10(pass 5, the CFG block pass) from the default0x7FFEBFFFgives the unoptimized result back.!($x < y),!($x > y)and!($x <= y)are all affected. That holds for a returned value and for anifcondition, and with untyped operands too.opcache.file_update_protection=2, a script modified in the last 2 s is not cached, so it is not optimized. Running a repro right after saving it prints the correct result, which looks like a fix.opcache.enable_clidefaults to 0, so a CLI test suite runs such code unoptimized and passes. We had a guard written asif ( ! ( abs( $x ) < 1e12 ) )that was meant to send NAN and huge values to a float path. Under opcache NAN skipped that path and reached an(int)cast. The guard is now writtenis_nan( $x ) || abs( $x ) >= 1e12.