Re: function needed in different source files

From: Date: Sun, 16 Jul 2000 08:53:48 +0000
Subject: Re: function needed in different source files
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-6807@lists.php.net to get a copy of this message
This works, but I like my included files to be self contained....so I do the following global $FILENAME_INCLUDED; if($FILENAME_INCLUDED == "File has been included") // nice and big to avoid confusion { // All the include file $FILENAME_INCLUDE = "File has been included"; } // end if Brandt ----- Original Message ----- From: Matt McClanahan <cardinal@dodds.net> To: Harald Houppermans <HBTHouppermans@zonnet.nl> Cc: <php-general@lists.php.net> Sent: Saturday, July 15, 2000 11:57 PM Subject: Re: [PHP] function needed in different source files > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#6807) next »