note 106572 added to function.debug-backtrace

From: Date: Sat, 19 Nov 2011 20:32:35 +0000
Subject: note 106572 added to function.debug-backtrace
Groups: php.notes 
Request: Send a blank email to php-notes+get-184575@lists.php.net to get a copy of this message
A function that i use for debug I shortened variables name and i eliminated the spaces from second function in order fit in post :( <?php define("LFP", './lt.log'); function LogTrace($Argument, $lfn = LFP, $itw = ' ') { error_log("=====\r", 3, $lfn); error_log("[BEGIN BACKTRACE]\r", 3, $lfn); $it = ''; $Ts = array_reverse(debug_backtrace()); foreach($Ts as $T) { if($T['function'] != 'include' && $T['function'] != 'require' && $T['function'] != 'include_once' && $T['function'] != 'require_once') { $ft = $it . '<'. basename($T['file']) . '> on line ' . $T['line']; if($T['function'] != 'LogTrace') { if(isset($T['class'])) $ft .= ' in method ' . $T['class'] . $T['type']; else $ft .= ' in function '; $ft .= $Trace['function'] . '('; } else $ft .= '('; if(isset($T['args'][0])) { if($T['function'] != 'LogTrace') { $ct = ''; foreach($T['args'] as $A) { $ft .= $ct . LogVar($A, '', $it, $itw, 0); $ct = $it . $itw . ','; } } else $ft .= LogVar($T['args'][0], '', $it, $itw, 0); } $ft .= $it . ")\r"; error_log($ft, 3, $lfn); $it .= $itw; } } error_log("[END BACKTRACE]\r", 3, $lfn); } function LogVar(&$Var, $vn, $pit, $itw, $nlvl, $m = '') { if($nlvl>=16) return; if($nlvl==0){$tv=serialize($Var);$tv=unserialize($tv);} else $tv=&$Var; $it=$pit.$itw; for($i=0; $i<$nlvl;$i++) $it.='.'.$itw; $o='';$nl="\n"; if(is_array($tv)) { if(strlen($vn)>0) $o.=$it.$m.'<array> $'.$vn.' = ('; else $o.="\r".$it.$m.'<array> = ('; $o.= $nl;$AK=array_keys($tv); foreach($AK as $AN) {$AV=&$tv[$AN];$o.=LogVar($AV,$AN,$pit,$itw,$nlvl+1);} $o.=$it.')'.$nl; } else if(is_string($tv)) { if(strlen($vn)>0)$o.=$it.$m.'<string> $'.$vn.' = '; else $o.=' '.$m.'<string> = '; if($tv===null) $o.='NULL'; else $o.='"'.$tv.'"'; $o.=$nl; } else if(is_bool($tv)) { if(strlen($vn) > 0) $o.=$it.$m.'<boolean> $'.$vn.' = '; else $o.=' '.$m.'<boolean> = '; if($tv===true) $o.='TRUE'; else $o.='FALSE'; $o.=$nl; } else if(is_object($tv)) { if(strlen($vn)>0) { $o.=$pit.$itw; for($i=0;$i<$nlvl;$i++) $o.='.'.$itw; $o.=$m.'<'.get_class($tv).'::$'.$vn.'> = {'.$nl; } else $o.=' '.$m.'<'.get_class($tv).'::> = {'.$nl; $R=new ReflectionClass($tv); $o.=$it.'.'.$itw.'Class methods {'.$nl; $CM=$R->getMethods(); foreach($CM as $MN => $MV) { $o.=$it.'.'.$itw.'.'.$itw.implode(' ',Reflection::getModifierNames($MV->getModifiers())).' '.$MV->getName().'('; $MP=$MV->getParameters(); $ct=''; foreach($MP as $MPN => $MPV) { $o.=$ct; $o.=$MPV->isOptional()?'[':''; if($MPV->isArray()) $o.='<array> '; else if($MPV->getClass()!==null) $o.='<'.$MPV->getClass()->getName().'::> '; $o.=$MPV->isPassedByReference()?'&':''; $o.='$'.$MPV->getName(); if($MPV->isDefaultValueAvailable()) { if($MPV->getDefaultValue()===null) $o.=' = NULL'; else if($MPV->getDefaultValue()===true) $o.=' = TRUE'; else if($MPV->getDefaultValue()===false) $o.=' = FALSE'; else $o.=' = '.$MPV->getDefaultValue(); } $o.=$MPV->isOptional()?']':''; $ct=', '; } $o.=')'.$nl; } $o.=$it.'.'.$itw.'}'.$nl; $o.=$it.'.'.$itw.'Class properties {'.$nl; $CV=$R->getProperties(); foreach($CV as $CN => $CV) { $M=implode(' ',Reflection::getModifierNames($CV->getModifiers())).' '; $CV->setAccessible(true); $o.=LogVar($CV->getValue($tv),$CV->getName(),$pit,$itw,$nlvl+2,$M); } $o.=$it.'.'.$itw.'}'.$nl; $o.=$it.'.'.$itw.'Object variables {'.$nl; $OVs=get_object_vars($tv); foreach($OVs as $ON => $OV) $o.=LogVar($OV,$ON,$pit,$itw,$nlvl+2); $o.=$it.'.'.$itw.'}'.$nl; $o.=$pit.$itw; for($i=0;$i<$nlvl;$i++) $o.='.'.$itw; $o.='}'.$nl; } else { if(strlen($vn)>0) $o.=$it.$m.'<'.gettype($tv).'> $'.$vn.' = '.$tv; else $o.=' '.$m.'<'.gettype($tv).'> = '.$tv; $o.=$nl; } return $o; } //test date_default_timezone_set('Europe/Bucharest'); $date = new DateTime('2010-01-28'); LogTrace($date); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 109.99.228.104 ---- Manual Page -- http://www.php.net/manual/en/function.debug-backtrace.php Edit -- https://master.php.net/note/edit/106572 Del: integrated -- https://master.php.net/note/delete/106572/integrated Del: useless -- https://master.php.net/note/delete/106572/useless Del: bad code -- https://master.php.net/note/delete/106572/bad+code Del: spam -- https://master.php.net/note/delete/106572/spam Del: non-english -- https://master.php.net/note/delete/106572/non-english Del: in docs -- https://master.php.net/note/delete/106572/in+docs Del: other reasons-- https://master.php.net/note/delete/106572 Reject -- https://master.php.net/note/reject/106572 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184575) next »