php.net |  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
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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-08 20:43 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2018-02-08 20:43 UTC] nikic@php.net
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] nikic@php.net
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
 [2018-02-09 14:12 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 28 09:01:28 2024 UTC