1--TEST-- 2Lazy objects: GC 003 3--FILE-- 4<?php 5 6class Canary { 7 public $value; 8 public function __destruct() { 9 var_dump(__FUNCTION__); 10 } 11} 12 13class C { 14} 15 16function ghost() { 17 printf("# Ghost:\n"); 18 19 $canary = new Canary(); 20 21 $obj = (new ReflectionClass(C::class))->newInstanceWithoutConstructor(); 22 (new ReflectionClass($obj))->resetAsLazyGhost($obj, function () use ($canary) { 23 }); 24 25 $canary->value = $obj; 26 $obj = null; 27 $canary = null; 28 29 gc_collect_cycles(); 30} 31 32function proxy() { 33 printf("# Proxy:\n"); 34 35 $canary = new Canary(); 36 37 $obj = (new ReflectionClass(C::class))->newInstanceWithoutConstructor(); 38 (new ReflectionClass($obj))->resetAsLazyProxy($obj, function () use ($canary) { 39 return new C(); 40 }); 41 42 $canary->value = $obj; 43 $obj = null; 44 $canary = null; 45 46 gc_collect_cycles(); 47} 48 49ghost(); 50proxy(); 51 52?> 53==DONE== 54--EXPECT-- 55# Ghost: 56string(10) "__destruct" 57# Proxy: 58string(10) "__destruct" 59==DONE== 60