24
trace
trace
SYNOPSIS
trace()
DESCRIPTION
trace collects the output of successive calls to dump or returns the collected outputs.
trace is called with 0, 1 or 2 arguments.
With 1 or 2 arguments, trace collects the output of dump with the same arguments, i.e. a value and an optional label.
With no arguments, trace returns the array of collected dumps.
NOTE: trace is intended for debugging.
A programmer can decide where to display the collected dumps.
See the final view standard.phtml in layouts:
<body>
<?php if (!empty($trace)): ?>
<div>
<?php foreach ($trace as $s): ?>
<?php echo $s; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (!empty($trace)): ?>
<div>
<?php foreach ($trace as $s): ?>
<?php echo $s; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
CODE
- require_once 'dump.php';
- function trace() {
- static $trace = null;
- if (func_num_args() == 0) {
- return $trace;
- }
- $var = func_get_arg(0);
- $label = func_num_args() > 1 ? func_get_arg(1) : null;
- if (!$trace) {
- $trace = array();
- }
- $trace[]=dump($var, $label, false);
- return true;
- }
Comments