|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xmf; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Debugging tools for developers |
|
16
|
|
|
* |
|
17
|
|
|
* @category Xmf\Debug |
|
18
|
|
|
* @package Xmf |
|
19
|
|
|
* @author trabis <[email protected]> |
|
20
|
|
|
* @author Richard Griffith <[email protected]> |
|
21
|
|
|
* @copyright 2011-2016 XOOPS Project (http://xoops.org) |
|
22
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
23
|
|
|
* @link http://xoops.org |
|
24
|
|
|
*/ |
|
25
|
|
|
class Debug extends \Kint |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* doOnce - do some local housekeeping on first use. Any method needing this |
|
29
|
|
|
* assist just calls every time, the one time logic is all here. |
|
30
|
|
|
* |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
|
|
private static function doOnce() |
|
34
|
|
|
{ |
|
35
|
|
|
static $done; |
|
36
|
|
|
if (true !== $done) { |
|
37
|
|
|
$done = true; |
|
38
|
|
|
$class = get_called_class(); |
|
39
|
|
|
parent::$aliases[] = [$class, 'dump']; |
|
40
|
|
|
parent::$aliases[] = [$class, 'backtrace']; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Dump one or more variables |
|
46
|
|
|
* |
|
47
|
|
|
* @param mixed $data variable(s) to dump |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
public static function dump($data = null) |
|
52
|
|
|
{ |
|
53
|
|
|
$args = func_get_args(); |
|
54
|
|
|
|
|
55
|
|
|
static::doOnce(); |
|
|
|
|
|
|
56
|
|
|
\Kint_Renderer_Rich::$theme = 'aante-light.css'; // options: 'original' (default), 'solarized', 'solarized-dark' and 'aante-light' |
|
57
|
|
|
forward_static_call_array(array('parent', 'dump'), $args); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Display debug backtrace |
|
62
|
|
|
* |
|
63
|
|
|
* @return void |
|
64
|
|
|
*/ |
|
65
|
|
|
public static function backtrace() |
|
66
|
|
|
{ |
|
67
|
|
|
static::dump(debug_backtrace()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* start_trace - turn on xdebug trace |
|
72
|
|
|
* |
|
73
|
|
|
* Requires xdebug extension |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $tracefile file name for trace file |
|
76
|
|
|
* @param string $collect_params argument for ini_set('xdebug.collect_params',?) |
|
77
|
|
|
* Controls display of parameters in trace output |
|
78
|
|
|
* @param string $collect_return argument for ini_set('xdebug.collect_return',?) |
|
79
|
|
|
* Controls display of function return value in trace |
|
80
|
|
|
* |
|
81
|
|
|
* @return void |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function startTrace($tracefile = '', $collect_params = '3', $collect_return = 'On') |
|
84
|
|
|
{ |
|
85
|
|
|
if (function_exists('xdebug_start_trace')) { |
|
86
|
|
|
ini_set('xdebug.collect_params', $collect_params); |
|
87
|
|
|
ini_set('xdebug.collect_return', $collect_return); |
|
88
|
|
|
if ($tracefile == '') { |
|
89
|
|
|
$tracefile = XOOPS_VAR_PATH . '/logs/php_trace'; |
|
90
|
|
|
} |
|
91
|
|
|
xdebug_start_trace($tracefile); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* stop_trace - turn off xdebug trace |
|
97
|
|
|
* |
|
98
|
|
|
* Requires xdebug extension |
|
99
|
|
|
* |
|
100
|
|
|
* @return void |
|
101
|
|
|
*/ |
|
102
|
|
|
public static function stopTrace() |
|
103
|
|
|
{ |
|
104
|
|
|
if (function_exists('xdebug_stop_trace')) { |
|
105
|
|
|
xdebug_stop_trace(); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClassto useselfinstead: