3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ObjectMap { private $keyMap = []; private $valMap = []; private $keyVal = []; private $valKey = []; private function hash($object) { return spl_object_hash($object); } public function set($key, $val) { $this->keyMap[$keyHash = $this->hash($key)] = $key; $this->valMap[$valHash = $this->hash($val)] = $val; $this->keyVal[$keyHash] = $valHash; $this->valKey[$valHash] = $keyHash; } public function get($key) { if (isset($this->keyVal[$keyHash = $this->hash($key)], $this->valMap[$this->keyVal[$keyHash]])) { return $this->valMap[$this->keyVal[$keyHash]]; } return null; } public function getKey($val) { if (isset($this->valKey[$valHash = $this->hash($val)], $this->keyMap[$this->valKey[$valHash]])) { return $this->keyMap[$this->valKey[$valHash]]; } } } $objectMap = new ObjectMap(); $objectMap->set($a = (object) ['value' => 'a'], $b = (object) ['value' => 'b']); $objectMap->set($c = (object) ['value' => 'c'], $d = (object) ['value' => 'd']); $objectMap->set($e = (object) ['value' => 'e'], $f = (object) ['value' => 'f']); var_dump($objectMap->get($a)); var_dump($objectMap->get($c)); var_dump($objectMap->getKey($f));
Output for rfc.property-hooks, git.master, git.master_jit
object(stdClass)#3 (1) { ["value"]=> string(1) "b" } object(stdClass)#5 (1) { ["value"]=> string(1) "d" } object(stdClass)#6 (1) { ["value"]=> string(1) "e" }

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:
79.66 ms | 2315 KiB | 4 Q