Project

General

Profile

Actions

Feature #20856

closed

debug in t3lib

Added by David Bruchmann over 15 years ago. Updated over 11 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2009-08-10
Due date:
% Done:

0%

Estimated time:
PHP Version:
4.3
Tags:
Complexity:
Sprint Focus:

Description

as addition or as replacement of t3lib_div::debug I wrote some debug-functions (I use them in an own extension).
Default call is like this:

$this->debug($myVar,__FILE__,__CLASS__,__FUNCTION__,'$myVar',__LINE__,$tmpHint);

$tmpHint is a text, that can be defined as Hint.
$myVar is the variable to debug, once as string, once as var,
The Rest is filled automatically and points to class, function and line where the call is localized.

Objects are much easier to view because they are rendered with more information and as table instead of simple text.
Try it, think about it, and please comment:

function debug($input,$file='',$classname='',$functionname='',$varname='',$position='',$addInfo='') {
$tmpType = $this->getType($input);
if ($classname || $functionname || $varname) {
$widthFirstCol = ' style="width:15em"';
$styleObjRow = ' style="color:#800"';
$name = '<table style="font-size:10px;font-weight:bold;border:0 ;width:100%" border="1">';
$name .= $position ? '<tr><td'.$widthFirstCol.'>File:</td><td title="File: '.$file.'">'.$file.'</td></tr>' : '';
$name .= !$classname ? '<tr><td'.$widthFirstCol.'>Class:</td><td title="Class: '.get_called_class().'">'.get_called_class().'</td></tr>' : '<tr><td>Class:</td><td title="Class: '.$classname.'">'.$classname.'</td></tr>';
$name .= $functionname ? '<tr><td'.$widthFirstCol.'>'.($classname ? 'Method' : 'Function').':</td><td title="'.($classname ? 'Method' : 'Function').': '.$functionname.'">'.$functionname.'</td></tr>' : '';
$name .= $varname ? '<tr'.$styleObjRow.'><td'.$widthFirstCol.'>'.$tmpType.':</td><td title="'.$tmpType.': '.$varname.'">'.$varname.'</td></tr>' : '';
$name .= $position ? '<tr><td'.$widthFirstCol.'>Line or Position:</td><td title="Line or Position: '.$position.'">'.$position.'</td></tr>' : '';
$name .= $addInfo ? '<tr><td'.$widthFirstCol.'>Additional Info:</td><td title="Additional Info: '.$addInfo.'">'.nl2br(wordwrap($addInfo,100)).'</td></tr>' : '';
$name .= '</table>';
}
if ($tmpType == 'object') {
$this->debug_object($input,$name);
}
else {
$this->debug_array($input,$name);
}
return;
}
function getType ($input) {        
$type = "string";
if (is_array($input)) $type = "array";
elseif (is_object($input)) $type = "object";
elseif (is_resource($input)) $type = "resource";
elseif (is_int($input)) $type = "int";
elseif (is_float($input)) $type = "float";
elseif (is_bool($input)) $type = "bool";
return $type;
}
function debug_object ($input,$name='') {
$obj['Type'] = 'object';
$obj['Classname'] = get_class($input);
$obj['Parent Class'] = get_parent_class($input);
$obj['Methods'] = get_class_methods($obj['Classname']);
$obj['Class Vars'] = get_class_vars($obj['Classname']);
$obj['Object Vars'] = get_object_vars($input);
$obj['Implemented Interfaces'] = class_implements($input);
$debugTitle = $obj['Classname'];
//if ($input === $this) $debugTitle .= ' ($this)';
$this->debug_array($obj,($name ? $name : '')); //$debugTitle
}
function debug_array($input,$name) {
echo '

<table class="typo3-debug" border="0" cellpadding="0" cellspacing="0" bgcolor="#eeeeee" style="border:2px solid; margin-top:1em; margin-bottom:1em;">
<tr>
<td style="background-color:#eee; font-family: verdana,arial; font-weight: bold; font-size: 10px;">
'.$name.'
</td>
</tr>
<tr>
<td>
'.t3lib_div::view_array($input).'
</td>
</tr>
</table>

';
}

(issue imported from #M11680)

Actions #2

Updated by David Bruchmann over 15 years ago

Inside the functions linking to each other it's better to write [Class]::[function]
So there is no need to instantiate anything.

Reordering of Parameters can be considered because the call perhaps is easier to note if individual parts follow directly:

$this->debug($myVar,$myShortExplanation,$myLongExplanation,__FILE__,__CLASS__,__FUNCTION__,__LINE__);

Actions #3

Updated by Chris topher over 14 years ago

Not in Core List; what should we do with this?

Actions #4

Updated by Alexander Opitz over 11 years ago

  • Status changed from New to Closed
  • Target version deleted (0)
  • TYPO3 Version set to 4.3

No response in over one year => closed.

Actions

Also available in: Atom PDF