Re: 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

Re: Get name of passed variable in a function

From: Andy Hassall <andy@andyh.co.uk>
Date: Mon Oct 03 2005 - 23:02:25 CEST

On Mon, 03 Oct 2005 22:29:48 +0200, Ewoud Dronkert
<firstname@lastname.net.invalid> wrote:

>Andy Hassall wrote:
>> In short, no.
>
>Yes, http://php.net/debug-backtrace

 No,

<pre>
<?php
function debug($var) {
    print_r(debug_backtrace());
}

$foo = 10;
debug($foo);

?>
</pre>

 Output:

Array
(
    [0] => Array
        (
            [file] => /home/andyh/public_html/test.php
            [line] => 8
            [function] => debug
            [args] => Array
                (
                    [0] => 10
                )

        )

)

 If you can find "foo" in the above then it would do what the OP requested:

>>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?

-- 
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Received on Tue Oct 18 02:31:04 2005