/** * Wrapper of Var_Dump * @param mixed any kind of eepression * @return void */ function epVarDump($var) { static $vd; if (epIsWebRun()) { include_once 'Var_Dump.php'; Var_Dump::displayInit(array('display_mode' => 'HTML4_Table')); Var_Dump::display($var); } else { var_dump($var); } }
function dump($var) { $trace = debug_backtrace(); echo "<div style=\"text-align:left\">dump() in {$trace[0]['file']}:{$trace[0]['line']}</div>"; //include_once 'Var_Dump.php'; if (class_exists('Var_Dump')) { Var_Dump::displayInit(array('display_mode' => 'HTML4_Table')); Var_Dump::display($var); } else { echo "<pre style=\"text-align:left\">"; var_dump($var); echo "</pre>"; } }
* * To display a variable : * * Var_Dump::display($variable); * * To return a variable : * * $str = Var_Dump::display($variable, TRUE); * */ /* * Initialise the HTML4 Table rendering */ Var_Dump::displayInit(array('display_mode' => 'HTML4_Table')); /* * Displays an array */ echo '<h2>Array</h2>'; $fileHandler = tmpfile(); $linkedArray = array('John', 'Jack', 'Bill'); $array = array( 'key-1' => 'The quick brown fox jumped over the lazy dog', 'key-2' => 234, 'key-3' => array( 'key-3-1' => 31.789, 'key-3-2' => & $linkedArray,
// Setup for displaying XHTML output. Var_Dump::displayInit(array('display_mode' => 'XHTML_Text'), array('mode' => 'normal', 'offset' => 4)); /** * Headline function for XHTML output * * @param string $text Text to put in header * * @return void */ function head($text) { echo '<br /><b>' . $text . '</b><br />'; } } else { // Setup for displaying console output. Var_Dump::displayInit(array('display_mode' => 'Text')); /** * Headline function for XHTML output * * @param string $text Text to put in header * * @return void */ function head($text) { echo "\n--- " . $text . " ---\n"; } } head("\$ftp = new Net_FTP();"); $ftp = new Net_FTP(); head("\$ftp->setHostname({$host})");
/** * Debug output * * <code> * Panda_Debug::p * 出力モードを指定して変数を出力します * </code> * * @param mixed $values any values * @param string $ouputMode 'var' | 'export' | 'syslog' | 'fire' dafult is 'print_a' * @param array $options options * * @return void */ public static function p($values = '', $ouputMode = null, array $options = array()) { if (!self::$enable) { return; } if (isset($options['return']) && $options['return'] === true) { ob_start(); } // Roならarrayに if (class_exists('BEAR_Ro', false) && $values instanceof BEAR_Ro) { $values = array('code' => $values->getCode(), 'headers' => $values->header, 'body' => $values->body, 'links' => $values->links); } if ($ouputMode === null && is_scalar($values)) { $ouputMode = 'dump'; } $trace = isset($options['trace']) ? $options['trace'] : debug_backtrace(); $file = $trace[0]['file']; $line = $trace[0]['line']; $includePath = explode(":", get_include_path()); $method = isset($trace[1]['class']) ? " ({$trace[1]['class']}" . '::' . "{$trace[1]['function']})" : ''; $fileArray = file($file, FILE_USE_INCLUDE_PATH); $p = trim($fileArray[$line - 1]); unset($fileArray); preg_match("/p\\((.+)[\\s,\\)]/is", $p, $matches); $varName = isset($matches[1]) ? $matches[1] : ''; $label = isset($options['label']) ? $options['label'] : "{$varName} in {$file} on line {$line}{$method}"; if (strlen(serialize($values)) > 1000000) { $ouputMode = 'dump'; } $label = is_object($values) ? ucwords(get_class($values)) . " {$label}" : $label; // if CLI if (PHP_SAPI === 'cli') { $colorOpenReverse = "[7;32m"; $colorOpenBold = "[1;32m"; $colorOpenPlain = "[0;32m"; $colorClose = "[0m"; echo $colorOpenReverse . "{$varName}" . $colorClose . " = "; var_dump($values); echo $colorOpenPlain . "in {$colorOpenBold}{$file}{$colorClose}{$colorOpenPlain} on line {$line}{$method}" . $colorClose . "\n"; return; } if (Panda::isCliOutput()) { if (class_exists('FB', false)) { $ouputMode = 'fire'; } else { $ouputMode = 'syslog'; } } $labelField = '<fieldset style="color:#4F5155; border:1px solid black;padding:2px;width:10px;">'; $labelField .= '<legend style="color:black;font-size:9pt;font-weight:bold;font-family:Verdana,'; $labelField .= 'Arial,,SunSans-Regular,sans-serif;">' . $label . '</legend>'; switch ($ouputMode) { case 'v': case 'var': if (class_exists('Var_Dump', false)) { Var_Dump::displayInit(array('display_mode' => 'HTML4_Text')); print $labelField; Var_Dump::display($values); } else { ob_start(); var_export($values); $var = ob_get_clean(); print $labelField; echo "<pre>" . $var . '</pre>'; } print "</fieldset>"; break; case 'd': case 'dump': $file = "<a style=\"color:gray; text-decoration:none;\" target=\"_blank\" href=/__panda/edit/?file={$file}&line={$line}>{$file}</a>"; $dumpLabel = isset($options['label']) ? $options['label'] : "in <span style=\"color:gray\">{$file}</span> on line {$line}{$method}"; echo self::dump($values, null, array('label' => $dumpLabel, 'var_name' => $varName)); break; case 'e': case 'export': echo "{$labelField}<pre>" . var_export($values, true); echo '</fieldset></pre>'; break; case 'h': case 'header': header("x-panda-{$label}", print_r($values, true)); break; case 's': case 'syslog': syslog(LOG_DEBUG, "label:{$label}" . print_r($values, true)); break; case 'f': case 'fire': if (class_exists('FB', false)) { $label = isset($options['label']) ? $options['label'] : 'p() in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line']; FB::group($label); FB::error($values); FB::groupEnd(); } break; case null: case 'printa': case 'print_a': default: $options = "max_y:100;pickle:1;label:{$label}"; print_a($values, $options); } if (isset($options['return']) && $options['return'] === true) { return ob_get_clean(); } }
<html> <style> /* style for XHTML_Text */ pre.var_dump { line-height:1.8em; } pre.var_dump span.type { color:#006600; background:transparent; } pre.var_dump span.value { padding:2px; color:#339900; background:#F0F0F0; border: 1px dashed #CCCCCC; } </style> <body> <?php include_once 'Var_Dump.php'; echo '<h1>example5.php : Text displaying modes</h1>'; /* * example5.php : Text displaying modes * */ $fileHandler = tmpfile(); $linkedArray = array(0 => 'John', 11 => 'Jack', 127 => 'Bill'); $array = array('key-1' => 'The quick brown fox jumped over the lazy dog', 'key-2' => array('long-key' => &$linkedArray, 'file' => $fileHandler), 'long-key-3' => 234); echo '<h2>Compact mode (offset 4)</h2>'; Var_Dump::displayInit(array('display_mode' => 'HTML4_Text'), array('mode' => 'compact', 'offset' => 4)); Var_Dump::display($array); echo '<h2>Normal mode (offset 4)</h2>'; Var_Dump::displayInit(array('display_mode' => 'HTML4_Text'), array('mode' => 'normal', 'offset' => 4)); Var_Dump::display($array); echo '<h2>Wide mode (offset 4)</h2>'; Var_Dump::displayInit(array('display_mode' => 'HTML4_Text'), array('mode' => 'wide', 'offset' => 4)); Var_Dump::display($array); fclose($fileHandler); ?> </body> </html>
/** * Array Renderer Class constructor (ZE2) for PHP5+ * * @param object &$parser Instance of the parser (model of MVC pattern) * @param array $conf A hash containing any additional configuration * * @access public * @since version 1.8.0b2 (2008-06-03) */ function __construct(&$parser, $conf) { parent::PHP_CompatInfo_Renderer($parser, $conf); $driver = 'PEAR::Var_Dump'; if (isset($conf[$driver])) { $var_dump = 'Var_Dump.php'; if (PHP_CompatInfo_Renderer::isIncludable($var_dump)) { include_once $var_dump; $class_options = $conf['PEAR::Var_Dump']; if (isset($class_options['options'])) { $options = $class_options['options']; } else { $options = array(); } if (isset($class_options['rendererOptions'])) { $rendererOptions = $class_options['rendererOptions']; } else { $rendererOptions = array(); } if (php_sapi_name() == 'cli') { // prevent wrong display on command line interface $options['display_mode'] = 'Text'; } Var_Dump::displayInit($options, $rendererOptions); $this->driver = $driver; } } if (!isset($this->driver)) { // if optional driver not defined, then use default PHP::var_export $this->driver = 'PHP'; } }
* */ $fileHandler = tmpfile(); $linkedArray = array(TRUE, 123, 123.45); $array = array('key1' => 'The quick brown' . "\n" . 'fox jumped over' . "\n" . 'the lazy dog', 'key2' => &$linkedArray, 'key3' => NULL, 'key4' => $fileHandler); echo '<h2>Text</h2>'; Var_Dump::displayInit(array('display_mode' => 'Text')); echo '<pre>'; Var_Dump::display($array); echo '</pre>'; echo '<h2>HTML4_Table</h2>'; Var_Dump::displayInit(array('display_mode' => 'HTML4_Table'), array('show_eol' => '•')); Var_Dump::display($array); echo '<h2>HTML4_Text</h2>'; Var_Dump::displayInit(array('display_mode' => 'HTML4_Text'), array('show_eol' => '•')); Var_Dump::display($array); echo '<h2>XHTML_Table</h2>'; Var_Dump::displayInit(array('display_mode' => 'XHTML_Table')); Var_Dump::display($array); echo '<h2>XHTML_Text</h2>'; Var_Dump::displayInit(array('display_mode' => 'XHTML_Text')); Var_Dump::display($array); echo '<h2>XML</h2>'; Var_Dump::displayInit(array('display_mode' => 'XML')); echo '<pre>'; echo htmlspecialchars(Var_Dump::display($array, TRUE)); echo '</pre>'; fclose($fileHandler); ?> </body> </html>
<?php include_once 'Var_Dump.php'; echo '<h1>example2.php : singleton approach</h1>'; /* * example2.php : Singleton approach * * Var_Dump::display() uses a singleton pattern, so if you want to * use this method, and configure the output to your needs, you will have * to call before the displayInit method with the appropriate parameters. * (for instance in the auto_prepend file) * */ // Initialise the HTML4 Table rendering (see Var_Dump/Renderer/HTML4_Table.php) Var_Dump::displayInit(array('display_mode' => 'HTML4_Table'), array('show_caption' => FALSE, 'bordercolor' => '#DDDDDD', 'bordersize' => '2', 'captioncolor' => 'white', 'cellpadding' => '4', 'cellspacing' => '0', 'color1' => '#FFFFFF', 'color2' => '#F4F4F4', 'before_num_key' => '<font color="#CC5450"><b>', 'after_num_key' => '</b></font>', 'before_str_key' => '<font color="#5450CC">', 'after_str_key' => '</font>', 'before_value' => '<i>', 'after_value' => '</i>')); /* * Displays an array */ echo '<h2>Array</h2>'; $fileHandler = tmpfile(); $linkedArray = array('John', 'Jack', 'Bill'); $array = array('key-1' => 'The quick brown fox jumped over the lazy dog', 'key-2' => 234, 'key-3' => array('key-3-1' => 31.789, 'key-3-2' => &$linkedArray, 'file' => $fileHandler), 'key-4' => NULL); Var_Dump::display($array); /* * Displays an object (with recursion) */ echo '<h2>Object (Recursive)</h2>'; class c_parent { function c_parent() {
<?php /* TODO: ImplyRight */ require_once 'config.inc.php'; include_once 'Var_Dump.php'; Var_Dump::displayInit(array('display_mode' => 'XHTML_Text'), array('mode' => 'normal', 'offset' => 4)); ?> <html> <style> a { color: #006600; text-decoration: none; } a:visisted { text-decoration: none; } a:hover { text-decoration: underline; } /* style for XHTML_Text */ table.var_dump { border-collapse:separate; border:1px solid black; border-spacing:0; } table.var_dump tr { color:#006600; background:#F8F8F8; vertical-align:top; } table.var_dump tr.alt { color:#006600; background:#E8E8E8; } table.var_dump th { padding:4px; color:black; background:#CCCCCC; text-align:left; } table.var_dump td { padding:4px; }
function debug_var($var) { @(include_once 'Var_Dump.php'); if (class_exists('Var_Dump')) { Var_Dump::displayInit(array('display_mode' => 'HTML4_Text'), array('mode' => 'normal', 'offset' => 3, 'before_type' => '<font color="#006600">', 'after_type' => '</font>', 'before_value' => '<font color="#000088">', 'after_value' => '</font>')); Var_Dump::display($var); } else { echo "<pre>\n"; print_r($var); echo "</pre>\n"; } }
/** * Dumps a var with PEAR::Var_Dump. * * @param mixed $var The variable to dump * @param string $title An optional title * * @return void */ public static function varDump($var, $title = '') { echo $title ? '<h3><tt>' . $title . '</tt></h3>' : ''; $debug_type = JComponentHelper::getParams('com_easycreator')->get('ecr_debug_type', 'easy'); if ($debug_type == 'krumo') { ecrLoadHelper('krumo_0_2.krumo'); krumo::dump($var); return; } include_once 'Var_Dump.php'; if (class_exists('Var_Dump')) { Var_Dump::displayInit(array('display_mode' => 'HTML4_Table'), array('show_caption' => FALSE, 'bordercolor' => '#ccc', 'bordersize' => '2', 'captioncolor' => 'black', 'cellpadding' => '8', 'cellspacing' => '5', 'color1' => '#000', 'color2' => '#000', 'before_num_key' => '<span style="color: #fff; font-weight: bold;">', 'after_num_key' => '</span>', 'before_str_key' => '<span style="color: #5450cc; font-weight: bold;">', 'after_str_key' => '</span>', 'before_value' => '<span style="color: #5450cc;">', 'after_value' => '</span>')); Var_Dump::display($var); } else { echo '<pre>' . print_r($var, true) . '</pre>'; } }
public static function init_Var_Dump() { Var_Dump::displayInit(array('display_mode' => 'HTML4_Text'), array('mode' => 'normal', 'offset' => 4)); }