3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Weakmaps accepts objects and arrays as keys $source = new Weakmap(); $key = (object) ['a' => 2]; $source[$key] = 1; // Yield may emit objects and arrays as keys $source = function () { yield (object) ['a' => 3] => 1; }; // This is just for illustration $source = $source(); // An iterator may return objects and arrays as keys(mixed, in fact) class myIterator implements Iterator { private int $position = 0; public function rewind(): void { $this->position = 0; } public function current(): mixed { return 1; } public function key(): mixed { return (object) ['a' => 4]; } public function next(): void { ++$this->position; } public function valid(): bool { return $this->position == 0; } } $source = new myIterator(); foreach($source as $key => $value) { print get_class($key); // Stdclass print $value; // 1 }
Output for git.master, git.master_jit
stdClass1

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:
41.33 ms | 774 KiB | 4 Q