<?php namespace PHPFUI; class Debug extends \PHPFUI\HTML5Element { public function __construct($variable, string $message = '') { parent::__construct('pre'); $location = ''; if (\strlen($message)) { $message .= ': '; } $bt = \debug_backtrace(); if (isset($bt[0]['file'])) { $location = $bt[0]['file'] . ' ' . $bt[0]['line'] . ': '; } $file = $bt[0]['file']; $file = \substr($file, 0, \strpos($file, '(') ?: \strlen($file)); $src = \file($file); $line = $src[$bt[0]['line'] - 1] ?? ''; \preg_match('#Debug\((.+)\)#', $line, $match); $max = \strlen($match[1] ?? 0); $varname = ''; $c = 0; for ($i = 0; $i < $max; $i++) { if ('(' == ($match[1][$i] ?? '')) { $c++; } elseif (')' == ($match[1][$i] ?? '')) { $c--; } if ($c < 0) { break; } $varname .= ($match[1][$i] ?? ''); } $this->add($location . $message . $varname . '=' . \htmlspecialchars(\print_r($variable, true))); } }