Re: include file identifier
| From: | Richard Lynch | Date: | Mon, 05 Feb 2007 05:28:11 +0000 |
| Subject: | Re: include file identifier | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248312@lists.php.net to get a copy of this message | ||
On Sat, February 3, 2007 7:05 pm, Eli wrote:
> Does any included file in PHP have a unique identifier? (like a stack
> of
> includes identifier).
Down in the guts of PHP source, there may be some kind of file handler
which is unique...
But nothing I'm aware of exposes this to <?php ?> code in any way,
other than http://php.net/include_once
> If the files names are different, then __FILE__ can be used as an
> identifier. But if a file was included by itself, then __FILE__ is the
> same, tho there are 2 different includes of the same file.
>
> Example:
> === a.php
> <?php
> echo "\nRunning ".__FILE__." (id=X)!\t";
> if (!$visited) {
> echo "You are visiting here!";
> $visited = true;
> include(__FILE__);
> }
> else {
> echo "You have been already visiting here! (Bye)";
> }
> ?>
>
> -thanks, Eli
If you want to avoid the overhead of include_once, it's a pretty
common practice (borrowed from C .h files) to do:
if (!defined('FILENAME')){
define('FILENAME', 1);
//rest of code here
}
It is entirely up to YOU to make sure FILENAME is unique for your
application/project... Which can become problematic when integrating
large packages.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?