function _formatBacktraceItem($item) { $trace_string = ''; if (isset($item['class'])) { $trace_string .= $item['class']; $trace_string .= "::"; } if (isset($item['function'])) { $trace_string .= $item['function']; $trace_string .= "("; } if (isset($item['args'])) { $sep = ''; foreach ($item['args'] as $arg) { $trace_string .= $sep; $sep = ', '; $trace_string .= lmb_var_export($arg, LIMB_DUMP_MAX_DEPTH); } } if (isset($item['function'])) { $trace_string .= ")"; } if (isset($item['file'])) { $trace_string .= ' in "' . $item['file'] . '"'; $trace_string .= " line "; $trace_string .= $item['line']; } return $trace_string; }
function toNiceString($without_backtrace = false) { $string = get_class($this) . ': ' . $this->getOriginalMessage() . PHP_EOL; if ($this->params) { $string .= 'Additional params: ' . PHP_EOL . lmb_var_export($this->params) . PHP_EOL; } if (!$without_backtrace) { $string .= 'Backtrace: ' . PHP_EOL . $this->getBacktraceObject()->toString(); } return $string; }
function lmb_var_export($arg, $level = 1) { $prefix = str_repeat(' ', $level > 0 ? $level - 1 : 0); switch (gettype($arg)) { case 'NULL': return 'NULL'; case 'boolean': return $arg ? 'TRUE' : 'FALSE'; case 'integer': return 'INT(' . $arg . ')'; case 'double': return 'FLOAT(' . $arg . ')'; case 'resource': if (is_resource($arg)) { $resource_id = strstr((string) $arg, '#'); $resource_type = get_resource_type($arg); return "RESOURCE({$resource_id}) of type (" . get_resource_type($arg) . ")"; } else { return lmb_var_export((string) $arg); } case 'object': if (LIMB_DUMP_MAX_DEPTH == $level) { return 'OBJECT(' . get_class($arg) . ')'; } $_ENV['LIMB_VAR_EXPORT_SHOWED_OBJECTS'][spl_object_hash($arg)] = true; if ($level == LIMB_DUMP_MAX_DEPTH) { return 'OBJECT(' . get_class($arg) . ")"; } else { $dump = 'OBJECT(' . get_class($arg) . ") {"; if (get_object_vars($arg)) { $dump .= PHP_EOL; foreach (get_object_vars($arg) as $name => $value) { $dump .= $prefix . " [\"{$name}\"]=> " . lmb_var_export($value, $level + 1) . PHP_EOL; } $dump .= $prefix; } $dump .= "}"; return $dump; } case 'array': if ($level == LIMB_DUMP_MAX_DEPTH) { return 'ARRAY(' . sizeof($arg) . ')'; } else { $dump = "ARRAY(" . sizeof($arg) . ') ['; if (sizeof($arg)) { $dump .= PHP_EOL; foreach ($arg as $arr_key => $arr_value) { $dump .= $prefix . " [{$arr_key}] => " . lmb_var_export($arr_value, $level + 1) . PHP_EOL; } $dump .= $prefix; } $dump .= "]"; return $dump; } case 'string': $dump = 'STRING(' . strlen($arg) . ') "'; $dump .= lmb_escape_string((string) $arg, 100); if (strlen($arg) > 100) { $dump .= '...'; } $dump .= '"'; return $dump; default: return var_export($arg, true); } }
/** * Function for quice print variable data without special constructions * @example $obj->callSomeMethod(lmb_var_debug($some_argument)) * @param mixed $arg * @return original arg */ function lmb_var_debug($arg) { echo lmb_var_export($arg); return $arg; }