3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ namespace epay; use SplFileObject; /** * TODO * -- ACT: complete all method bodies * -- DUE: 17 Apr. 2014 * -- MOD: 15 Apr. 2014 */ /** * Description of Logger * * @author Talaeedeh */ class Logger { /** * Public * Used for exporting log files. Must be unique per Logger. * * @var String complete output filename (eg. "output.log") */ public $FILENAME; /** * Public * Used for exporting log files. Must be followed by * a \ at the end. * * @var String absolute output path (eg. "C:\\Program Files(x86)\\App\\") */ public $PATH; /** * Protected * The level of importance of logs that will be recorded. * Zero means log nothing * * @var LogLevel (int) Level of log importance */ public $LEVEL; /** * String representation of current message in LogLevel::EVERYTHING. * * @var Array(LogLevel,String) Current message */ protected $CMESSAGE; /** * String representation of messages in LogLevel::EVERYTHING that * are not yet recorded or purged. * * @var SplQueue(Array(LogLevel,String)) last messages */ protected $LMESSAGES; /* MARKED4DEL * -- REASON: Added Log level of current message into current message * using TYPEX String : Array(LogLevel,String) * * /** * * Level of importance of current message * * stored in $CMESSAGE * * * * @var LogLevel(int) CMESSAGE's level of importance * *\/ * protected $CLEVEL; */ /** * Write Log * * Writing the log messages stored in $MESSAGES into the file * specified by $PATH . $FILENAME. * * @param SplQueue(Array(LogLevel,String)) $MESSAGES Pending messages to be written. * @return Array(LogLevel,String) NULL if successful, Error message otherwise. */ protected function WriteLog($MESSAGES) { } /** * Purge Messages * * Purging log messages stored in $MESSAGES permenantly. * * -- !WARNING: Make sure you have written all necessary messages into a file * before purging. Purging is irreversible and all contents in * $MESSAGES will be inaccessible afterwards. * * @param SplQueue(Array(LogLevel,String)) $MESSAGES Pending messages to be written. * @return Array(LogLevel,String) NULL if successful, Error message otherwise. */ protected function Purge(&$MESSAGES) { } /** * Export Messages * * Essentialy writes log messages into the specified file using $PATH . $FILENAME * follows by purging all messages inside $MESSAGES. * * -- !WARNING: Exporting is irreversible. * * @param SplQueue(Array(LogLevel,String)) $MESSAGES Pending messages to be written. * @return Array(LogLevel,String) NULL if successful, Error message otherwise. */ public function Export(&$MESSAGES) { } /** * !FIXME: * -- PROBLEM: @author Talaeezadeh * got tired for today; end of work time at 7:30. * -- DUE: 16 Apr. 2014 * -- MOD: 15 Apr. 2014 */ /** * Import Messages * * Purges all messages inside $MESSAGES and imports a chunk of log-file * specified by $PATH . $FILENAM. * * -- !WARNING: Importing is irreversible. * * @param SplQueue(Array(LogLevel,String)) $MESSAGES Pending messages to be written. * @param Int $BEGIN OPTIONAL: First error no. to be imported. Inclusive. * @param Int $END OPTIONAL: Last error no. to be imported. Exclusive. * @return SplQueue(Array(LogLevel,String)) NULL if successful, Error messages otherwise. */ public function Import(SplQueue &$MESSAGES) { /** * @var Array(LogLevel,String) Error. */ $err = NULL; /** * @var Int Number of arguments. */ $num_args = func_num_args() > 3; /** * Checking for errors in arguments. */ if ($num_args > 3) { $err = array (LogLevel::WARNING, "WARNING @" . __FILE__ . " line". __LINE__ .": " . __TRAIT__ . " says: \'Unexpected argument. Escaped!\'"); echo $err[1]; return $err; } elseif ($num_args == 0) { $err = array (LogLevel::WARNING, "WARNING @" . __FILE__ . " line ". __LINE__ .": " . __TRAIT__ . " says: \'No arguments. Escaped!\'"); echo $err[1]; return $err; } /** * Setting Optional Arguments. */ if ($num_args > 1) { $BEGIN = func_get_arg(1); } if ($num_args > 2) { $END = func_get_arg(2); } /** * Setting up file handler and purge the $MESSAGES. */ /** * @var Resource A resource handler to log file to be processed. */ $fileHNDL = new SplFileObject($this->PATH . $this->FILENAME, 'r'); /** * Check if file exists. If not, returns with the error message. */ if ($fileHNDL === \NULL) { $err = array (LogLevel::ERROR, "ERROR @" . __FILE__ . " line ". __LINE__ .": " . __TRAIT__ . " says: \'File not found. Escaped!\'"); echo $err[1]; return $err; }; /** * Purge the $MESSAGES empty. */ $this->Purge($MESSAGES); /** * Reading desired parts of the file. */ /** * FIXME: * -- PROBLEM: If the user specified begining excedes file length. * -- DUE: 16 Apr. 2014 * -- MOD: 15 Apr. 2014 * -- FIN: 13 Apr. 2014 13:47 THR */ /** * Checking if the user specified begining excedes file length. */ $fileHNDL->seek($BEGIN); if ($fileHNDL->eof()) { $err = array (LogLevel::WARNING, "WARNING @" . __FILE__ . " line ". __LINE__ .": " . __TRAIT__ . " says: \'The line $BEGIN does not exist in current content!\'"); echo $err[1]; return $err; } /** * If there is the $END parameter available by user. */ if (isset($END)) { for ($i = $BEGIN; $i < $END; $i++) { $fileHNDL->seek($i); /** * Unexpected end of file reached. */ if ($fileHNDL->eof()) { break; } /** * @var String Temporary storage for the current line of log being processed. */ $tmpLine = $fileHNDL->current(); /** * TODO: * -- ACT: Extract LogLevel and String Messages from $tmpLine. * and remove stubs: $matchedLevel and $matchedMessage. * -- DUE: 16 Apr. 2014 * -- MOD: 15 Apr. 2014 * -- FIN: 16 Apr. 2014 13:25 THR */ /** * Extracting LogLevel and String Messages from $tmpLine. */ /** * @var Array(String) Temporary storage for current log importance level extraction. */ $tmpMatches = array(); /** * Extraction. Macthes $tmpLine to a RegX explaining uppercase substrings. */ preg_match("/[A-Z]+/", $tmpLine, $tmpMatches); /** * @var LogLevel The importance level of current log entry. */ $matchedLevel = constant("epay\LogLevel::$tmpMatches[0]"); /** * @var String The message contained in the current log entry. */ $matchedMessage = str_replace($tmpMatches[0] . '', "" , $tmpLine); $MESSAGES->enqueue(array($matchedLevel,$matchedMessage)); } } /** * If $End parameter is not provided by user, read until the end of file. */ else { $i = $BEGIN; $fileHNDL->seek($i); do { $tmpLine = $fileHNDL->current(); /** * TODO: * -- ACT: Extract LogLevel and String Messages from $tmpLine. * and remove stubs: $matchedLevel and $matchedMessage. * -- DUE: 16 Apr. 2014 * -- MOD: 15 Apr. 2014 * -- FIN: 16 Apr. 2014 13:25 THR */ /** * Extracting LogLevel and String Messages from $tmpLine. */ /** * @var Array(String) Temporary storage for current log importance level extraction. */ $tmpMatches = array(); /** * Extraction. Macthes $tmpLine to a RegX explaining uppercase substrings. */ preg_match("/[A-Z]+/", $tmpLine, $tmpMatches); /** * @var LogLevel The importance level of current log entry. */ $matchedLevel = constant("epay\LogLevel::$tmpMatches[0]"); /** * @var String The message contained in the current log entry. */ $matchedMessage = str_replace($tmpMatches[0] . '', "" , $tmpLine); $MESSAGES->enqueue(array($matchedLevel,$matchedMessage)); $i++; $fileHNDL->seek($i); } while (!$fileHNDL->eof()); } /** * Freeing up the file handler resource so it could be closed. */ $fileHNDL = \NULL; } /** * This is the Logger's constructor */ public function __construct() { } /** * This is the Logger's destructor */ public function __destruct() { } /** * This is the ToString defult function */ public function __toString() { } } $newLogger = new Logger(); newLogger->Import($MESSAGES);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.40.0070.00718.91
8.3.30.0070.00719.04
8.3.20.0080.00020.37
8.3.10.0040.00423.54
8.3.00.0100.00020.56
8.2.170.0120.00322.96
8.2.160.0160.00320.53
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0040.01426.16
8.2.120.0080.00022.28
8.2.110.0030.00621.91
8.2.100.0060.00318.87
8.1.270.0000.00823.83
8.1.260.0030.00626.35
8.1.250.0030.00628.09
8.1.240.0000.01018.75
8.1.230.0000.01018.71
5.4.270.0070.03912.44
5.4.260.0110.04612.44
5.4.250.0050.04712.45
5.4.240.0080.05712.44
5.4.230.0150.05212.43
5.4.220.0100.05012.43
5.4.210.0040.05512.43
5.4.200.0080.05112.43
5.4.190.0130.04912.43
5.4.180.0100.04912.43
5.4.170.0150.06112.44
5.4.160.0080.05312.43
5.4.150.0090.04812.43
5.4.140.0070.05812.12
5.4.130.0140.04812.10
5.4.120.0100.07912.07
5.4.110.0060.05012.06
5.4.100.0060.06112.06
5.4.90.0100.05612.06
5.4.80.0060.05112.06
5.4.70.0050.03612.06
5.4.60.0040.03812.06
5.4.50.0080.03812.06
5.4.40.0080.04712.05
5.4.30.0070.03512.04
5.4.20.0090.03212.04
5.4.10.0040.03812.04
5.4.00.0060.03511.53
5.3.280.0090.03412.71
5.3.270.0040.04112.73
5.3.260.0070.04012.72
5.3.250.0040.04712.71
5.3.240.0140.04712.71
5.3.230.0070.04712.71
5.3.220.0050.03812.68
5.3.210.0090.05412.68
5.3.200.0100.05412.68
5.3.190.0070.05512.68
5.3.180.0160.04812.67
5.3.170.0070.03612.67
5.3.160.0070.03712.67
5.3.150.0030.04012.67
5.3.140.0070.03512.66
5.3.130.0050.04212.66
5.3.120.0070.03812.66
5.3.110.0040.04112.66
5.3.100.0050.03812.13
5.3.90.0070.03512.11
5.3.80.0070.03512.09
5.3.70.0040.03812.09
5.3.60.0060.03612.08
5.3.50.0070.03712.03
5.3.40.0160.04312.02
5.3.30.0110.04412.00
5.3.20.0060.03711.77
5.3.10.0070.03711.74
5.3.00.0050.03811.72

preferences:
39.65 ms | 400 KiB | 5 Q