Bug #75938 [Ver->Csd]: Modulus value not stored in variable
| From: | nikic@php.net | Date: | Fri, 09 Feb 2018 14:12:17 +0000 |
| Subject: | Bug #75938 [Ver->Csd]: Modulus value not stored in variable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213897@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75938&edit=1
ID: 75938
Updated by: nikic@php.net
Reported by: php at darkain dot com
Summary: Modulus value not stored in variable
-Status: Verified
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Debian 9.3
PHP Version: 7.2.2
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7aac61ce762b2658263f605dd4d910f6914b7129
Log: Fixed bug #75938
Previous Comments:
------------------------------------------------------------------------
[2018-02-08 20:43:45] nikic@php.net
Indeed, this is a bug in value range inference. The code handling modulus operations looks pretty
bogus to me.
------------------------------------------------------------------------
[2018-02-08 19:55:56] php at darkain dot com
Description:
------------
Using this combination of code, $mod remains INT 0 instead of being set to INT 1. The wrapped
var_dump however shows the proper value still.
I've tested this code on my Debian box with:
PHP 7.2.2-1+0~20180205160742.18+stretch~1.gbpb78b58
On my test machine, php cli works properly. However, php fpm shows this particular error.
My guess is that this is somewhere in the optimizer. Changing or removing any line prior to the
first var_dump will result in proper output. Changing the values from variables to constant will
result in proper output. Changing the modulus operator to any other operator will result in a proper
output.
Test script:
---------------
function borken($columns) {
$columns = (int) $columns;
if ($columns < 1) return 0;
$count = count([1,2,3,4,5]);
var_dump($mod = ($count % $columns));
var_dump($mod);
}
borken(2);
Expected result:
----------------
int(1)
int(1)
Actual result:
--------------
int(1)
int(0)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75938&edit=1