[php-src] Issue #11917: primitives seem to be passed via reference instead of by value under some conditions when opcache is enabled

From: Date: Tue, 08 Aug 2023 23:13:50 +0000
Subject: [php-src] Issue #11917: primitives seem to be passed via reference instead of by value under some conditions when opcache is enabled
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245134@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11917 Author: terrafrost ### Description The following code: ```php $a = [2147483647,2147483647,2147483647,3,0,0,32,2147483584,127]; echo crc32(json_encode(bitwise_small_split($a))) . "\n"; echo crc32(json_encode(bitwise_small_split($a))) . "\n"; echo crc32(json_encode(bitwise_small_split($a))) . "\n"; echo crc32(json_encode(bitwise_small_split($a))) . "\n"; function bitwise_small_split($val) { $split = 8; $vals = []; $mask = (1 << $split) - 1; $i = $overflow = 0; $len = count($val); $val[] = 0; $remaining = 31; while ($i != $len) { $digit = $val[$i] & $mask; $val[$i] >>= $split; if (!$overflow) { $remaining -= $split; $overflow = $split <= $remaining ? 0 : $split - $remaining; if (!$remaining) { $i++; $remaining = 31; $overflow = 0; } } elseif (++$i != $len) { $tempmask = (1 << $overflow) - 1; $digit |= ($val[$i] & $tempmask) << $remaining; $val[$i] >>= $overflow; $remaining = 31 - $overflow; $overflow = $split <= $remaining ? 0 : $split - $remaining; } $vals[] = $digit; } while ($vals[count($vals) - 1] == 0) { unset($vals[count($vals) - 1]); } return array_reverse($vals); } ``` With this php.ini: ``` zend_extension = C:/pphp/ext/php_opcache.dll [opcache] opcache.enable=1 opcache.enable_cli=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=16 opcache.max_accelerated_files=100000 opcache.jit_buffer_size=128M opcache.jit=tracing ``` Resulted in this output: ``` 48207660 48207660 1497456976 1497456976 ``` But I expected this output instead: ``` 48207660 48207660 48207660 48207660 ``` I get the expected output when I set opcache.enable to 0 in the php.ini but not when it's set to 1. Note that sometimes I need to run the PHP file twice before the issue starts appearing. ### PHP Version PHP 8.2.9 ### Operating System Windows 11

« previous php.bugs (#245134) next »