Wednesday, 16 September 2009

Formaldehyde: PHP debug info for the client side

Formaldehyde: PHP debug info for the client side: "


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


Simply grab the project and throw in an inclusion:



PHP:







  1. <?php require_once 'formaldehyde.php'; ?>









You are off to the races.


Want to do a touch more?



JAVASCRIPT:







  1. // *optional* custom ServerError constructor



  2. function ServerError(e){



  3. for(var key in e)



  4. this[key] = e[key]



  5. ;



  6. };



  7. // make Firebug the best friend ever



  8. (ServerError.prototype = new Error).name = 'ServerError';






  9. // same call



  10. var xhr = new XMLHttpRequest;



  11. xhr.open('get', 'test.php', true);



  12. xhr.onreadystatechange = function(){



  13. if(xhr.readyState === 4){



  14. if(199 <xhr.status && xhr.status <400){



  15. // do something without failures



  16. eval(xhr.responseText);



  17. }






  18. // if Formaldehyde managed the call



  19. else if(xhr.status === 500 && xhr.getResponseHeader('X-Formaldehyde') != null) {






  20. // evaluate safely the response



  21. // generating a proper error



  22. console.log(new ServerError(eval('(' + xhr.responseText + ')')));






  23. } else {



  24. // 404 or other cases



  25. console.log(new Error(xhr.responseText));



  26. }



  27. }



  28. };



  29. xhr.send(null);









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




"

No comments:

Sike's shared items