1--TEST-- 2WeakMap iteration 3--FILE-- 4<?php 5 6$map = new WeakMap; 7 8echo "\nEmpty loop:\n"; 9foreach ($map as $key => $value) { 10 var_dump($key, $value); 11} 12 13echo "\nSimple loop:\n"; 14$obj0 = new stdClass; 15$obj1 = new stdClass; 16$obj2 = new stdClass; 17$map[$obj0] = 0; 18$map[$obj1] = 1; 19$map[$obj2] = 2; 20foreach ($map as $key => $value) { 21 var_dump($key, $value); 22} 23 24echo "\nObject removed during loop:\n"; 25foreach ($map as $key => $value) { 26 if (isset($obj1) && $key === $obj1) unset($obj1); 27 var_dump($key, $value); 28} 29 30echo "\nBy reference iteration:\n"; 31foreach ($map as $key => &$value) { 32 $value++; 33} 34var_dump($map); 35 36?> 37--EXPECT-- 38Empty loop: 39 40Simple loop: 41object(stdClass)#2 (0) { 42} 43int(0) 44object(stdClass)#3 (0) { 45} 46int(1) 47object(stdClass)#4 (0) { 48} 49int(2) 50 51Object removed during loop: 52object(stdClass)#2 (0) { 53} 54int(0) 55object(stdClass)#3 (0) { 56} 57int(1) 58object(stdClass)#4 (0) { 59} 60int(2) 61 62By reference iteration: 63object(WeakMap)#1 (2) { 64 [0]=> 65 array(2) { 66 ["key"]=> 67 object(stdClass)#2 (0) { 68 } 69 ["value"]=> 70 &int(1) 71 } 72 [1]=> 73 array(2) { 74 ["key"]=> 75 object(stdClass)#4 (0) { 76 } 77 ["value"]=> 78 &int(3) 79 } 80} 81