3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class IOException extends Exception { protected $file; public function __construct($file, $message) { parent::__construct($message); $this->file = $file; } public function getPath() { return $this->file; } } class File { protected $path; protected $handle; 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, "could not open the file"); } } } $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 5.3.0 - 7.1.0
Exception occured opening /no/file object(IOException)#2 (7) { ["file":protected]=> string(8) "/no/file" ["message":protected]=> string(23) "could not open the file" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["line":protected]=> int(26) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(9) "/in/atUmE" ["line"]=> int(34) ["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.2.17
Exception occured opening /no/file object(IOException)#2 (6) { ["file:protected"]=> string(8) "/no/file" ["message:protected"]=> string(23) "could not open the file" ["string:private"]=> string(0) "" ["code:protected"]=> int(0) ["line:protected"]=> int(26) ["trace:private"]=> array(1) { [0]=> array(6) { ["file"]=> string(9) "/in/atUmE" ["line"]=> int(34) ["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 (6) { ["file:protected"]=> string(8) "/no/file" ["message:protected"]=> string(23) "could not open the file" ["string:private"]=> string(0) "" ["code:protected"]=> int(0) ["line:protected"]=> int(26) ["trace:private"]=> array(2) { [0]=> array(5) { ["file"]=> string(9) "/in/atUmE" ["line"]=> int(26) ["function"]=> string(4) "open" ["class"]=> string(4) "File" ["type"]=> string(2) "::" } [1]=> array(6) { ["file"]=> string(9) "/in/atUmE" ["line"]=> int(34) ["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/atUmE on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/atUmE 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/atUmE on line 3
Process exited with code 255.