1--TEST-- 2GC 048: Objects with destructor are collected without delay 3--FILE-- 4<?php 5 6class CycleWithoutDestructor 7{ 8 private \stdClass $cycleRef; 9 10 public function __construct() 11 { 12 $this->cycleRef = new \stdClass(); 13 $this->cycleRef->x = $this; 14 } 15} 16 17class CycleWithDestructor extends CycleWithoutDestructor 18{ 19 public function __construct() 20 { 21 parent::__construct(); 22 } 23 24 public function __destruct() 25 { 26 new CycleWithoutDestructor(); 27 } 28} 29 30echo "---\n"; 31 32$cycleWithoutDestructor = new CycleWithoutDestructor(); 33$cycleWithoutDestructorWeak = \WeakReference::create($cycleWithoutDestructor); 34$cycleWithDestructor = new CycleWithDestructor(); 35$cycleWithDestructorWeak = \WeakReference::create($cycleWithDestructor); 36gc_collect_cycles(); 37 38echo "---\n"; 39 40unset($cycleWithoutDestructor); 41var_dump($cycleWithoutDestructorWeak->get() !== null); 42gc_collect_cycles(); 43var_dump($cycleWithoutDestructorWeak->get() !== null); 44 45echo "---\n"; 46 47unset($cycleWithDestructor); 48var_dump($cycleWithDestructorWeak->get() !== null); 49gc_collect_cycles(); 50var_dump($cycleWithDestructorWeak->get() !== null); 51--EXPECT-- 52--- 53--- 54bool(true) 55bool(false) 56--- 57bool(true) 58bool(false) 59