Re: include_once() isnt!
| From: | Eric Bolikowski | Date: | Sat, 07 Feb 2004 13:46:03 +0000 |
| Subject: | Re: include_once() isnt! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-177091@lists.php.net to get a copy of this message | ||
"Rob" <midnightstudent@shaw.ca> wrote in message
news:20040203220433.95299.qmail@pb1.pair.com...
> Ive programmed with C/C++ for years and have recently started to dabble in
> PHP. Ive written a multi-part script for a friend and Ive run into a
> problem.
>
> Ive got 14 include files 3 of which are basic components that may or may
not
> be used by other components. One is an authorisation class, another is a
> Dbase clas (For MySQL) and another is a file system component.
>
> Now heres the problem. My authorisation component uses the DBase
component.
> Some of my other components use the DBase component only some of the time
> and the Auth and DBase components some of the time and the Auth component
> some of the time. SO... In the Auth component ive included (via
> include_once()) the DB component, because it needs it. NOW... in other
> modules Ive included (via include_once()) the auth, DB, and gallery
> components.
> Heres where the problem lies. Each component is in a separate file, and
when
> I run the script, I get an arror saying I cant re-define the classes.
> Which makes me believe that the include_once() function is trying to
include
> the other components even though they are already included. So, does that
> mean that include_once() only works right when it is used in the same
file?
> It wont recognise that an include was already included in another include?
> Have I confused you yet? I am.
There may be a problem with include_once, something about where it's placed
and so on...
But anyway I would advise you to not generally rely on include_once() or
require_once().
These are just meant to protect you from making an error, but you should
check to see that you don't use include_once() on the same file many times.
It's bad practice to include one file several times.
One tip i would give you, is to set up one file, something like
"define_classes.inc.php", which is responsable for including the classes and
defining them.
In this way you can just include define_classes.inc.php in the scripts where
you need classes, and your work will be a lot more structured.
I personally use this system on my web-site, and it does that i don't have
to be worried about if I am getting the correct classes, because I get them
all through define_classes.inc.php
Eric