Activate your free membership today | Log-in

Thursday, September 10th, 2009

Formaldehyde: PHP debug info for the client side

Category: Debugging, PHP

Andrea Giammarchi has released Formaldehyde, a new Ajax and PHP error debugger.

Simply grab the project and throw in an inclusion:

PHP:
  1.  
  2. <?php require_once 'formaldehyde.php'; ?>
  3.  

You are off to the races.

Want to do a touch more?

JAVASCRIPT:
  1.  
  2. // *optional* custom ServerError constructor
  3. function ServerError(e){
  4.     for(var key in e)
  5.         this[key] = e[key]
  6.     ;
  7. };
  8. // make Firebug the best friend ever
  9. (ServerError.prototype = new Error).name = "ServerError";
  10.  
  11. // same call
  12. var xhr = new XMLHttpRequest;
  13. xhr.open("get", "test.php", true);
  14. xhr.onreadystatechange = function(){
  15.     if(xhr.readyState === 4){
  16.         if(199 <xhr.status && xhr.status <400){
  17.             // do something without failures
  18.             eval(xhr.responseText);
  19.         }
  20.        
  21.         // if Formaldehyde managed the call
  22.         else if(xhr.status === 500 && xhr.getResponseHeader("X-Formaldehyde") != null) {
  23.        
  24.             // evaluate safely the response
  25.             // generating a proper error
  26.             console.log(new ServerError(eval("(" + xhr.responseText + ")")));
  27.  
  28.         } else {
  29.             // 404 or other cases
  30.             console.log(new Error(xhr.responseText));
  31.         }
  32.     }
  33. };
  34. xhr.send(null);
  35.  

We have known about the great FirePHP for quite some time, but this is different as explained. Check it out!

Posted by Dion Almaer at 6:49 am
4 Comments

++++-
4.6 rating from 17 votes

4 Comments »

Comments feed TrackBack URI

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

Comment by WebReflection — September 10, 2009

Ok, I’m impressed.

Comment by Darkimmortal — September 10, 2009

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

Comment by WebReflection — September 10, 2009

January 1999 Motorola 328cAlthough plus size mother of the bride dressesthe first flip phone in should be sooner, but this clamshell phone is just an integrated microphonemother of bride dresses is not in the usual sense we are now referred to flip.Column Strapless Satin Tulle Wedding Dress Most of the time we are actually referring to folding clamshell handsets, but Motorola’s first cheap prom dressesclamshell phone is the famous “palm-sized” – 328c. The phone is the beginning of in the domestic market and ghetto prom dressescan be received in English and Chinese text, but it does not support sending text messages in Chinese, which is sorry. Column Satin Organdie Lace Wedding DressHowever, clear call quality and handsome appearance are popular at the time this phone place.wedding dress

Comment by wuwei — November 10, 2009

Leave a comment

You must be logged in to post a comment.