PhpStorm debugging is indispensable
I was given a problem: the (somewhat usual) error message showed up Warning: Invalid argument supplied for foreach() in element_children() (line 6396 of common.inc).
. Trying to debug it with the usual print-and-see is entirely and totally hopeless. If you print just $elements
from element_children
? You get picture
. If you try to print the backtrace? It's impossibly big. One hope is printing the backtrace with DEBUG_BACKTRACE_IGNORE_ARGS
and then manually opening up every step in the rather big backtrace. Or you can set a conditional breakpoint on the problematic line with !is_array($elements)
as a condition and immediately have access to the backtrace in a very nice structured/collapsed format where you can see the parent, grandparent etc render arrays, reach every caller with one click and eventually find this in a template:
<span style="color: #000000"><span style="color: #0000BB"><?php </span><span style="color: #007700">foreach (</span><span style="color: #0000BB">$content </span><span style="color: #007700">as </span><span style="color: #0000BB">$key </span><span style="color: #007700">=> </span><span style="color: #0000BB">$item</span><span style="color: #007700">): </span><span style="color: #0000BB">?></span></span><br> <span style="color: #000000"><span style="color: #0000BB"><?php </span><span style="color: #007700">print </span><span style="color: #0000BB">render</span><span style="color: #007700">(</span><span style="color: #0000BB">$item</span><span style="color: #007700">); </span><span style="color: #0000BB">?></span></span>
I have worked for years without a debugger -- finding this without is really frustrating and slow. Finding it with one is a matter of minutes. And PhpStorm debugger is literally zero config.