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: Adam <anon@nowhere.com>
Date: Tue Oct 04 2005 - 12:56:42 CEST

On 3 Oct 2005 22:32:04 -0700, Chung Leong wrote:

>See the following thread:
>http://groups.google.com/group/comp.lang.php/browse_frm/thread/5055003f44ae6ee4/35697d72cf31b316

Chung - thank you for that! I had to do the array_shift tweak as I
tend to use include files.

For the benefit of readers here, I've pasted your code (with my tweak
and thanks):

function bobo_the_clown($b) {
 $bt = debug_backtrace();
 extract(array_shift($bt));
 $lines = file($file);
 $code = implode('', array_slice($lines, $line - 1));
 preg_match('/\bbobo_the_clown\s*\(\s*(\S*?)\s*\)/i', $code,
$matches);
 return @$matches[1] . " : " . $b;
}

$a = "Hello";
echo bobo_the_clown($a);

Now, if only I could understand how it works .. LOL. Still so much to
learn!

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