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.4.1 - 8.4.18, 8.5.0 - 8.5.3
Parse error: syntax error, unexpected token "{" in /in/KkaBl on line 62
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30
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:
100.76 ms | 1957 KiB | 4 Q