3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Uid implements \ArrayAccess { protected $uid; public function __construct($uid) { $this->uid = $uid; } public function __toString() { return $this->uid; } public function offsetExists($offset) { return $offset === 0; } public function offsetGet($offset) { if ($offset === 0 || $offset == 'uid') { return $this->uid; } } public function offsetSet($offset, $value) {} public function offsetUnset($offset) {} } $data = new stdClass(); $data->uid = '1234'; print $data->uid; print "\n"; print $data->uid[0]; print "\n"; $data = array(); $data['uid'] = '1234'; print $data['uid']; print "\n"; print $data['uid'][0]; print "\nNew Uid Class\n"; $data['uid'] = new Uid('1234'); print $data['uid']; print "\n"; print $data['uid'][0]; print "\n"; print $data['uid'][1];
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Uid::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VLaJ0 on line 15 Deprecated: Return type of Uid::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VLaJ0 on line 19 Deprecated: Return type of Uid::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VLaJ0 on line 25 Deprecated: Return type of Uid::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VLaJ0 on line 27 1234 1 1234 1 New Uid Class 1234 1234

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:
52.79 ms | 404 KiB | 8 Q