Quick, easy php debugging function

11
Dec

This function was originally developed to help me easily debug PHP. I modified it to play nicely with Drupal by also outputting object data. With Drupal, the function can be placed in any active custom module and then accessed from any module that you are working on.

Simple is always better so, type cast if it's an object or just jump right to the making it pretty. I like to know if the object was converted because most often when I use this, I'm building my output and knowing how to access the information is key.

function pr($data) {
  if (is_array($data)) {
    echo '<pre style="color: #fff;text-align: left">';
        print_r($data);
        echo '</pre>';
  } elseif (is_object($data)) {
          echo 'Converted from object';
          pr((array)$data);
  } else {
    echo $data.'<br>';
  }
}

  • Login or register to post comments

The beginning of progress

03
Dec
To finish a work? To finish a picture? What nonsense! To finish it means to be through with it, to kill it, to rid it of its soul, to give it its final blow the coup de grace for the painter as well as for the picture. -- Pablo Picasso

The work that is my personal web site has finally begun, to the surprise of many no doubt (including myself). While entrenched in work and my wonderful family, making this site live has been on the back burner.

The site has been titled "Progress" because that is what I strive for. If I ever reach a point where I don't think I can get any better or smarter, then I have officially become ignorant. I intend for this site simply to be a repository of information, mainly pertaining to programming and web development but it will certainly be sprinkled with random bits of tid from here and there.

If you need to contact me, please do so by emailing Chris[-at-]chrisrockwell[-dot-]com. Here's to Progress!