Re: include file identifier

From: Date: Sun, 04 Feb 2007 01:58:42 +0000
Subject: Re: include file identifier
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-248264@lists.php.net to get a copy of this message
On Sun, 2007-02-04 at 03:27 +0200, Eli wrote: > Robert Cummings wrote: > > Looking at the code above... it would seem you want: > > > > include_once() > It's not the idea.. > > I'm not trying to make that code work, I want to know which exact > include (of the same file) does what.. > > Say you got a loop of self-include: > e.g: > === a.php > <?php > echo "\nRunning ".__FILE__." (id=X)!\t"; > if ($visited<5) { > echo "You are visiting here!"; > $visited++; > include(__FILE__); > } > else { > echo "That's enough! Bye!"; > } > ?> > > In "(id=X)!".. what's the X? You may say you can use $visited as an > identifier, but it's not the point I mean.. I want a global include file > identifier, that is not dependent on other variables. Make one... <?php if( !isset( $GLOBALS['include_counter'][__FILE__] ) ) { $GLOBALS['include_counter'][__FILE__] = 1; } else { $GLOBALS['include_counter'][__FILE__]++; } echo "\nRunning ".__FILE__." (id=X)!\t"; if( $GLOBALS['include_counter'][__FILE__] < 5 ) { echo "You are visiting here!"; include(__FILE__); } else { echo "That's enough! Bye!"; } ?> The actual counter stuff could be put in a function which could be in an include file you load so that you do the following at the top: <?php include( 'someFunctions.php' ); register_include( __FILE__ ); ?> Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#248264) next »