Thursday, September 10th, 2009
Formaldehyde: PHP debug info for the client side
<>p>
Andrea Giammarchi has released Formaldehyde, a new Ajax and PHP error debugger.
Simply grab the project and throw in an inclusion:
- < ?php require_once 'formaldehyde.php'; ?>
You are off to the races.
Want to do a touch more?
- // *optional* custom ServerError constructor
- function ServerError(e){
- for(var key in e)
- this[key] = e[key]
- ;
- };
- // make Firebug the best friend ever
- (ServerError.prototype = new Error).name = "ServerError";
- // same call
- var xhr = new XMLHttpRequest;
- xhr.open("get", "test.php", true);
- xhr.onreadystatechange = function(){
- if(xhr.readyState === 4){
- if(199 < xhr.status && xhr.status < 400){
- // do something without failures
- eval(xhr.responseText);
- }
- // if Formaldehyde managed the call
- else if(xhr.status === 500 && xhr.getResponseHeader("X-Formaldehyde") != null) {
- // evaluate safely the response
- // generating a proper error
- console.log(new ServerError(eval("(" + xhr.responseText + ")")));
- } else {
- // 404 or other cases
- console.log(new Error(xhr.responseText));
- }
- }
- };
- xhr.send(null);
We have known about the great FirePHP for quite some time, but this is different as explained. Check it out!
Related Content:











Thanks Dion, just as extra note: this evening I am planning to create a cross-browser JavaScript file to include if necessary in order to make responses management automatic and possibly compatible with every library as well without changing a single piece of code ( it’s a XMLHttpRequest / ActiveXObject wrapper )
That should make this little project complete so please stay tuned
Ok, I’m impressed.
As promised, Formaldehyde JS cross-browser, same logic (include as first file in the page that will perform Ajax calls, and that’s it, do not require any change in your existent JS code)
http://code.google.com/p/formaldehyde/
I am writing down some documentation about.
Regards