Bug #77310 [Opn]: Variable values incorrect when Opcache enabled
| From: | nikic@php.net | Date: | Mon, 07 Jan 2019 08:21:14 +0000 |
| Subject: | Bug #77310 [Opn]: Variable values incorrect when Opcache enabled | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218823@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77310&edit=1
ID: 77310
Updated by: nikic@php.net
Reported by: taylor at laravel dot com
Summary: Variable values incorrect when Opcache enabled
Status: Open
Type: Bug
Package: opcache
Operating System: Multiple
PHP Version: 7.3.0
Block user comment: N
Private report: N
New Comment:
@syntax53: That looks like bug #77257 to me, based on the involvement of switch. I can't
reproduce this issue on current 7.3 tip.
@titansoftime: Can't reproduce that on on current 7.3 tip either, though not sure which bug
would have fixed that one.
Previous Comments:
------------------------------------------------------------------------
[2019-01-07 03:03:22] titansoftime at gmail dot com
I to have experienced this bug. Happens every time after first page load. Totally broke my games
stat system.
Code works ok on first attempt after ftp upload, get 0's every time afterwards.
OpCache for php 7.2.13 has no issue, only php 7.3 has the issue. Disabling opcache solves the
problem. Using Ubuntu 18.
Test code:
class itest{
function make_user_stats():array{
$stats = array(
'strength' => 0,
'stamina' => 0,
'intellect' => 0,
'spirit' => 0,
'agility' => 0,
'armor' => 0,
'resist' => 0
);
$item_stats = array(
'stam_x' => 0,
'str_x' => 0,
'int_x' => 0,
'agi_x' => 0,
'spirit_x' => 0,
'armor_inc' => 0,
'resist_inc' => 0
);
$count = count($rows = array(
array(
'intellect' => 100,
'stamina' => 200,
'strength' => 30,
'spirit' => 300,
'agility' => 500,
'resist' => 5,
'armor' => 5,
),
array(
'intellect' => 200,
'stamina' => 300,
'strength' => 330,
'spirit' => 40,
'agility' => 100,
'resist' => 10,
'armor' => 5,
),
array(
'intellect' => 250,
'stamina' => 120,
'strength' => 330,
'spirit' => 30,
'agility' => 5,
'resist' => 10,
'armor' => 10,
),
));
foreach( $rows as $row ){
$item_stats['stam_x'] += $row['stamina'];
$item_stats['str_x'] += $row['strength'];
$item_stats['int_x'] += $row['intellect'];
$item_stats['agi_x'] += $row['agility'];
$item_stats['spirit_x'] += $row['spirit'];
$item_stats['armor_inc'] += $row['armor'];
$item_stats['resist_inc'] += $row['resist'];
//var_dump($item_stats);
}
$stats['stamina'] += ceil( ($stats['stamina'] *
($item_stats['stam_x']/100)) ) + $item_stats['stam_x'];
$stats['intellect'] += ceil( ($stats['intellect'] *
($item_stats['int_x']/100)) ) + $item_stats['int_x'];
$stats['strength'] += ceil( ($stats['strength'] *
($item_stats['str_x']/100)) ) + $item_stats['str_x'];
$stats['agility'] += ceil( ($stats['agility'] *
($item_stats['agi_x']/100)) ) + $item_stats['agi_x'];
$stats['spirit'] += ceil( ($stats['spirit'] *
($item_stats['spirit_x']/100)) ) + $item_stats['spirit_x'];
$stats['armor'] += $item_stats['armor_inc'];
$stats['resist'] += $item_stats['resist_inc'];
return $stats;
}
}
$itest = new itest;
$stats = $itest->make_user_stats();
var_dump($stats);
------------------------------------------------------------------------
[2019-01-07 02:44:03] syntax53 at gmail dot com
I believe a problem I just ran across is related / same as this. This is with PHP 7.3 nts x64 (I
tried 7.3.1RC1 and same problem) on Windows 2016.
---[begin]
<?php
$data[0][0] = 'zero';
$data[0][1] = 0;
$data[1][0] = 'one';
$data[1][1] = 1;
$data[2][0] = 'two';
$data[2][1] = 2;
function breakit($op,$table,$data_arr,$qual="") {
switch ($op) {
case "go":
$foo[0] = "";
$foo[1] = "";
$bar[0] = "";
$bar[1] = "";
for($i = 0; $i < count($data_arr); $i++)
{
if ($foo[0] != "") { $foo[0]=$foo[0].","; $foo[1]=$foo[1].","; }
if ($bar[0] != "") { $bar[0]=$bar[0].","; $bar[1]=$bar[1].","; }
$field = "
".$data_arr[$i][0]."";
$val = "'".$data_arr[$i][1]."'";
$foo[0] .= $field;
$foo[1] .= $val;
$bar[0] = $bar[0].$field;
$bar[1] = $bar[1].$val;
}
echo "foo[0]: ".$foo[0]."<br>";
echo "foo[1]: ".$foo[1]."<br>";
echo "bar[0]: ".$bar[0]."<br>";
echo "bar[1]: ".$bar[1]."<br>";
break;
}
}
breakit('go','table',$data);
?>
---[end]
output--
foo[0]:
foo[1]:
bar[0]: zero,one,two
bar[1]: '0','1','2' (edited)
... with opcache enabled the string concatenation of "var .= value" produces an empty
string. But using "var = var . value" works fine. Disable opcache and output of foo and
bar is identical.
------------------------------------------------------------------------
[2018-12-20 15:13:02] cmb@php.net
Can you please check with the fix for that bug[1] applied? Instead
of applying the fix yourself, you can also test with PHP
7.3.1RC1[2] (announcement including hashes and signatures will
follow shortly).
Anyhow, this issue might also be related to bug #76937.
[1] <http://git.php.net/?p=php-src.git;a=commit;h=93aabf1533bd3af673bb59cf283e6599ced3ab9a>
[2] <http://downloads.php.net/~cmb/>
------------------------------------------------------------------------
[2018-12-20 11:57:17] taylor at laravel dot com
Might be duplicate / similar issue as: https://bugs.php.net/bug.php?id=77275
------------------------------------------------------------------------
[2018-12-17 16:59:26] nikic@php.net
Off-topic comment by spam2 at rhsoft dot net deleted.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=77310
--
Edit this bug report at https://bugs.php.net/bug.php?id=77310&edit=1