3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Dictionary { private $kMap; private $vMap; private $kvHashMap; private $vkHashMap; public function add($k, $v) { $kHash = spl_object_hash($k); $vHash = spl_object_hash($v); $this->kMap[$kHash] = $k; $this->vMap[$vHash] = $v; $this->kvHashMap[$kHash] = $vHash; $this->vkHashMap[$vHash] = $kHash; } public function get($k) { $kHash = spl_object_hash($k); if (isset($this->kvHashMap[$kHash])) { $vHash = $this->kvHashMap[$kHash]; if (isset($this->vMap[$vHash])) { return $this->vMap[$vHash]; } } return null; } public function getKey($v) { $vHash = spl_object_hash($v); if (isset($this->vkHashMap[$vHash])) { $kHash = $this->vkHashMap[$vHash]; if (isset($this->kMap[$kHash])) { return $this->kMap[$kHash]; } } return null; } } $dictionary = new Dictionary(); $k = (object) ['i' => 'am a key']; $v = (object) ['i' => 'am a value']; $dictionary->add($k, $v); var_dump($dictionary->get($k)); var_dump($dictionary->getKey($v));
Output for git.master, git.master_jit, rfc.property-hooks
object(stdClass)#3 (1) { ["i"]=> string(10) "am a value" } object(stdClass)#2 (1) { ["i"]=> string(8) "am a key" }

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:
43.21 ms | 401 KiB | 8 Q