I (very recently, after long time when I thought how to have exception warnings better and as exact and descriptive as possible) solved problem with incomplete report of getTrace with following (maybe not perfect, but still usable) method:
private function Create_TraceText()
{
$trace_text = "<b>TRACE:</b> <br /><br />\n";
$trace = $this -> getTrace();
for($index = 0; $index < count($trace); $index++)
{
$trace_text .= 'STEP ' . ($index + 1) . ":<br />\n";
foreach($trace[$index] as $trace_name => $trace_value)
{
$trace_value = $this -> Convert_StringifyEmpty($trace_value);
$trace_value = $this -> Convert_StringifyNull($trace_value);
$trace_value = $this -> Convert_StringifyArray($trace_value);
$trace_text .= strtoupper($trace_name == 'args' ? 'arguments' : $trace_name) . ': ' . $trace_value . "<br />\n";
}
$trace_text .= "<br />\n";
}
return $trace_text;
}
Method Create_TraceText
calls three other methods that are (also) my own. Those methods have following purpose:
- insert alternative text in case of no argument was set
- replace NULL value with NULL string
- convert arguments' array into string (with comma as glue)
- make code better readable
I chose private accessibility because it is called internally by method that handles report assembling. But if you would like, you may have it public.
It iterates through trace, takes items (keys and their values) of each step and converts them into string in form that is written below
TRACE:
STEP 1:
FILE: A:\WWW\Kilometrovnik\Kilometrovnik.php
LINE: 166
FUNCTION: Execute
CLASS: VMaX\MarC\Assemblers\CodeGenerator
TYPE: ->
ARGUMENTS: not defined
There is only one step in example above, but it may be repeated (automatically done), if demanded by trace.
Notice:
Method getTrace may be used directly, of course. I chose current way to support make code better readable (and may be faster - if method getTrace is used only once).
Also, if you would like, you may delete replacement of args
with arguments
(and have written args
) or let trace items lowercase, as is in default.
Trace parts class and function may be united into method. But it is not neccessary, of course.
Example comes from my localhost private testing project (and your file name may be different).