' : '';
-
- $isSimpleVar = false;
- $valueType = gettype($value);
- switch($valueType)
- {
- case 'array' : $result .= '
ARRAY'.htmlspecialchars('['); break;
- case 'object' : $result .= '
OBJECT ' . get_class($value) . ''.htmlspecialchars('('); break;
- default : $value = [$value]; $isSimpleVar = true; break;
- }
-
- $result .= '
';
-
- foreach ($value as $key => $val)
- {
- $valType = gettype($val);
- if ($valType === 'array' || $valType === 'object')
- {
- if ($valueType === 'array')
- {
- $result .= '- [' . htmlspecialchars(strval($key)) . '] '.htmlspecialchars('=>').' ' . xout($val, $dontDie, false) . '
';
- }
- if ($valueType === 'object')
- {
- $result .= '- ' . htmlspecialchars(strval($key)) . ' '.htmlspecialchars('->').' ' . xout($val, $dontDie, false) . '
';
- }
- }
- else
- {
- $color = 'black';
- switch($valType)
- {
- case 'string' : $color = $stringTypeColor; $val = htmlspecialchars('\'').$val.htmlspecialchars('\''); break;
- case 'integer' : $color = $integerTypeColor; $val = strval($val); break;
- case 'double' : $color = $doubleTypeColor; $val = strval($val); break;
- case 'resource' : $color = $resourceTypeColor; $val = 'resource ('.get_resource_type($val).')'; break;
- case 'resource (closed)' : $color = $resourceClosedTypeColor; $val = 'resource (closed)'; break;
- case 'boolean' : $color = $booleanTypeColor; $val = ($val === true) ? 'TRUE' : 'FALSE'; break;
- case 'NULL' : $color = $nullTypeColor; $val = 'NULL'; break;
- }
-
- $result .= '- ';
- if(!$isSimpleVar)
- {
- if($valueType === 'array')
- {
- $result .= '[' . htmlspecialchars(strval($key)) . '] '.htmlspecialchars('=>').' ';
- }
- if($valueType === 'object')
- {
- $result .= '' . htmlspecialchars(strval($key)) . ' '.htmlspecialchars('->').' ';
- }
- }
- $result .= '' . htmlspecialchars($val) . '
';
- }
- }
-
- $result .= '
';
-
- if(!$isSimpleVar)
- {
- switch($valueType)
- {
- case 'array' : $result .= htmlspecialchars(']'); break;
- case 'object' : $result .= htmlspecialchars(')'); break;
- }
- }
-
- $result .= $initCall ? '
' : '';
-
- if($initCall) //Finished
- {
- echo($result);
- if(!$dontDie)
- {
- die();
- }
- }
- else //End of recursive call
- {
- return $result;
- }
+ private function __construct(){}
+
+ const FONT_FAMILY = 'Courier New';
+ const FONT_WEIGHT = 'normal';
+ const FONT_SIZE = '16px';
+ const INDENT_SIZE = '2rem';
+
+ const BASE_COLOR = '#333';
+ const CLASS_COLOR = '#267f99';
+
+ const ARRAY_COLOR = '#777';
+ const OBJ_PROP_COLOR = '#333';
+
+ const OBJ_COLOR = '#777';
+ const STRING_COLOR = '#a31515';
+ const INT_COLOR = '#098658';
+ const DOUBLE_COLOR = '#098658';
+ const RES_COLOR = 'purple';
+ const RES_CLOSED_COLOR = 'plum';
+ const BOOL_COLOR = '#00f';
+ const NULL_COLOR = '#00f';
+ const FUNCTION_COLOR = '#00f';
+
+ private static $braceColors = ['#00f', '#319331', '#7b3814']; //PHP 5.4 does not support array constants
+ const BRACE_STYLE_ALLMAN = true;
+
+
+ /**
+ * A more readable implementation of PHPs `var_dump()` or `print_r()` function.
+ * Provides syntax-highlighted insight into nested objects, arrays, etc.
+ *
+ * @param mixed $value The variable to print out
+ * @param bool $return Return the resulting HTML insted of sending it with echo()
+ * @param bool $dontDie If set to `TRUE` the script will not be aborted. This parameter has no effect if `$return` is set to `TRUE`
+ * @return void|string If `$return` is set to `TRUE` the resulting HTML is returned as string
+ *
+ * ```
+ * //Example usage:
+ * $something = ['cars' => ['audi','bmw'], 'nothing' => (object)['name' => 'Mario', 'age' => 34]];
+ * xout($something);
+ * ```
+ */
+ public static function xout($value, $return = false, $dontDie = false)
+ {
+ self::$res = sprintf('', self::FONT_FAMILY, self::FONT_SIZE, self::BASE_COLOR, self::FONT_WEIGHT);
+ self::_xout($value, true);
+ self::$res .= '
';
+
+ if($return)
+ {
+ return self::$res;
+ }
+
+ echo self::$res;
+
+ if($dontDie == false)
+ {
+ die;
+ }
+ }
+
+ private static function _xout($value)
+ {
+ /** @var string Value Type */
+ $t = self::get_type($value);
+ /** @var string Value Class Name */
+ $cn = $t === 'object' ? self::get_classname($value) : '';
+ //We define closure as a separate type, i think its ok, after all it IS a function
+ $t = $cn === 'Closure' ? 'closure' : $t;
+ /** @var bool Value is Simple/Scalar Type */
+ $s = !($t === 'array' || $t === 'object');
+ /** @var bool Value is an empty object or array */
+ $eo = !$s && self::is_e($value);
+
+
+ self::pre($t,$eo,$cn);
+
+ $value = $s ? [$value] : $value;
+ foreach($value as $key => $val)
+ {
+ $t2 = self::get_type($val);
+ switch($t2)
+ {
+ case 'array' : self::main($t, $t2, $key, $val, ''); break;
+ case 'object' : self::main($t, $t2, $key, $val, ''); break;
+ case 'closure' : self::main($t, $t2, $key, sprintf('