3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Path { public $currentPath; private $array; function __construct( $path ) { $this->currentPath = $path; $this->array = array_slice( explode( "/", $path ), 1 ); } public function cd( $newPath ) { if ( $newPath == "" || $newPath == "." ) { return $this; } $change = explode( "/", $newPath ); foreach ( $change as $value ) { if ( $value == ".." ) { if ( count( $this->array ) > 0 ) { array_pop($this->array); } } elseif ( $value !== "" ) { array_push( $this->array, $value ); } } if ( count( $this->array ) > 0 ) { $this->currentPath = "/" + implode( "/", $this->array ); } else { $this->currentPath = "/"; } return $this; } } $path = new Path('/a/b/c/d'); echo $path->cd('../../x')->currentPath;
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: Unsupported operand types: string + string in /in/YduXP:28 Stack trace: #0 /in/YduXP(37): Path->cd('../../x') #1 {main} thrown in /in/YduXP on line 28
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.75 ms | 401 KiB | 8 Q