You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[VarDumper from Symfony](https://symfony.com/doc/current/components/var_dumper.html)
9
+
*[Kint - a modern and powerful PHP debugging helper](https://kint-php.github.io/kint/)
10
+
11
+
## Debugging Variable Dumpers
12
+
13
+
This plugin provides two different tools for dumping variables:
14
+
15
+
* VarDumper from Symfony
16
+
* Kint
17
+
18
+
VarDumper provides a simple container that displays where you place it.
19
+
20
+
Kint gathers all the data and displayed it at the bottom of the screen as a fixed position container. It also provides a call stack, which can be handy, and tracing functionality if you need it.
21
+
22
+
### Which one should you use?
23
+
24
+
It depends.
25
+
26
+
1. You want to simply display the contents of a variable: Use VarDumper's functions, i.e. `vdump()`, `vd()`, `vdd()`, or `vddd()`.
27
+
2. You want the call stack in addition to the variable: Use Kint's functions: `d()`, `dd()`, or `ddd()`.
28
+
29
+
### Functions
30
+
31
+
| Task | VarDumper | Kint |
32
+
| :--- | :--- | :--- |
33
+
| Dumps the given variable(s) |`vd( mixed $var );`|`d( mixed $var [ , mixed $var2, ...] );`|
34
+
| Dumps the given variable(s) |`vdump( mixed $var );`|`Kint::dump( mixed $var [ , mixed $var2, ...] );`|
35
+
| Dumps and dies |`vdd( mixed $var );`|`dd( mixed $var [ , mixed $var2, ...] );`|
36
+
| Dumps and dies |`vddd( mixed $var );`|`ddd( mixed $var [ , mixed $var2, ...] );`|
37
+
| Dumps and dies |`vddd( mixed $var );`|`ddd( mixed $var [ , mixed $var2, ...] );`|
38
+
| Dumps plain text | na |`s( mixed $var [ , mixed $var2, ...] );`|
Notice the subtle differences between the three different ways of dumping the title out to the browser:
66
+
67
+
* VarDumper's `vd()` provides a very simple highlighter around the title.
68
+
* Kint's `d()` is shown at the bottom of the screen and contains the function, string length, title, and call stack.
69
+
* Kint's `s()` provides a similar display as `vd()` except that it also includes what was passed into the function (shown in the dashed box), string length, value (title), and where the function was called from in your code.
70
+
71
+
#### How about for arrays, objects, etc?
72
+
73
+
Here's the example code for `vd()`:
74
+
75
+
```php
76
+
add_action( 'loop_start', function() {
77
+
$array = [
78
+
'ID' => get_the_ID(),
79
+
'title' => get_the_title(),
80
+
];
81
+
82
+
vd( $array );
83
+
} );
84
+
```
85
+
86
+
It renders as:
87
+
88
+

89
+
90
+
Here's the example code for `d()`:
91
+
92
+
```php
93
+
add_action( 'loop_start', function() {
94
+
$array = [
95
+
'ID' => get_the_ID(),
96
+
'title' => get_the_title(),
97
+
];
98
+
99
+
d( $array );
100
+
} );
101
+
```
102
+
103
+
It renders as:
104
+
105
+

106
+
107
+
Here's the example code for `s()`:
108
+
109
+
```php
110
+
add_action( 'loop_start', function() {
111
+
$array = [
112
+
'ID' => get_the_ID(),
113
+
'title' => get_the_title(),
114
+
];
115
+
116
+
s( $array );
117
+
} );
118
+
```
119
+
120
+
It renders as:
121
+
122
+

123
+
124
+
## Whoops - An Awesome PHP Error Tool
125
+
126
+
The built-in PHP error container is basic and not as helpful as it could be. On top of that, it's rather ugly. Wouldn't you agree?
127
+
128
+
The Whoops package gives you a cool interface that is helpful, interactive, and quite nice to look at .
129
+
130
+
Consider the error this code would produce:
131
+
132
+
```php
133
+
add_action( 'loop_start', function() {
134
+
does_not_exist();
135
+
} );
136
+
```
137
+
138
+

139
+
140
+
You can learn more about Whoops by visiting [http://filp.github.io/whoops/](http://filp.github.io/whoops/).
0 commit comments