Page 1 of 1

Calling function with the "include file name"

Posted: Wed Dec 03, 2003 8:37 am
by markbeadle
Hello Alll,

I seem to remember having read somewhere that there is a facility for calling a function with additional information beforehand which shows which include file the function is held in.

Example:
file xyz.php holds function getHello();

Main file
<?php
include("xyz");

echo(<method>getHello());
?>

Has anyone come across this ? Are they able replace the <method> text ?

I realise the other method could be echo(getHello()); // function in xyz.php

Thanks
Mark

Posted: Wed Dec 03, 2003 12:30 pm
by vigge89
First of all, you have some bad things in your code;

Code: Select all

<?php

include("xyz.php"); //You forgot the .php extension

echo "<method>getHello()"; //you forgot " and "

?>
if you want to replace <method> by getHello(), use str_replace
look at the PHP manual under strings for it

Posted: Wed Dec 03, 2003 5:16 pm
by McGruff
__FILE__ and __LINE__ might be what you are looking for.

Note that you can't build a single use-anywhere function to wrap that up: they'll always return the custom function location and not the location where you execute the fn.

I use this quite a lot for debugging. First I build a $location var with the above two constants, and then pass it in to a $monitor logging object. Very useful if your scripts are composed of multiple files.

Posted: Thu Dec 04, 2003 2:56 am
by markbeadle
McGruff wrote:__FILE__ and __LINE__ might be what you are looking for.
Thanks McGruff. Very useful to know.