|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75938 Modulus value not stored in variable
Submitted: 2018-02-08 19:55 UTC Modified: 2018-02-08 20:43 UTC
From: php at darkain dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.2.2 OS: Debian 9.3
Private report: No CVE-ID: None
 [2018-02-08 19:55 UTC] php at darkain dot com
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));


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-08 20:43 UTC]
-Status: Open +Status: Verified
 [2018-02-08 20:43 UTC]
Indeed, this is a bug in value range inference. The code handling modulus operations looks pretty bogus to me.
 [2018-02-09 14:12 UTC]
Automatic comment on behalf of
Log: Fixed bug #75938
 [2018-02-09 14:12 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC