Get name of passed variable in a function
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Get name of passed variable in a function

From: Adam <anon@nowhere.com>
Date: Mon Oct 03 2005 - 22:14:21 CEST

I've cobbled a sort of global "debug" routine by using this function:

function debug($str, $strname) {
        global $debugYN;
        if ($debugYN) {
                echo "<br>[Debug (<span
style=\"color:red\">$$strname</span>) : <strong>$str</strong>]<br>";
        }
}

This function gets included (usually in a header) and then called by
setting $debugYN = 1 wherever I want to start viewing variable info -
calling the function with:

debug($foo, "foo");

I'm having to pass two values - the value of the variable AND it's
name. Is there a way of extracting the NAME of the variable ("foo" in
this case) without having to pass it?

Adam.
Received on Tue Oct 18 02:31:03 2005