3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DIContainer1 implements ArrayAccess { private array $registered; private array $created; public function offsetSet(mixed $offset, mixed $value): void { if (is_null($offset)) { throw new DIContainerException('Обязательно должен быть указан ключ.'); } if (array_key_exists($offset, $this->registered)) { throw new DIContainerException('Нельзя использовать один и тот же ключ для нескольких элементов.'); } $this->registered[$offset] = $value; } public function offsetExists(mixed $offset): bool { return isset($this->registered[$offset]); } public function offsetUnset(mixed $offset): void { unset($this->registered[$offset]); unset($this->created[$offset]); } public function offsetGet(mixed $offset): mixed { if (array_key_exists($offset, $this->created)) { return $this->created[$offset]; } elseif (array_key_exists($offset, $this->registered)) { $object = $this->registered[$offset]($this); $this->created[$offset] = $object; return $object; } else { throw new DIContainerException('Элемент с таким ключом не зарегистрирован.'); } } }
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
93.56 ms | 407 KiB | 5 Q