1--TEST-- 2The Closure object of a generator is freed when the generator is freed. 3--FILE-- 4<?php 5 6$genFactory = function() { 7 yield 1; 8 yield 2; 9 yield 3; 10}; 11 12$r = WeakReference::create($genFactory); 13$generator = $genFactory(); 14unset($genFactory); 15 16var_dump($r->get()); 17 18foreach ($generator as $value) var_dump($value); 19 20var_dump($r->get()); 21 22unset($generator); 23 24var_dump($r->get()); 25 26?> 27--EXPECTF-- 28object(Closure)#%d (3) { 29 ["name"]=> 30 string(%d) "{closure:%s:%d}" 31 ["file"]=> 32 string(%d) "%s" 33 ["line"]=> 34 int(%d) 35} 36int(1) 37int(2) 38int(3) 39object(Closure)#%d (3) { 40 ["name"]=> 41 string(%d) "{closure:%s:%d}" 42 ["file"]=> 43 string(%d) "%s" 44 ["line"]=> 45 int(%d) 46} 47NULL 48