Updates from March, 2008

  • Simple PHP debugging

    Andi 02:46 on March 6, 2008 | 0 Permalink | Reply

    If you debug your PHP code, you often get too many messages if you just use echo and print_r() or var_dump(). In the last few weeks I have implemented some useful techniques to prevent bunches of debugging messages on my screen:

    1. If you debug a template and you want to see the true result without any messages – but you don’t want to remove them or comment them out, you define a constant that tells your script whether it’s going to debug or not and you define your own function for debugging. This function checks if your constant is true and then prints your message.
    2. You can make it more comfortable and make your debug function accept any number of arguments of of different types. They will be conactenated and printed out in a meaningful way. So a false won’t be a blank string, an array is printed via print_r() or var_dump()
    3. Arrange your messages neatly by printing them in the end of your script – or use the killer feature: Send them to your Firebug console. Now your page is clean and you use full featuritis of Firebug, that will show your objects and recursive structures in a much more developer friendly way ;) When you test your site in other browsers, you can change output mode to HTML – your messages are collected in a box, and that’s it.

    E.g.:

    define('debug', 1);
    define('debugMode', 'js'); // 'html' or 'js'
    ...
    function myMethod($arg1, $arg2) {
      $_ = func_get_args();
      debug(__method__, $_);
    
      ... code ...
    
      debug("\twhat I wanna say", array('that' => 'sucks'));
    }
    
    // print all messages at once
    debugChain();

    I don’t want you to do all the work again: Download the package rename file extension to “.php” and use it: debugPackage0.1._php

     
  • Google feiert Lego

    Andi 13:40 on January 28, 2008 | 0 Permalink | Reply

    (German) Google zeigt heute, dass Lego Geburtstag hat – mit einem Google Doodle:

     
  • Sarkasmshirt - neue Shirts

    Andi 08:00 on December 26, 2007 | 0 Permalink | Reply

    (German) Es gibt neue Sarkasmshirts – surft mal rein:

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
esc
cancel