Issues (98)

application/Debug.php (1 issue)

1
<?php
2
3
class Debug
4
{
5
    /**
6
     * Export variables omitting array keys that are strictly numeric
7
     *
8
     * By default will output result
9
     *
10
     * @param mixed $data
11
     * @param bool $return
12
     * @param int $level
13
     *
14
     * @return string string representation of variable
15
     */
16
    public static function export($data, bool $return = false, int $level = 0)
17
    {
18
        $result = '';
19
        if (is_array($data)) {
20
            $needKey = array_keys($data) !== range(0, count($data) - 1);
21
            $result .= '[' . PHP_EOL;
22
            foreach ($data as $key => $value) {
23
                $result .= str_repeat(' ', 4 * ($level + 1));
24
                if ($needKey) {
25
                    $result .= self::export($key, true, $level + 1);
26
                    $result .= ' => ';
27
                }
28
29
                $result .= self::export($value, true, $level + 1);
30
                $result .= ',' . PHP_EOL;
31
            }
32
            $result .= str_repeat(' ', 4 * $level) . ']';
33
        } else {
34
            $result .= var_export($data, true);
35
        }
36
37
        if (!$return) {
38
            echo $result;
39
        }
40
41
        return $result;
42
    }
43
}
44
45
function ve($a, bool $return = false)
46
{
47
    return Debug::export($a, $return);
48
}
49
50
function v(): void
51
{
52
    var_dump(func_get_args());
53
}
54
55
function w(): void
56
{
57
    $isHtml = (PHP_SAPI !== 'cli');
58
    echo "\n_________________________________________________________________________________________________________________________" . ($isHtml ? '</br>' : '') . "\n";
59
    var_dump(func_get_args());
60
    echo "\n" . ($isHtml ? '</br>' : '') . '_________________________________________________________________________________________________________________________' . ($isHtml ? '<pre>' : '') . "\n";
61
    debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
62
    echo '' . ($isHtml ? '</pre>' : '') . '_________________________________________________________________________________________________________________________' . ($isHtml ? '</br>' : '') . "\n";
63
    die("script aborted on purpose.\n");
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
64
}
65