3v4l.org

run code in 300+ PHP versions simultaneously
<?php class IOException extends Exception { protected $path; protected $mode; public function __construct($path, $mode, $message) { parent::__construct($message); $this->path = $path; $this->mode = $mode; } public function getPath() { return $this->path; } } class File { protected $path; protected $handle; protected $mode; public function __construct($path) { $this->path = $path; } public function open($mode) { $this->handle = @fopen($this->path, $mode); if (!$this->handle) { throw new IOException( $this->path, $mode, "could not open the file"); } $this->mode = $mode; } } $file = new File("/no/file"); try { $file->open("r"); } catch (IOException $io) { printf( "Exception occured opening %s\n", $io->getPath()); var_dump($io); } ?>
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Exception occured opening /no/file object(IOException)#2 (9) { ["message":protected]=> string(23) "could not open the file" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/JDHTi" ["line":protected]=> int(29) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(9) "/in/JDHTi" ["line"]=> int(39) ["function"]=> string(4) "open" ["class"]=> string(4) "File" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(1) "r" } } } ["previous":"Exception":private]=> NULL ["path":protected]=> string(8) "/no/file" ["mode":protected]=> string(1) "r" }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 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, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Exception occured opening /no/file object(IOException)#2 (9) { ["path":protected]=> string(8) "/no/file" ["mode":protected]=> string(1) "r" ["message":protected]=> string(23) "could not open the file" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/JDHTi" ["line":protected]=> int(29) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(9) "/in/JDHTi" ["line"]=> int(39) ["function"]=> string(4) "open" ["class"]=> string(4) "File" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(1) "r" } } } ["previous":"Exception":private]=> NULL }
Output for 5.0.0 - 5.0.2, 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Exception occured opening /no/file object(IOException)#2 (8) { ["path:protected"]=> string(8) "/no/file" ["mode:protected"]=> string(1) "r" ["message:protected"]=> string(23) "could not open the file" ["string:private"]=> string(0) "" ["code:protected"]=> int(0) ["file:protected"]=> string(9) "/in/JDHTi" ["line:protected"]=> int(29) ["trace:private"]=> array(1) { [0]=> array(6) { ["file"]=> string(9) "/in/JDHTi" ["line"]=> int(39) ["function"]=> string(4) "open" ["class"]=> string(4) "File" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(1) "r" } } } }
Output for 5.0.3 - 5.0.4
Exception occured opening /no/file object(IOException)#2 (8) { ["path:protected"]=> string(8) "/no/file" ["mode:protected"]=> string(1) "r" ["message:protected"]=> string(23) "could not open the file" ["string:private"]=> string(0) "" ["code:protected"]=> int(0) ["file:protected"]=> string(9) "/in/JDHTi" ["line:protected"]=> int(29) ["trace:private"]=> array(2) { [0]=> array(5) { ["file"]=> string(9) "/in/JDHTi" ["line"]=> int(29) ["function"]=> string(4) "open" ["class"]=> string(4) "File" ["type"]=> string(2) "::" } [1]=> array(6) { ["file"]=> string(9) "/in/JDHTi" ["line"]=> int(39) ["function"]=> string(4) "open" ["class"]=> string(4) "File" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(1) "r" } } } }
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/JDHTi on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/JDHTi on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/JDHTi on line 3
Process exited with code 255.

preferences:
267.88 ms | 401 KiB | 456 Q