What mechanism may be used in PHP that will act as #define and
am 30.03.2008 01:14:22 von af300wsm
The question is I have a base class in file1 and files file2 and file3
both contain classes that derive from the base class in file1. I'm
running in to a redefinition problem when I'm loading the files. What
I'd like is something like this:
file1:
// defining stuff
?>
file2:
require("path/to/file1");
// doing important stuff
?>
file3:
require("path/to/file1");
//doing important stuff
?>
Then in the "main" files I have:
main:
require("path/to/file2");
require("path/to/file3");
// do important stuff
?>
Now, I'm getting the redefinition problem here. In C or C++, I'd do:
#ifndef SOMETHING
#define SOMETHING
// code here
#endif
Is there something that would do this php? I haven't actually tried
wrapping the base class definition in a conditional because I thought
I remember reading that PHP uses the same scope rules as C and C++.
If I define something inside the scope of a conditional, that
something goes out of existence when that scope moves out. Is this
true, or would a conditional be the answer?
Thanks,
Andy
Re: What mechanism may be used in PHP that will act as #define and
am 30.03.2008 01:29:53 von petersprc
Hi,
Use require_once instead of require to ensure the include is evaluated
only once per interpreter.
Regards,
John Peters
On Mar 29, 8:14 pm, Andrew Falanga wrote:
> The question is I have a base class in file1 and files file2 and file3
> both contain classes that derive from the base class in file1. I'm
> running in to a redefinition problem when I'm loading the files. What
> I'd like is something like this:
>
> file1:
>
> // defining stuff
> ?>
>
> file2:
>
> require("path/to/file1");
>
> // doing important stuff
> ?>
>
> file3:
>
> require("path/to/file1");
> //doing important stuff
> ?>
>
> Then in the "main" files I have:
> main:
>
> require("path/to/file2");
> require("path/to/file3");
> // do important stuff
> ?>
>
> Now, I'm getting the redefinition problem here. In C or C++, I'd do:
>
> #ifndef SOMETHING
> #define SOMETHING
> // code here
> #endif
>
> Is there something that would do this php? I haven't actually tried
> wrapping the base class definition in a conditional because I thought
> I remember reading that PHP uses the same scope rules as C and C++.
> If I define something inside the scope of a conditional, that
> something goes out of existence when that scope moves out. Is this
> true, or would a conditional be the answer?
>
> Thanks,
> Andy
Re: What mechanism may be used in PHP that will act as #define and
am 30.03.2008 04:26:23 von af300wsm
On Mar 29, 6:29 pm, petersprc wrote:
> Hi,
>
> Use require_once instead of require to ensure the include is evaluated
> only once per interpreter.
>
> Regards,
>
> John Peters
>
Thanks, I figured it was simple but I'm not yet a php guru.
Andy