Our Thoughts
Pratik Bothra
24 June, 2014 2 MIN READ

Devel Execute PHP Code with Syntax Highlighter

Devel is one of the most powerful modules in Drupal, and it's one of the first modules I end up installing as a developer.

One of the less prominent features of Devel, is the Devel Execute PHP Code, which is available on your site as /devel/php. It provides a text area for entering your PHP code into. Any output (print, print_r, var_dump) is shown in a drupal_set_message.

I often use this interface to experiment with code, run one time scripts, and debug existing functions. Yes, within this block, all drupal functions, and any functions you write on your site can be executed. But it comes with it's fair share of difficulties, and the biggest stumbling block for me, was the lack of a syntax highlighter. There were silly errors you make, which takes forever to debug, and time is always of the essence.

But all this forever changed, when PHP Execute Extended Tools came to my world. This sandbox module is available athttps://drupal.org/sandbox/DizzyC/1905296 and  will change the way you thing about Devel Execute PHP. Quoting from the horse's mouth , PHP Execute Extended Tools is meant to be an extension to Devel's PHP Execute PHP page (/devel/php), and is compatible with Drupal 7.



PHP X Tools adds a History section to the devel execute page as well as a Saved Script section. It keeps a history off all scripts executed on the devel/php page so you can rerun or review them at any time. It also adds the ability to save and load custom scripts so you can keep a collection of scripts that you want to be able to load and rerun at any time. (Can be some testing scripts, i

Optionally it integrates with the 'CodeMirror' library (http://codemirror.net/) transforming the plain textarea into a lightweight code editor supporting syntax highlighting, code formatting, code folding, matching brackets, search and replace and some more. 

To be honest, it's this optional integration which gives it all it's fanciness so it's highly recommended. Instructions to install are clearly mentioned in the sandbox project link, and will only take minutes for you to get started.

Code away, and now the semicolon or apostrophe that you forgot, will no longer come back to bite you in the ass. 

Happy Coding!!!

Pratik Bothra