|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[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
[2018-10-25 14:45 UTC] nikic@php.net
-Status: Assigned
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 05:00:02 2025 UTC |
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