php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77058 Type inference in opcache causes side effects
Submitted: 2018-10-25 13:11 UTC Modified: 2018-10-25 14:24 UTC
From: phpbug at kacena dot name Assigned: nikic (profile)
Status: Closed Package: opcache
PHP Version: 7.2.11 OS: Debian GNU/Linux 9
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phpbug at kacena dot name
New email:
PHP Version: OS:

 

 [2018-10-25 13:11 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-25 14:24 UTC] nikic@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2018-10-25 14:45 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f1ceec5533c5ee0e1de7867d629f336f1353f4b3
Log: Fixed bug #77058
 [2018-10-25 14:45 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 05 20:01:30 2024 UTC