Home > Archive > PHP Language > February 2005 > Getting function name from within include
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Getting function name from within include
|
|
| anonymous 2005-02-20, 3:55 pm |
|
Is there a way to get the function name of a PHP function from
within an include file included by that function? I know you can
use a global variable to pass the value of __FUNCTION__, but
that defeats the purpose of what I am trying to achieve.
Basicly, what I'm looking for is a PHP function/code that I can
place in my include file *only* that says, "execute __FUNCTION__
within the scope of the calling function and return the results to this
scope". Is there anything like that in Php?
Here's a small example that illustrates what I am trying to achieve:
Include file testinc.php:
<?php
function xxxtestit () {
global $temp;
$temp = "<P>This works!</P>\r\n";
}
$func = 'xxx'.__FUNCTION__;
if (function_exists($func))
$func();
?>
File testit.php:
<?php
function displayit () {
global $temp;
header ("Content-type: text/html");
echo
"<html>\r\n<head>\r\n<title>Testit</title>\r\n</head>\r\n<body>\r\n$temp</body>\r\n</html>";
}
function testit () {
global $temp;
$temp = "<P>This doesn't work because of the scope of
'__FUNCTION__'.</P>\r\n";
include("testinc.php");
displayit();
}
$temp='';
testit();
?>
| |
| anonymous 2005-02-20, 3:55 pm |
| fyi, I solved the problem using get_included_files()...
Include file testinc.php:
<?php
function xxxtestit () {
global $temp;
$temp = "<P>This works!</P>\r\n";
}
foreach (get_included_files() as $filename) {
$func='xxx'.rtrim(basename($filename),'.php');
switch ($func) {
case 'xxxtestit' : xxxtestit(); break;
default: continue;
}
}
?>
|
|
|
|
|