Bug #75938 [Opn->Ver]: Modulus value not stored in variable

From: Date: Thu, 08 Feb 2018 20:43:46 +0000
Subject: Bug #75938 [Opn->Ver]: Modulus value not stored in variable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213875@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: Open +Status: Verified 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: Indeed, this is a bug in value range inference. The code handling modulus operations looks pretty bogus to me. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#213875) next »