Re: function needed in different source files
| From: | Matt McClanahan | Date: | Sun, 16 Jul 2000 06:57:39 +0000 |
| Subject: | Re: function needed in different source files | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6802@lists.php.net to get a copy of this message | ||
On Sun, 16 Jul 2000, Harald Houppermans wrote:
> Hi php programmers...
>
> How can I include a script multiple times ?
>
> In c you wold use:
>
> #ifndef TEST
> #define TEST
>
> function something()
> {
>
> }
>
> #endif
>
> I need to use the function something() in different source files.
>
> I am using: require ( test.php3 );
>
> But I get the following error:
>
> Fatal error: Can't redeclare already declared function in
> test.php3 on line 6
>
> Is there something you can do about it ?
You could do essentially the same thing with define().
In test.php3, set a constant,
define('LOADED_TEST_PHP3',1);
and then in the calling script,
if (!LOADED_TEST_PHP3)
include 'test.php3';
Note: Require won't work here because it doesn't work in conditionals.
HTH,
Matt