Re: Retrieving variable name?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Sure.  Use debug_backtrace to figure out what line and what file the
> caller is in, then read that file, find that line, find the function
> call within that line, and read what ever is between the parentheses.

Something like this:

<?php
function myTest($input) {
	$backtrace = debug_backtrace();
	$file = file($backtrace[0]['file']);
	$linenum = $backtrace[0]['line'];
	$function = $backtrace[0]['function'];
	$line = $file[$linenum-1];
	preg_match("/{$function}\((.*)\);/", $line, $matches);
	echo "This function called with '{$matches[1]}'";
}

$a = 5;
myTest($a);

?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux