Bug #80184 [NEW]: Complex expression in while / if statements resolves to false incorrectly
| From: | jelly dot legend at gmail dot com | Date: | Sun, 04 Oct 2020 12:58:24 +0000 |
| Subject: | Bug #80184 [NEW]: Complex expression in while / if statements resolves to false incorrectly | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-229371@lists.php.net to get a copy of this message | ||
From: jelly dot legend at gmail dot com
Operating system: MacOS 10.15.6
PHP version: 8.0.0rc1
Package: opcache
Bug Type: Bug
Bug description:Complex expression in while / if statements resolves to false incorrectly
Description:
------------
If a use a complex expression as an if condition or while condition, it
incorrectly resolves to false. While it correctly evaluates it if passed
to a variable and printed.
PHP version:
PHP 8.0.0rc1 (cli) (built: Oct 4 2020 13:58:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.0.0rc1, Copyright (c), by Zend Technologies
php.development-ini changes:
zend_extension=opcache
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
If I disable opcache I get the correct results.
PHP was built from source. With following configuration.
./configure \
--prefix=.../php-8.0.0rc1 \
--with-config-file-path=.../php-8.0.0rc1/etc \
--enable-mbstring \
--enable-sockets \
--enable-opcache \
--with-openssl=/usr/local/openssl \
--with-curl \
--with-sodium \
--with-bz2 \
--with-zlib \
--with-zip
I was first noticed the bug on beta-4 but decided to try it out in rc-1
instead.
Test script:
---------------
$factory = function (string $msg): Closure {
return function () use ($msg): void {
echo $msg;
};
};
$callbacks = [
$factory('First item!'),
$factory('Second item!'),
$factory('Third item!'),
$factory('Fourth item!'),
];
$nl = function (): void {
echo PHP_EOL;
};
while ((null !== $callback = array_shift($callbacks)) && ($callback() ||
$nl() || true))
/**/; // exists after first item, should iterate thought all
// Full test at: https://pastebin.com/br54nGvM
Expected result:
----------------
First item!
Second item!
Third item!
Fourth item!
Actual result:
--------------
First item!
--
Edit bug report at https://bugs.php.net/bug.php?id=80184&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80184&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80184&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80184&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80184&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80184&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80184&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80184&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80184&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80184&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80184&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80184&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80184&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80184&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80184&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80184&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80184&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80184&r=mysqlcfg