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 <fpoeydomenge at free dot 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, HTML/XHTML text, HTML/XHTML table, XML, ...
* @author Frederic Poeydomenge <fpoeydomenge at free dot 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_STRING', 6 );
define ('VAR_DUMP_TYPE_ARRAY', 1 );
define ('VAR_DUMP_TYPE_OBJECT', 2 );
define ('VAR_DUMP_PREG_MATCH', 0 );
define ('VAR_DUMP_PREG_SPACES', 1 );
define ('VAR_DUMP_PREG_KEY_QUOTE', 2 );
define ('VAR_DUMP_PREG_KEY', 3 );
define ('VAR_DUMP_PREG_STRING_TYPE', 4 );
define ('VAR_DUMP_PREG_STRING_LENGTH', 5 );
define ('VAR_DUMP_PREG_STRING_VALUE', 6 );
define ('VAR_DUMP_PREG_VALUE', 7 );
define ('VAR_DUMP_PREG_VALUE_REFERENCE', 8 );
define ('VAR_DUMP_PREG_VALUE_TYPE', 9 );
define ('VAR_DUMP_PREG_VALUE_COMPL', 10 );
define ('VAR_DUMP_PREG_VALUE_RESOURCE', 11 );
define ('VAR_DUMP_PREG_ARRAY_END', 12 );
define ('VAR_DUMP_PREG_ARRAY_START', 13 );
define ('VAR_DUMP_PREG_ARRAY_TYPE', 14 );
define ('VAR_DUMP_PREG_ARRAY_COUNT', 15 );
define ('VAR_DUMP_PREG_STRING_COMPL', 16 );
* Default configuration options.
var $defaultOptions = array (
'display_mode' => 'XHTML_Text', // Display mode.
'ignore_list' => NULL // List of ignored class names.
* Run-time configuration options.
* Rendering configuration options.
* See Var_Dump/Renderer/*.php for the complete list of options
var $rendererOptions = array ();
* The factory approach must be used in relationship with the
* See Var_Dump/Renderer/*.php for the complete list of options
* @see Var_Dump::toString()
* @param mixed $options String (display mode) or array (Global parameters).
* @param array $rendererOptions Parameters for the rendering.
function Var_Dump ($options = array (), $rendererOptions = array ())
'display_mode' => $options
$this->rendererOptions = $rendererOptions;
$this->options['display_mode'],
* Attempt to return a concrete Var_Dump instance.
* The factory approach must be used in relationship with the
* See Var_Dump/Renderer/*.php for the complete list of options
* @see Var_Dump::toString()
* @param mixed $options String (display mode) or array (Global parameters).
* @param array $rendererOptions Parameters for the rendering.
function & factory ($options = array (), $rendererOptions = array ())
$obj = & new Var_Dump ($options, $rendererOptions);
* 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)
$family = array (); // element family
$depth = array (); // element depth
$type = array (); // element type
$value = array (); // element value
// When xdebug is loaded, disable the custom fancy var_dump() function,
// that is not compatible with the regexp parsing below, by forcing
// the "html_errors" configuration option to "off"
// Captures the output of the var_dump function,
// by using output control functions.
// When xdebug is loaded, restore the value of the
// "html_errors" configuration option
// Regexp that parses the output of the var_dump function.
// The numbers between 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
(?:\[("?)(.*?)\\2\]=>) # Key [2-3]
(?:(&?string\((\d+)\))\s+"(.*)) # String [4-6]
(bool|int|float|resource| # - type [9]
NULL|\*RECURSION\*|UNKNOWN:0) #
(?:\((.*?)\))? # - complement [10]
(?:\sof\stype\s\((.*?)\))? # - resource [11]
(}) # End of array/object [12]
(?:(&?(array|object)\((.+)\).*)\ {) # Start of array/object [13-15]
(.*) # String (additional lines) [16]
// Used to keep the maxLen of the keys for each nested variable.
// Used when matching a string, to count the remaining
// number of chars before the end of the string.
// Loop through the matches of the previously defined regexp.
while (list ($key, $match) = each($matches)) {
$count = count($match) - 1;
// Find which alternative has been matched in the regexp,
// by looking at the number of elements in the $match array.
// - Compute the maxLen of the keys at the actual depth
// - Set the countdown (remaining number of chars before eol) =
// len of the string - matched len + 1 (final ")
// String (additional lines)
//===========================
// - Compute new countdown value
// - Pop value off the end of the array, and concatenate new value
// - Last additional line : remove trailing "
// - Push new value onto the end of array
$new_value = substr($new_value, 0 , -1 );
// - Pop the maxLen of the keys off the end of the stack
// - If the last element on the stack is an array(0) or object(0),
// replace it by a standard element
$keyLen[$oldLen[0 ]] = $maxLen;
($type[count($type) - 1 ] === 0 )
$type[count($type) - 1 ] = $value[count($value) - 1 ];
$value[count($value) - 1 ] = NULL;
//=======================
// - If object is in the "ignore_list", jump at the end of it
// - Else process it normally :
// - Push the maxLen of the keys onto the end of the stack
// - Initialize new maxLen to 0
// If object is in the "ignore_list", jump at the end of it.
! is_null($this->options['ignore_list'])
in_array($class_name, $this->options['ignore_list'])
$type[] = 'object(' . $class_name . ')';
$value[] = 'Not parsed.';
list ($dummy, $each) = each($matches);
// If not, process it normally.
$this->renderer->initialize ($family, $depth, $type, $value, $keyLen);
return $this->renderer->toString ();
* Attempt to return a concrete singleton Var_Dump instance.
* The singleton approach must be used in relationship with the
* displayInit() and display() methods.
* See Var_Dump/Renderer/*.php for the complete list of options
* @see Var_Dump::display(), Var_Dump::displayInit()
* @return object Var_Dump instance
if (! isset ($instance)) {
$instance = new Var_Dump (array (), array (), array ());
* Initialise the singleton object used by the display() method.
* @see Var_Dump::singleton(), Var_Dump::display()
* @param mixed $options String (display mode) or array (Global parameters).
* @param array $rendererOptions Parameters for the rendering.
function displayInit ($options = array (), $rendererOptions = array ())
$displayInit = & Var_Dump ::singleton ();
$displayInit->Var_Dump ($options, $rendererOptions);
* Outputs or returns a string representation of a variable.
* @see Var_Dump::singleton(), Var_Dump::displayInit()
* @param mixed $expression The variable to parse.
* @param bool $return Whether the variable should be echoed or returned.
* @param mixed $options String (display mode) or array (Global parameters).
* @param array $rendererOptions Parameters for the rendering.
* @return string If returned, the string representation of the variable.
function display ($expression, $return = FALSE , $options = NULL , $rendererOptions = NULL )
$display = & Var_Dump ::singleton ();
$rendererOptions = array ();
$display->Var_Dump ($options, $rendererOptions);
return $display->toString ($expression);
echo $display->toString ($expression);
Documentation generated on Mon, 11 Mar 2019 14:23:43 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|