clive wrote:
Thanks Vincent,Stut and Olaf. Thats __file___ is exactly what I needed :)
now for another brain teaser for your collective brains, How does a
function know what file it was called from.
a.php includes functions.php
in a.php we call function test(); which is declared in functions.php
Is there anyway for test(); to echo "called from a.php" with out
passing 'a.php' or ___FILE___ as a parameter to the function?
Im busy googling now for a answer.
Note that the following function has not been extensively tested, and
should be treated as such. I wrote this function a long time ago to get
the calling function from a common error routine. You should be able to
modify this to get what you want...
function GetCaller($offset = 0)
{
$trace = debug_backtrace();
$retval = '';
if (is_array($trace))
{
foreach ($trace as $call)
{
if ($offset > 0)
{
$offset--;
}
else
{
if (strlen($retval) == 0)
{
$retval = str_replace($GLOBALS['rootdir'], '',
$call['file']).':'.$call['line'].' ';
}
elseif (isset($call['function']))
{
return $retval.(isset($call['class'])
?
$call['class'].'::'
:
'').$call['function'];
}
}
}
}
if (strlen($retval) == 0)
return 'unknown';
return $retval.'unknown function';
}
Hope it helps.
-Stut
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php