Bug #77058 [Opn->Asn]: Type inference in opcache causes side effects
| From: | nikic@php.net | Date: | Thu, 25 Oct 2018 14:24:29 +0000 |
| Subject: | Bug #77058 [Opn->Asn]: Type inference in opcache causes side effects | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217678@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77058&edit=1
ID: 77058
Updated by: nikic@php.net
Reported by: phpbug at kacena dot name
Summary: Type inference in opcache causes side effects
-Status: Open
+Status: Assigned
Type: Bug
Package: opcache
Operating System: Debian GNU/Linux 9
PHP Version: 7.2.11
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2018-10-25 13:11:41] phpbug at kacena dot name
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 this bug report at https://bugs.php.net/bug.php?id=77058&edit=1