The Not ! operator in combination with NAN fails with OPcache enabled
Open
Nobody has claimed this yet.
Bug
Category: Optimizer
Status: Requires RFC
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
$a = 100.0;
$b = \NAN;
$cmp = $a > $b; // since NAN always false;
$cmp2 = !($a > $b); // $expected true;
var_dump($cmp);
var_dump($cmp2);
assert($cmp === false);
assert($cmp2 === true);
Resulted in this output:
bool(false)
bool(true)
Resulted in this output with opcache enabled:
bool(false)
bool(false) ❌
But I expected this output instead:
bool(false)
bool(true)
The issue only seems to appear using opcache. Also spotted on different environments with older PHP versions.
PHP 8.3.11 (cli) (built: Aug 30 2024 16:21:34) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.11, Copyright (c) Zend Technologies
with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans
with Zend OPcache v8.3.11, Copyright (c), by Zend Technologies
PHP Version
PHP 8.3.11
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the minimal PHP example from the report with OPcache enabled and disabled, using PHP 8.3.11 or another affected version. Then trace the OPcache optimizer handling of the comparison and negation; done means the assertions pass and both outputs match the expected values when OPcache is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100