Re: include file identifier

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux