3v4l.org

run code in 300+ PHP versions simultaneously
<?php // класс хранилища данных, реализующий интерфейс Iterator class Registry implements Iterator { // массив, в котором хранятся настройки private $options = []; // возвращает текущий элемент public function current() { return current($this -> options); } // возвращает ключ текущего элемента public function key() { return key($this -> options); } // передвигаемся вперед на один элемент public function next() { next($this -> options); } // возвращает указатель на начало массива // фактически мы начинаем считать заново с нуля public function rewind() { reset($this -> options); } // проверяет, достигли ли мы конца массива public function valid() { return current($this -> options) !== false; } // метод для добавления настройки в хранилище public function set($option, $value) { $this -> options[$option] = $value; return $this; } // метод для получения настройки из хранилища public function get($option) { return $this -> options[$option]; } } // создали объект $reg = new Registry(); // добавили настройки $reg -> set("DS",DIRECTORY_SEPARATOR) -> set("APP_HOME", '.') -> set("AUTO_RELOAD",true); // и прошлись по настройкам. // обратите внимание - никаких массивов, только объект $reg foreach ( $reg as $option => $value ) { echo $option, " = ", $value, PHP_EOL; }
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.4, 8.3.6 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
Deprecated: Return type of Registry::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fMaTi on line 10 Deprecated: Return type of Registry::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fMaTi on line 23 Deprecated: Return type of Registry::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fMaTi on line 16 Deprecated: Return type of Registry::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fMaTi on line 36 Deprecated: Return type of Registry::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fMaTi on line 30 DS = / APP_HOME = . AUTO_RELOAD = 1
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.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Return type of Registry::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fMaTi on line 10 Deprecated: Return type of Registry::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fMaTi on line 23 Deprecated: Return type of Registry::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fMaTi on line 16 Deprecated: Return type of Registry::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fMaTi on line 36 Deprecated: Return type of Registry::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fMaTi on line 30 DS = / APP_HOME = . AUTO_RELOAD = 1
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
DS = / APP_HOME = . AUTO_RELOAD = 1

preferences:
208.35 ms | 413 KiB | 5 Q