Source for file Var_Dump.php
Documentation is available at Var_Dump.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Frederic Poeydomenge <frederic.poeydomenge@free.fr> |
// +----------------------------------------------------------------------+
require_once 'Var_Dump/Renderer.php';
* Wrapper for the var_dump function.
* " The var_dump function displays structured information about expressions
* that includes its type and value. Arrays are explored recursively
* with values indented to show structure. "
* The Var_Dump class captures the output of the var_dump function,
* by using output control functions, and then uses external renderer
* classes for displaying the result in various graphical ways :
* simple text, (X)HTML text, (X)HTML table, XML, ...
* @author Frederic Poeydomenge <frederic.poeydomenge@free.fr>
define ('VAR_DUMP_START_GROUP', 1 );
define ('VAR_DUMP_FINISH_GROUP', 2 );
define ('VAR_DUMP_START_ELEMENT_NUM', 3 );
define ('VAR_DUMP_START_ELEMENT_STR', 4 );
define ('VAR_DUMP_FINISH_ELEMENT', 5 );
define ('VAR_DUMP_FINISH_ELEMENT_NL', 6 );
* Run-time configuration options.
* Default configuration options.
var $defaultOptions = array (
'display_mode' => 'XHTML_Text'
* Rendering configuration options, one entry for each renderer.
* See Var_Dump/Renderer/*.php for the complete list of options
var $rendererOptions = array ();
* See Var_Dump/Renderer/*.php for the complete list of options
* @param array $options Global parameters.
* @param array $rendererOptions Parameters for the rendering.
function Var_Dump ($options = array (), $rendererOptions = array ())
$this->setOptions ($options);
$displayMode= $this->options['display_mode'];
if (!isset ($this->rendererOptions[$displayMode])) {
$this->rendererOptions[$displayMode] = $rendererOptions;
$this->rendererOptions[$displayMode],
$this->rendererOptions[$displayMode]
* Attempt to return a concrete Var_Dump instance.
* See Var_Dump/Renderer/*.php for the complete list of options
* @param array $options Global parameters.
* @param array $rendererOptions Parameters for the rendering.
function & factory ($options = array (), $rendererOptions = array ())
$obj = & new Var_Dump ($options, $rendererOptions);
* Attempt to return a concrete singleton Var_Dump instance.
* See Var_Dump/Renderer/*.php for the complete list of options
* @param array $options Run-time configuration options.
* @param array $rendererOptions Parameters for the rendering.
function & singleton ($options = array (), $rendererOptions = array ())
$instance = new Var_Dump ($options, $rendererOptions);
$instance->Var_Dump ($options, $rendererOptions);
* Set run-time configuration options for the renderer
* @param array $options Run-time configuration options.
function setOptions ($options = array ())
* Outputs or returns a string representation of a variable.
* @param mixed $expression The variable to parse.
* @param bool $return Whether the variable should be echoed or returned.
* @return string If returned, the string representation of the variable.
function display ($expression, $return=FALSE )
$display = & Var_Dump ::singleton ();
return $display->toString ($expression);
echo $display->toString ($expression);
* Uses a renderer object to return the string representation of a variable.
* @param mixed $expression The variable to parse.
* @return string The string representation of the variable.
function toString ($expression)
if (PEAR ::isError ($this->renderer)) {
$family = array (); // element family
$depth = array (); // element depth
$type = array (); // element type
$value = array (); // element value
// The numbers between the square brackets [] are the reference of the captured subpattern
// and correspond to the entries in the resulting $matches array
(\s*) # 2 spaces for each depth level
(?: # start of alternative
(?:\[("?)(.*?)\\2\]=>) # = Key [2-3]
(?: # = Value, multiline [4-5]
(string\([0-9]*\)) # - type [4]
\s+"(.*[^"]$\n # - value [5], first line (no " at the end)
(?:^.*[^"]$\n)* # - value [5], multiple middle line (no " at the end)
^.*)" # - value [5], last line (closing ")
(bool|string|int|float| # - type [7]
resource|NULL|\*RECURSION\*) #
(?:\((.*?)\))? # - complement [8]
(?:\s+(?: # - value [9-10]
(?:"(.*?)") | # . string [9] OR
(?:of\ type\ \((.*?)\)) # . resource [10]
(}) # = End of array [11]
(?:(&?(?:array|object).*)\ {) # = Start of array [12]
foreach($matches AS $match) {
if ($count>=4 and $count<=13 ) {
$depth[] = strlen($match[1 ]) >> 1;
$type[] = $match[7 ]. '('. $match[8 ]. ')';
$type[] = $match[7 ]. '('. $match[10 ]. ')';
$keyLen[$oldLen[0 ]] = $maxLen;
$value[] = $match[$count-1 ];
$value[] = $match[$count-1 ];
$this->renderer->initialize (
return $this->renderer->toString ();
Documentation generated on Mon, 11 Mar 2019 10:16:08 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|