3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class DS { /* * Properties for logging in-loops */ private static $_variables = array(); private static $_arrays = array(); /* * Property for global data store */ private static $_globals = array(); private static $_constants = array(); private static $_objects = array(); /* * Properties for logging storage */ private static $_errors = array(); private static $_progress = array(); private static $_syse = array(); const LOGGING_PROGRESS_FILE_PREFIX = 'progress'; const LOGGING_ERRORS_FILE_PREFIX = 'errors'; const LOGGING_DEBUG_FILE_PREFIX = 'debug'; const LOGGING_KEYS_PER_WRITE = 100; const LOGGING_LINE_FORMAT = '%1$s - [%2$s/%3$s][%4$s] %5$s: %6$s'; const LOGGING_SYSE_LINE_FORMAT = '%1$s - [PHP %2$s ON %3$s:%4$s] - %5$s (%6$s)'; /* * Property for temporary storage */ private static $_tmp = array(); /* * Property for logging output */ private static $_log = array(); private static $_fbt = array(); public static function init() { //date folder // /* * Used for wiping data for in-loop stored data * ready for next iteration */ } /* * GENERAL LOGGING */ public static function L($section = 'general', $text = '', $type = 'progress', $kill = 0) { if (!empty($type) && !empty($title)) { self::$_fbt = self::FBT(debug_backtrace()); self::${"_$type"}[] = sprintf(self::LOGGING_LINE_FORMAT, date('dmY-His'), DS::G('CURRENT_TYPE'), DS::G('CURRENT_CRAWLER'), $section, self::$_fbt, $text ); if (count(self::${"_$type"}) >= self::LOGGING_KEYS_PER_WRITE) { self::logWrite($type); } } } public static function SYS_E($errno, $errstr, $errfile, $errline){ if (!$errno) return; switch ($errno) { case E_USER_ERROR: $type='ERROR'; break; case E_USER_WARNING: $type='WARNING'; break; case E_USER_NOTICE: $type='NOTICE'; break; default: $type='UNKNOWN'; break; } self::$_syse[] = sprintf(self::LOGGING_SYSE_LINE_FORMAT, date('dmY-His'), $type, $errfile, $errline, $errstr, $errno ); self::logWrite('syse'); return true; } private static function logWrite($type = '') { if (empty($type)) return false; $fh = fopen(DIR_LOG.date('Ymd').'-'.$type,'a'); foreach (self::${"_$type"} as $item) fwrite($fh,$text."\n"); fclose($fh); self::clearLogBuffer($type); } private static function FBT($fbt,$full=0) { $arr=array(); foreach($bt as $bti){ $arr[]= $bti['function']; } $arr=array_reverse($arr); array_pop($arr); return ($full===1 ? implode('->',$arr) : $arr[count($arr)-1]); } private static function clearLogBuffer($type) { self::${"_$type"} = array(); } /** * // GENERAL LOGGING */ /** * public static function loopReset() { self::$_variables = array(); self::$_arrays = array(); self::$_tmp = array(); self::$_log = array(); } /** * KEY - VALUE STORAGE */ public static function dump($title = '') { if (!empty($title)) { self::$_log[] = $title.' {'; self::$_log[] = ''; } foreach (array('variables','constants','arrays') as $varName) { self::$_log[] = "\t".strtoupper($varName); if (count(self::${"_$varName"}) > 0) { foreach (self::${"_$varName"} as $k => $v) { self::$_log[] = "\t\t".'$'.$k.' = '.self::inlinePrint($v); } } else { self::$_log[] = "\t\tnone"; } } if (!empty($title)) { self::$_log[] = ''; self::$_log[] = '}'; self::$_log[] = ''; } echo implode("\n",self::$_log); } public static function V($name,$val = '') { if (!self::setVal('variables',$name,$val)) return self::$_variables[$name]; } public static function C($name,$val = '') { if (!self::setVal('constants',$name,$val)) return self::$_constants[$name]; } public static function A($name,$array = '') { if (!self::setVal('arrays',$name,$array)) return self::$_arrays[$name]; } public static function G($name,$value) { if (!self::setVal('globals',$name,$value)) return self::$_globals[$name]; } public static function O($name,$value) { if (!self::setVal('objects',$name,$value)) return self::$_global[$name]; } private static function setVal($type,$name,$value) { if (!empty($type) && !empty($name) && !empty($value)) { if (strpos($name,':')!==false && in_array($type,array('arrays','globals'))) { foreach(explode(':',$arr) as $split) $conv.= '[\''.$split.'\']'; if (empty($array)) { eval("return (isset(self::\$_$type$conv) ? self::\$_$type$conv : false);"); }else{ eval("self::\$_arrays$conv = \$array;"); } }else{ self::${"_$type"}[$name] = $value; return true; } } } private static function inlinePrint($data) { return str_replace(array("\n","\t"," "," "),' ',print_r($data,true)); } } DS::A('array1',array(1,2,3)); DS::C('constant1','doom'); DS::dump('prod #12343'); ?>
based on YTZqd
Output for 5.4.0 - 7.2.0
prod #12343 { VARIABLES none CONSTANTS $constant1 = doom ARRAYS $array1 = Array ( [0] => 1 [1] => 2 [2] => 3 ) }