3v4l.org

run code in 500+ PHP versions simultaneously
<?php class WeakAnalysingMapRepro { /** @var workaround https://github.com/php/php-src/issues/13612, remove once PHP 8.3 support is dropped */ private \stdClass $destructedEarly; public array $destroyed = []; public array $ownerDestructorHandlers = []; public function __construct() { $this->destructedEarly = new \stdClass(); $handler = new class($this, $this->destructedEarly) { private \WeakReference $weakAnalysingMap; private \WeakReference $weakAnalysingMapDestructedEarly; public function __construct(WeakAnalysingMapRepro $analysingMap, \stdClass $destructedEarly) { $this->weakAnalysingMap = \WeakReference::create($analysingMap); $this->weakAnalysingMapDestructedEarly = \WeakReference::create($destructedEarly); } public function __destruct() { if ($this->weakAnalysingMapDestructedEarly->get() === null) { return; } var_dump($this->weakAnalysingMap->get()); } }; $this->destroyed[] = 1; $this->ownerDestructorHandlers[] = $handler; } } new WeakAnalysingMapRepro(); echo 'DONE';
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.35, 8.3.0 - 8.3.36, 8.4.1 - 8.4.27, 8.5.0 - 8.5.12
DONE

preferences:
32.87 ms | 1159 KiB | 6 Q