3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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; /** * FIXME: * -- PROBLEM: Server and NetBeans don't understand SplEnum type yet; * so it can't be used for now. * -- DUE: 17 Apr. 2014 * -- MOD: 16 Apr. 2014 14:07 THR */ /*** * Enumeration for logging levels of importancy. * * @author Talaeezadeh */ class LogLevel// extends \SplEnum { //const __default = self::NONE; /** * Disable logging * * @var Constatnt(Int) No loggong */ const NONE = 0; /** * Fatal Errors * * @var Constant(Int) Fatal Errors */ const FATAL = 1; /** * Errors that are not fatal * * @var Constant(Int) Normal Errors */ const ERROR = 2; /** * Warnings * * @var Constant(Int) Warnings */ const WARNING = 3; /** * Notifications * * @var Constant(Int) Notifications */ const NOTICE = 4; /** * Informations * * @var Constant(Int) Informations */ const INFO = 5; /** * Everything that are not categorized in previous levels * * @var Constant(Int) Every (other) thing */ const EVERYTHING = 6; } namespace epay; use SplFileObject; use SplQueue; /** * 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(); $MESSAGES = new SplQueue(); $newLogger->Import($MESSAGES);
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
WARNING @/in/OlIrb line 244: says: \'No arguments. Escaped!\'
Output for 5.3.0 - 5.3.29
Notice: Use of undefined constant __TRAIT__ - assumed '__TRAIT__' in /in/OlIrb on line 244 WARNING @/in/OlIrb line 244: __TRAIT__ says: \'No arguments. Escaped!\'
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/OlIrb on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/OlIrb on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/OlIrb on line 8
Process exited with code 255.