This is a discussion on Check if a file has been included before? within the PHP Language forums, part of the PHP Programming Forums category; Hello, I want my scripts to be warning and error free. Is it possible to check is a file has ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello,
I want my scripts to be warning and error free. Is it possible to check is a file has already been included as part of a "require", "require_once" or "include" call in the script? I guess I could just include everything and turn warnings/errors off, but I'd prefer not to do that. Much thanks - |
|
|||
|
if you use requre or include _once() then they should never be included
again. I do not know if there is a way to check, but years ago, in C i would write a constant in the include file and check if it was defined in the include if not, would include itself, then define. -- Mike Bradley http://www.gzentools.com -- free online php tools "D. Alvarado" <laredotornado@zipmail.com> wrote in message news:9fe1f2ad.0403061949.1d74ebb6@posting.google.c om... > Hello, > I want my scripts to be warning and error free. Is it possible to > check is a file has already been included as part of a "require", > "require_once" or "include" call in the script? I guess I could just > include everything and turn warnings/errors off, but I'd prefer not to > do that. Much thanks - > |
|
|||
|
> if you use requre or include _once() then they should never be included > again. > > I do not know if there is a way to check, but years ago, in C i would write > a constant in the include file and check if it was defined in the include if > not, would include itself, then define. > What about if( !defined('INCLUDE_THEFILE')) { include( 'somefile.php' ); }else{ echo 'Already included' } .... .... // in somefile.php defined('INCLUDE_THEFILE') Might not be the best way...i didn't know that including a file more than once could be a prob. Sims |
|
|||
|
On 2004-03-07, D. Alvarado wrote:
> Hello, > I want my scripts to be warning and error free. Is it possible to > check is a file has already been included as part of a "require", > "require_once" or "include" call in the script? I guess I could just > include everything and turn warnings/errors off, but I'd prefer not to > do that. Much thanks - How about: get_included_files () or get_required_files () They both return an array containing all included and required files. They both do the same thing by the way (one is an alias of the other). See: http://www.php.net/get_included_files -- Mike Peters mike [-AT-] ice2o [-DOT-] com http://www.ice2o.com |
|
|||
|
"Sims" <siminfrance@hotmail.com> wrote in message
news:c2f05b$1rr9hh$1@ID-162430.news.uni-berlin.de... > > > if you use requre or include _once() then they should never be included > > again. > > > > I do not know if there is a way to check, but years ago, in C i would > write > > a constant in the include file and check if it was defined in the include > if > > not, would include itself, then define. > > > > What about > > if( !defined('INCLUDE_THEFILE')) > { > include( 'somefile.php' ); > }else{ > echo 'Already included' > } > ... > ... > // in somefile.php > defined('INCLUDE_THEFILE') > > Might not be the best way...i didn't know that including a file more than > once could be a prob. > > Sims Yea thats it, then I started thinking, they should just use require/include ...._once(); then it hit me, instead of going through all the code, and writing snippets to see if it was already include, just change all includes to .._once(). OK, as I write this, I just got an idea, perhaps a small file that shows something cool is included at several places, and they dont want to over do it, so they need to check if it is included. -- Mike Bradley http://www.gzentools.com -- free online php tools |
|
|||
|
On 2004-03-07, CountScubula <me@scantek.hotmail.com> wrote:
> if you use requre or include _once() then they should never be included > again. > > I do not know if there is a way to check, but years ago, in C i would write > a constant in the include file and check if it was defined in the include if > not, would include itself, then define. I presume it was like #ifndef FOO_H #define FOO_H .... #endif -- http://home.mysth.be/~timvw |