public function __debugInfo() { $data = []; foreach ($this as $k => $v) { if ($k === "buffer") { $data[$k] = bin2hex($v); } elseif (is_string($v) or is_object($v) and method_exists($v, "__toString")) { $data[$k] = Utils::printable((string) $v); } else { $data[$k] = $v; } } return $data; }
function getTrace($start = 1, $trace = null) { if ($trace === null) { if (function_exists("xdebug_get_function_stack")) { $trace = array_reverse(xdebug_get_function_stack()); } else { $e = new \Exception(); $trace = $e->getTrace(); } } $messages = []; $j = 0; for ($i = (int) $start; isset($trace[$i]); ++$i, ++$j) { $params = ""; if (isset($trace[$i]["args"]) or isset($trace[$i]["params"])) { if (isset($trace[$i]["args"])) { $args = $trace[$i]["args"]; } else { $args = $trace[$i]["params"]; } foreach ($args as $name => $value) { $params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . (is_array($value) ? "Array()" : Utils::printable(@strval($value)))) . ", "; } } $messages[] = "#{$j} " . (isset($trace[$i]["file"]) ? cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable(substr($params, 0, -2)) . ")"; } return $messages; }
private function continueDump($from, &$data, &$objects, &$refCounts, $recursion, $maxNesting, $maxStringSize) { if ($maxNesting <= 0) { $data = "(error) NESTING LIMIT REACHED"; return; } --$maxNesting; if (is_object($from)) { if (!isset($objects[$hash = spl_object_hash($from)])) { $objects[$hash] = $from; $refCounts[$hash] = 0; } ++$refCounts[$hash]; $data = "(object) {$hash}@" . get_class($from); } elseif (is_array($from)) { if ($recursion >= 5) { $data = "(error) ARRAY RECURSION LIMIT REACHED"; return; } $data = []; foreach ($from as $key => $value) { $this->continueDump($value, $data[$key], $objects, $refCounts, $recursion + 1, $maxNesting, $maxStringSize); } } elseif (is_string($from)) { $data = "(string) len(" . strlen($from) . ") " . substr(Utils::printable($from), 0, $maxStringSize); } elseif (is_resource($from)) { $data = "(resource) " . print_r($from, true); } else { $data = $from; } }