|
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
|
|
|
* @return string string representation of variable |
|
14
|
|
|
*/ |
|
15
|
|
|
public static function export($data, bool $return = false, int $level = 0) |
|
16
|
|
|
{ |
|
17
|
|
|
$result = ''; |
|
18
|
|
|
if (is_array($data)) { |
|
19
|
|
|
$needKey = array_keys($data) !== range(0, count($data) - 1); |
|
20
|
|
|
$result .= '[' . PHP_EOL; |
|
21
|
|
|
foreach ($data as $key => $value) { |
|
22
|
|
|
$result .= str_repeat(' ', 4 * ($level + 1)); |
|
23
|
|
|
if ($needKey) { |
|
24
|
|
|
$result .= self::export($key, true, $level + 1); |
|
25
|
|
|
$result .= ' => '; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$result .= self::export($value, true, $level + 1); |
|
29
|
|
|
$result .= ',' . PHP_EOL; |
|
30
|
|
|
} |
|
31
|
|
|
$result .= str_repeat(' ', 4 * $level) . ']'; |
|
32
|
|
|
} else { |
|
33
|
|
|
$result .= var_export($data, true); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if (!$return) { |
|
37
|
|
|
echo $result; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return $result; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function ve($a, bool $return = false) |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
return Debug::export($a, $return); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function v() |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
var_dump(func_get_args()); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function w() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$isHtml = (PHP_SAPI !== 'cli'); |
|
57
|
|
|
echo "\n_________________________________________________________________________________________________________________________" . ($isHtml ? '</br>' : '') . "\n"; |
|
58
|
|
|
var_dump(func_get_args()); |
|
|
|
|
|
|
59
|
|
|
echo "\n" . ($isHtml ? '</br>' : '') . '_________________________________________________________________________________________________________________________' . ($isHtml ? '<pre>' : '') . "\n"; |
|
60
|
|
|
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
61
|
|
|
echo '' . ($isHtml ? '</pre>' : '') . '_________________________________________________________________________________________________________________________' . ($isHtml ? '</br>' : '') . "\n"; |
|
62
|
|
|
die("script aborted on purpose.\n"); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.