Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Getting function name from within include

 
   Database Help (Home) -> PHP RSS
Next:  Student scheduling query...  
Author Message
anonymous

External


Since: Feb 20, 2005
Posts: 2



(Msg. 1) Posted: Sun Feb 20, 2005 9:20 am
Post subject: Getting function name from within include
Archived from groups: alt>comp>lang>php (more info?)

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();
?>

 >> Stay informed about: Getting function name from within include 
Back to top
Login to vote
anonymous

External


Since: Feb 20, 2005
Posts: 2



(Msg. 2) Posted: Sun Feb 20, 2005 1:40 pm
Post subject: Re: Getting function name from within include [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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

 >> Stay informed about: Getting function name from within include 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
crontab and the include() function - We recently upgraded php from 4.3.9 to 4.4.7. Everything is working well, except the php scripts running as cronjobs. It appears the problem is that these scripts utilize the include() function and these functions are utilizing relative paths. They..

problem with 'include' and 'file_exists' function - i encountered this problem: "include('inc.php')" will work problely but "include('./inc.php') doesn't work .. both file_exists('inc.php') or file_exists('./inc.php') didn't return the right value.this always show "file doesn't exist...

include within include, using a relatve path - Hi, I have noticed something in PHP's include mechanism that surprised me. If you include a script that itself contains an include command using a relative path, that path is interpreted from the position of the 'outermost' script, not that of the scrip...

error says can't see include file, yet executes some code .. - Hi guys, I need some urgent help here please: I am using an include_once() command to include a file that sits a level above the file view.php. when the code is run, I have an error as follows: Warning: include_once(../common.php)..

include failing to include... - Folks, I have a virtual server with an ISP and I had a web based application available for a customer to try out - it worked fine up until three weeks ago - nothing has changed since then (I am the only one with root password unless the ISP took control....
   Database Help (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]