3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Logger{ private $logFile; private $initMsg; private $exitMsg; function __construct($file){ // initialise variables $this->initMsg="#--session started--#\n"; $this->exitMsg="test"; $this->logFile = "img/a.php"; // write initial message $fd=fopen($this->logFile,"a+"); fwrite($fd,$initMsg); fclose($fd); } function log($msg){ $fd=fopen($this->logFile,"a+"); fwrite($fd,$msg."\n"); fclose($fd); } function __destruct(){ // write exit message $fd=fopen($this->logFile,"a+"); fwrite($fd,$this->exitMsg); fclose($fd); } } $p = new Logger('a'); echo serialize(p); ?>
based on RKRLH
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Warning: fopen(img/a.php): failed to open stream: No such file or directory in /in/tInPc on line 15 Notice: Undefined variable: initMsg in /in/tInPc on line 16 Warning: fwrite() expects parameter 1 to be resource, boolean given in /in/tInPc on line 16 Warning: fclose() expects parameter 1 to be resource, boolean given in /in/tInPc on line 17 Notice: Use of undefined constant p - assumed 'p' in /in/tInPc on line 35 s:1:"p"; Warning: fopen(img/a.php): failed to open stream: No such file or directory in /in/tInPc on line 28 Warning: fwrite() expects parameter 1 to be resource, boolean given in /in/tInPc on line 29 Warning: fclose() expects parameter 1 to be resource, boolean given in /in/tInPc on line 30
Output for hhvm-3.10.0 - 3.12.0
Warning: No such file or directory in /in/tInPc on line 15 Notice: Undefined variable: initMsg in /in/tInPc on line 16 Warning: fwrite() expects parameter 1 to be resource, boolean given in /in/tInPc on line 16 Warning: fclose() expects parameter 1 to be resource, boolean given in /in/tInPc on line 17 Notice: Use of undefined constant p - assumed 'p' in /in/tInPc on line 35 s:1:"p"; Warning: No such file or directory in /in/tInPc on line 28 Warning: fwrite() expects parameter 1 to be resource, boolean given in /in/tInPc on line 29 Warning: fclose() expects parameter 1 to be resource, boolean given in /in/tInPc on line 30
Output for 5.1.0 - 5.2.17
Warning: fopen(img/a.php): failed to open stream: No such file or directory in /in/tInPc on line 15 Notice: Undefined variable: initMsg in /in/tInPc on line 16 Warning: fclose(): supplied argument is not a valid stream resource in /in/tInPc on line 17 Notice: Use of undefined constant p - assumed 'p' in /in/tInPc on line 35 s:1:"p"; Warning: fopen(img/a.php): failed to open stream: No such file or directory in /in/tInPc on line 28 Warning: fwrite(): supplied argument is not a valid stream resource in /in/tInPc on line 29 Warning: fclose(): supplied argument is not a valid stream resource in /in/tInPc on line 30
Output for 5.0.4 - 5.0.5
Warning: fopen(img/a.php): failed to open stream: No such file or directory in /in/tInPc on line 15 Notice: Undefined variable: initMsg in /in/tInPc on line 16 Warning: fwrite(): supplied argument is not a valid stream resource in /in/tInPc on line 16 Warning: fclose(): supplied argument is not a valid stream resource in /in/tInPc on line 17 Notice: Use of undefined constant p - assumed 'p' in /in/tInPc on line 35 s:1:"p"; Warning: fopen(img/a.php): failed to open stream: No such file or directory in /in/tInPc on line 28 Warning: fwrite(): supplied argument is not a valid stream resource in /in/tInPc on line 29 Warning: fclose(): supplied argument is not a valid stream resource in /in/tInPc on line 30
Output for 5.0.0 - 5.0.3
Warning: fopen(img/a.php): failed to open stream: No such file or directory in /in/tInPc on line 15 Notice: Undefined variable: initMsg in /in/tInPc on line 16 Warning: fwrite(): supplied argument is not a valid stream resource in /in/tInPc on line 16 Warning: fclose(): supplied argument is not a valid stream resource in /in/tInPc on line 17 Notice: Use of undefined constant p - assumed 'p' in /in/tInPc on line 35 s:1:"p"; Warning: fopen(img/a.php): failed to open stream: No such file or directory in /in/tInPc on line 28 Warning: fwrite(): supplied argument is not a valid stream resource in /in/tInPc on line 29 Warning: fclose(): supplied argument is not a valid stream resource in /in/tInPc on line 30
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/tInPc on line 4
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/tInPc on line 4
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/tInPc on line 4
Process exited with code 255.