Like you, I have many little functions that are useful for debugging in a

The problem is that when you start to pepper them around, whilst debugging,
you can often times forget where you left them. A search isn't always
helpful since I sometimes leave them in the code, but commented out, so I
end up finding dozens of matches.

What I need are some variables that tell me the current calling file, line
and function I'm in. Then when I see some debug info on the screen, I know
exactly where it came from. are for the
most part useless for this task, as they tell you information about the
file, line and function name itself. This is a subtle but significant

Say I have a typical setup: -- has all my helper routines and fancy debug functions. -- the functions for mywebpage as I follow MVC logic.
mywebpage.php -- the page I'm trying to work on and debug.

If I place a print_x($foo) in somewhere, lets say in a
function insert_into_database() on line 69, I would expect that __FILE__,
__LINE__ and __FUNCTION__ to reflect all of that. It should return with
"", "69" and "insert_into_database" respectively.

What in fact happens is that I get "", "642", "print_x". If I
use $_SERVER['PHP_SELF'] instead of __FILE__ then I get "mywebpage.php"
(not "" as desired)

Now, the __FILE__, __LINE__ and __FUNCTION__ have their merit in some
cases, but I think there needs to be another set of magic variables that
are more dynamic and work as I suggest. Perhaps a __CFILE__, __CLINE__ and
__CFUNCTION__  with the "C" prefix for "Current" or "Calling"

* Print out a pretty, portlet, styled version of an array
* @param        array   $array  Array to print out
* @param        boolean $var_dump use either print_r (false/default) or
* @param        string $string if set, this will print out in the title of
the debug portlet
function print_x($array, $var_dump=false, $string='')
        if (!is_array($array))
                echo '<b>'.$_SERVER['PHP_SELF'].'::'.__FUNCTION__."(Not An
Array) $string</b><br/>\n";
<div class="debug">
        <div class="header"><h2><?= $_SERVER['PHP_SELF'].'::'.__FUNCTION__
?>()<?= $string ?></h2></div>
        <div class="content">
            print "<div class=\"debug\"><pre style=\"padding: 0; margin:

                if ($var_dump)
                        foreach($array as $k => $v)
                                if (is_bool($v))
                                        $array[$k] = ($v === true) ?
                                elseif (is_object($v))
                                        $array[$k] =

                        print_r( $array );

                print "</pre>\n</div>\n";

function debug_print($var, $name='MY_VARIABLE')
        if (is_array($var))
                print_x($var, false, $name);

        echo '<span class="debug">'.__FILE__.'@'.__LINE__.'<b>'.$name.'</b>
= '.$var."</span><br/>\n";

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to