3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Path { public $currentPath; private $array; function __construct($path) { $this->currentPath = $path; $array = explode("/", $path); } public function cd($newPath) { $change = explode("/", $newPath); foreach ($change as $value) { if ($value == "..") { if (count($array) > 0) { array_pop($array); } } else { array_push($array, $value); } } $currentPath = implode("/", $array); } } $path = new Path('/a/b/c/d'); echo $path->cd('../x')->currentPath;
based on oUZGl
Output for 7.2.0
Notice: Undefined variable: array in /in/GLfKA on line 15 Warning: count(): Parameter must be an array or an object that implements Countable in /in/GLfKA on line 15 Warning: array_push() expects parameter 1 to be array, null given in /in/GLfKA on line 19 Warning: implode(): Invalid arguments passed in /in/GLfKA on line 23 Notice: Trying to get property 'currentPath' of non-object in /in/GLfKA on line 28
Output for 5.3.20 - 7.1.10
Notice: Undefined variable: array in /in/GLfKA on line 15 Warning: array_push() expects parameter 1 to be array, null given in /in/GLfKA on line 19 Warning: implode(): Invalid arguments passed in /in/GLfKA on line 23 Notice: Trying to get property of non-object in /in/GLfKA on line 28