3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bathroom { const LEFT = [2, 5, 8, 3, 6, 9]; const UP = [4, 5, 6, 7, 8, 9]; const RIGHT = [1, 2, 4, 5, 7, 8]; const DOWN = [1, 2, 3, 4, 5, 6]; private $number = 5; private $code; public function left() { if (in_array($this->number, self::LEFT)) { $this->number -= 1; } } public function up() { if (in_array($this->number, self::UP)) { $this->number -= 3; } } public function right() { if (in_array($this->number, self::RIGHT)) { $this->number += 1; } } public function down() { if (in_array($this->number, self::DOWN)) { $this->number += 3; } } public function getCode() { return $this->code; } public function updateCode() { $this->code .= $this->number; } } $input = 'ULL RRDDD LURDL UUUUD'; $inputs = (explode("\n", $input)); $bathroom = new Bathroom; foreach ($inputs as $input) { $len = strlen($input); for ($i = 0; $i < $len; $i++) { switch ($input{$i}) { case 'U': $bathroom->up(); break; case 'L': $bathroom->left(); break; case 'R': $bathroom->right(); break; case 'D': $bathroom->down(); break; } } $bathroom->updateCode(); } echo $bathroom->getCode();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Array and string offset access syntax with curly braces is no longer supported in /in/KkaBl on line 62
Process exited with code 255.
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 Fatal error: Array and string offset access syntax with curly braces is no longer supported in /in/KkaBl on line 62
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/KkaBl on line 62 1985
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
1985

preferences:
206.11 ms | 402 KiB | 291 Q