Someone said this in #drupal today. I long wanted to blog about this. I never use print_r. There is no need for it, var_export is far superior IMO -- if I need to write a quick script which actually does something on the data, I can copypaste the output into PHP code. Little but annoying things like escaping apostrophes are handled too, so it's even useful for dumping strings. Of course, var_dump is also useful as that dumps type info -- how cool it would be if it would do that in a PHP comment and then it would also render valid PHP code as debug output.
Commenting on this Story is closed.
Agree totally,
I use var_export with TRUE as the second paramenter so the output can be redirected to drupal message function:
drupal_set_message('< pre >'. var_export(array_to_dump,TRUE) .'< /pre >');
You can define this as a macro in your favorite editor to quick & dirty debug arrays or variables.
Someone said this in #drupal today. I long wanted to blog about this. I never use print_r. There is no need for it, var_export is far superior IMO -- if I need to write a quick script which actually does something on the data, I can copypaste the output into PHP code. Little but annoying things like escaping apostrophes are handled too, so it's even useful for dumping strings. Of course, var_dump is also useful as that dumps type info -- how cool it would be if it would do that in a PHP comment and then it would also render valid PHP code as debug output.