The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

PhpStorm debugging is indispensable

Submitted by nk on Fri, 2014-09-05 16:48

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:

<?php foreach ($content as $key => $item): ?>
  <?php print render($item); ?>

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.

Commenting on this Story is closed.

Submitted by Anonymous on Mon, 2014-09-08 07:09.

Totally agree.

Submitted by Anonymous on Mon, 2014-09-08 10:04.

It can also help to install the devel module, go to admin/config/development/devel, and set "Error handlers" to "Krumo backtrace in the message area".

To test this you can install devel, go to devel/php, type in "element_children($a = 'test');", and see the result with the standard error handler and the "Krumo backtrace in the message area" handler.

Cheers,

Albert.

Submitted by Anonymous on Mon, 2014-09-08 14:53.

Devel is not a step debugger. It is really not that effective at all.

Submitted by Anonymous on Mon, 2014-09-08 14:54.

Respectfully, I think this is the type of Drupal-ism we should be avoiding. Debuggers are something that every professional PHP developer should be familiar with, having to understand some tribal knowledge about the Devel module is infuriating to people who are new to Drupal. Furthermore, debuggers allow you to debug in context of runtime, where the technique mentioned above might work for this specific situation but is devoid of any context that could point to the root of the problem.

Just my $0.02,
cpliakas

Submitted by Anonymous on Mon, 2014-09-08 21:09.

I had a similar problem last month and PHPStorm did the debug so easily... You are right.