Krumo::_dump PHP Method

_dump() private static method

Dump information about a variable
private static _dump ( mixed &$data, string $name = '…' )
$data mixed
$name string
    private static function _dump(&$data, $name = '…')
    {
        // Highlight elements that have a space in their name.
        // Spaces are hard to see in the HTML and are hard to troubleshoot
        $name = static::sanitizeName($name);
        // object
        if (is_object($data)) {
            static::_object($data, $name);
        } elseif (is_array($data)) {
            static::_array($data, $name);
        } elseif (is_resource($data)) {
            static::_resource($data, $name);
        } elseif (is_string($data)) {
            static::_string($data, $name);
        } elseif (is_float($data)) {
            static::_float($data, $name);
        } elseif (is_integer($data)) {
            static::_integer($data, $name);
        } elseif (is_bool($data)) {
            static::_boolean($data, $name);
        } elseif (is_null($data)) {
            static::_null($name);
        }
    }

Usage Example

Example #1
0
 /**
  * Render a dump for the properties of an array or objeect
  *
  * @param mixed &$data
  * @access private
  * @static
  */
 private static function _vars(&$data)
 {
     $_is_object = is_object($data);
     // test for references in order to
     // prevent endless recursion loops
     $_recursion_marker = Krumo::_marker();
     if ($_is_object) {
         if (($hash = spl_object_hash($data)) && isset(self::$objectRecursionProtection[$hash])) {
             $_r = self::$objectRecursionProtection[$hash];
         } else {
             $_r = NULL;
         }
     } else {
         $_r = isset($data[$_recursion_marker]) ? $data[$_recursion_marker] : null;
     }
     // recursion detected
     if ($_r > 0) {
         return Krumo::_recursion();
     }
     // stain it
     Krumo::_hive($data);
     // render it
     $collapsed = Krumo::_isCollapsed(self::$_level, count($data) - 1);
     if ($collapsed) {
         $collapse_style = 'style="display: none;"';
     } else {
         $collapse_style = '';
     }
     print "<div class=\"krumo-nest\" {$collapse_style}>";
     print "<ul class=\"krumo-node\">";
     // we're descending one level deeper
     self::$_level++;
     // Object?? - use Reflection
     if ($_is_object) {
         $reflection = new ReflectionObject($data);
         $properties = $reflection->getProperties();
         foreach ($properties as $property) {
             $prefix = null;
             $setAccessible = false;
             if ($property->isPrivate()) {
                 $setAccessible = true;
                 $prefix = 'private';
             } elseif ($property->isProtected()) {
                 $setAccessible = true;
                 $prefix = 'protected';
             } elseif ($property->isPublic()) {
                 $prefix = 'public';
             }
             $name = $property->getName();
             if ($setAccessible) {
                 $property->setAccessible(true);
             }
             $value = $property->getValue($data);
             Krumo::_dump($value, "<span>{$prefix}</span>&nbsp;{$name}");
             if ($setAccessible) {
                 $property->setAccessible(false);
             }
         }
     } else {
         // keys
         $keys = array_keys($data);
         // iterate
         foreach ($keys as $k) {
             // skip marker
             if ($k === $_recursion_marker) {
                 continue;
             }
             // get real value
             $v =& $data[$k];
             Krumo::_dump($v, $k);
         }
     }
     print "</ul>\n</div>";
     self::$_level--;
 }