Bug #77058 [NEW]: Type inference in opcache causes side effects
| From: | phpbug at kacena dot name | Date: | Thu, 25 Oct 2018 13:11:41 +0000 |
| Subject: | Bug #77058 [NEW]: Type inference in opcache causes side effects | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-217677@lists.php.net to get a copy of this message | ||
From: phpbug at kacena dot name
Operating system: Debian GNU/Linux 9
PHP version: 7.2.11
Package: opcache
Bug Type: Bug
Bug description:Type inference in opcache causes side effects
Description:
------------
The $x in myfunc() function below confuses opcache and it displays:
Warning: Narrowing occurred during type inference. Please file a bug
report on bugs.php.net in Unknown on line 0.
The problem here is not the Warning itself, but the fact that the bug
makes side effect change to the $Nr variable, wich has dothing to do
with $x. In more complex application it led to dvidision by zero and
caused php-fpm to hang.
The minimal source code without the side-effect (which still throws the
Warning) would be:
<?php function neverCalled(){ while(1){ $x--; $x++; } } ?>
Interesting notes:
sapi/cli/php -d opcache.enable_cli=1 ../buggy-oppcache.php ---wrong
sapi/cli/php -d opcache.enable_cli=1 < ../buggy-oppcache.php ---wrong
cat ../buggy-oppcache.php | sapi/cli/php -d opcache.enable_cli=1
---correct
PHP 5.6 and 7.0 are not affected, only 7.1, 7.2. and 7.3.0RC4
Also switching the position of -- and ++ resolves the issue. It means
putting $x++ before $x-- is fine. Interestingly, if the condition is ++
$Nr >= 1 then it is also ok. But ++ $Nr > 1 still gets the error.
And last stragne behaviour is when I made a change to the soruce file
and run php very quickly, the firust run is ok. Next run throws the
error. Does it have anything to do with the 2 second revalidate_freq
when running in CLI mode? In the first run opcache_get_status() reports
'scripts' as an empty array while the next run has my file there.
Test script:
---------------
<?php //Throws: Warning: Narrowing occurred during type inference.
Please file a bug report on bugs.php.net in Unknown on line 0
function myfunc(){
$Nr = 0;
while(1){
$x--;
$x++;
if( ++ $Nr >= 2 ) break;
}
echo "'$Nr' is expected to be 2",PHP_EOL;
}
echo 'PHP is ',PHP_VERSION, ', Opcache enabled(cli):
',ini_get('opcache.enable_cli'),PHP_EOL;
myfunc();
Expected result:
----------------
$ sapi/cli/php -d opcache.enable_cli=1 ../buggy-oppcache.php
PHP is 7.2.11, Opcache enabled(cli): 1
'2' is expected to be 2
Actual result:
--------------
$ sapi/cli/php -d opcache.enable_cli=1 ../buggy-oppcache.php
Warning: Narrowing occurred during type inference. Please file a bug
report on bugs.php.net in Unknown on line 0
PHP is 7.2.11, Opcache enabled(cli): 1
'' is expected to be 2
--
Edit bug report at https://bugs.php.net/bug.php?id=77058&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77058&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77058&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77058&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77058&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77058&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77058&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77058&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77058&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77058&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77058&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77058&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77058&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77058&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77058&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77058&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77058&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77058&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77058&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77058&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77058&r=mysqlcfg