Code Revisions: Week 5

Week 5. Two days late.. I wasn’t happy with what I got on Tuesday and did not want to post yesterday because of other internship posts. Well, I’m still not happy with my progress on syntax checking. Maybe I can get some constructive feedback on this: When I initially proposed this project the idea of preventing faulty code of being saved came up. It is easy to break an installation with some bad changes to a php file of an active theme or plugin. Obviously, a broken installation is a bad user experience.

The problem I ran into when investigating this is that it is not that easy to check php syntax from within php. There was a function in php core itself which got removed some versions ago. The current implementation of this in version 0.5 of my plugin uses eval – I know eval is evil, but it doesn’t matter because you can do what ever evil you want to when you’ve got access to the editors:

var_dump(eval("return true; if(0){?>{$code}?><?php };"));
$error = error_get_last();

This still does not catch all errors, but it at least gives me the ability to notify about  unbalanced brackets and missing quotes. The problem here is that some shared hosts might have it disabled by default.. Any thoughts on alternatives?

Next week is evaluation time and I will be doing some testing on different installs. Because this functionality for the moment is intended to only work with WordPress 3.6 this shouldn’t bring up to many problems. Happy WordCamp everyone in SF!

#code-revisions, #weekly-update