刚解决了一个 BRN 的诡异 bug: 玩家控制系统里会重复出现同一个玩家的数据,占用的键却是其他人的. 经过一番排查定位到了一段 foreach 语句附近. 抽象后的代码如下:
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  | 
						<?php $b = array(); function process(&$value) { 	$GLOBALS['b'][] = &$value; } $a = array(0, 1, 2, 3, 4); foreach($a as $key => $value){ 	process($value); } var_dump($b); ?>  | 
					
输出:
| 
					 1 2 3 4 5 6 7  | 
						array(5) {  [0]=> &int(4)  [1]=> &int(4)  [2]=> &int(4)  [3]=> &int(4)  [4]=> &int(4) }  | 
					


近期评论