3v4l.org

run code in 300+ PHP versions simultaneously
<?php class IdObjectStorage extends SplObjectStorage { public function getHash($object) { return (string) $object->id; } } $storage = new IdObjectStorage(); $array = []; $object1 = new stdClass(); $object1->id = 1; $object1->value = 'Object #1'; $storage->attach($object1); $array[$object1->id] = $object1; foreach($storage as $x) var_dump($x->value); // Object #1 foreach($array as $x) var_dump($x->value); // Object #1 $object2 = new stdClass(); $object2->id = 1; $object2->value = 'Object #2'; $array[$object2->id] = $object2; $storage->attach($object2); foreach($storage as $x) var_dump($x->value); // Object #1 foreach($array as $x) var_dump($x->value); // Object #2
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of IdObjectStorage::getHash($object) should either be compatible with SplObjectStorage::getHash(object $object): string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/i1v7q on line 4 string(9) "Object #1" string(9) "Object #1" string(9) "Object #1" string(9) "Object #2"

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:
53.07 ms | 402 KiB | 8 Q