During PHP development I like to echo out the values of variables/functions to make sure they're what I expect or to find out what's in them. PHP's print_r() function works fine mostly but I decided I wanted the output formatted clearer and each variable type shown as well as the value. A big problem too is that if there's any HTML in the value you pass to print_r() then it gets printed to the page without being escaped so you get in a right mess.
I decided to write my own function which tells you everything you could possibly want to know about whatever you throw at it. Usage is stupidly easy:
will print out whatever is in $variable. If it's a string or a number it'll just tell you what it is and its value. If it's an array or an object it'll iteratively loop over it and output each element or property (handling an infinite depth of multidimensional arrays), telling you the type and value of each element as it goes. Example:
prints out:
Something more complicated like this:
prints out:
The function takes two optional parameters. The second parameter ($name) can be used to override the displayed name which preceeds the output. The third parameter ($echo) can be set to false to just return the value and not echo it.
So this function can be used in any of my PHP files, I've got it inside a file called _auto_prepend.php and this file gets automatically prepended to every PHP file with the auto_prepend PHP directive. On my local XAMPP installation I've got an .htaccess file in my DocumentRoot folder to do it. On my remote web server I've had to change the value in my php.ini file as it wouldn't let me override the auto_prepend value using .htaccess. See the downloads section an example .htaccess. If it doesn't work then the php.ini version is there too.
Ohloh computes statistics on FOSS projects by examining source code and commit history in source code management systems. This project has code locations but that location contains no recognizable source code for Ohloh to analyze.
Copyright
©
2013
Black Duck Software, Inc.
and its contributors, Some Rights Reserved. Unless otherwise marked, this work is licensed under a
Creative Commons Attribution 3.0 Unported License
. Ohloh
®
and the Ohloh logo are trademarks of
Black Duck Software, Inc.
in the United States and/or other jurisdictions. All other trademarks are the property of their respective holders.