3v4l.org

run code in 300+ PHP versions simultaneously
<?php class WeakMap2 { private array $weakRefs = []; private array $values = []; public function offsetSet($object, $value) : void { $id = spl_object_id($object); $this->weakRefs[$id] = \WeakReference::create($object); $this->values[$id] = $value; } } class WeakAnalysingMapRepro { public array $valueWithOwnerCountByIndex = []; private WeakMap2 $ownerDestructorHandlers; public function __construct() { $this->ownerDestructorHandlers = new WeakMap2(); $this->addKeyOwner(new \DateTime()); } protected function addKeyOwner(object $owner) { $handler = new class($this) { private \WeakReference $weakAnalysingMap; public function __construct(WeakAnalysingMapRepro $analysingMap) { $this->weakAnalysingMap = \WeakReference::create($analysingMap); } public function __destruct() { $analysingMap = $this->weakAnalysingMap->get(); var_dump(array_keys($analysingMap->valueWithOwnerCountByIndex)); \Closure::bind(static function () use ($analysingMap) { var_dump(array_keys($analysingMap->valueWithOwnerCountByIndex)); }, null, WeakAnalysingMapRepro::class)(); } public function addReference($index): void { $analysingMap = $this->weakAnalysingMap->get(); $analysingMap->valueWithOwnerCountByIndex[$index] = true; } }; $this->ownerDestructorHandlers->offsetSet($owner, $handler); $handler->addReference(10); } } $map = new WeakAnalysingMapRepro(); unset($map); echo 'DONE';
Output for git.master_jit, git.master
Warning: Attempt to read property "valueWithOwnerCountByIndex" on null in /in/h7ZER on line 44 Fatal error: Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in /in/h7ZER:44 Stack trace: #0 /in/h7ZER(44): array_keys(NULL) #1 /in/h7ZER(64): class@anonymous->__destruct() #2 {main} thrown in /in/h7ZER on line 44
Process exited with code 255.
Output for rfc.property-hooks
array(1) { [0]=> int(10) } array(1) { [0]=> string(12) "analysingMap" } DONE

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
57.61 ms | 406 KiB | 5 Q