Re: Is there a way to un include a file

From: Date: Fri, 09 Mar 2007 00:34:50 +0000
Subject: Re: Is there a way to un include a file
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-250142@lists.php.net to get a copy of this message
jekillen wrote:
On Mar 7, 2007, at 11:47 PM, Larry Garfield wrote:
No there is not, because an included file *executes* at the time it is included and is then done. Any memory-resident objects (function/class definitions, variables, etc.) that it defies then exist until you make them un-exist (with unset() for variables or, well, you can't with functions and classes AFAIK). Include files are libraries. They are not functions. What you're looking for is a function. Don't try to use include files as functions. Therein lies pain.
I have function definitions in included files all over the place. I do that so one file will not be too big to keep scrolling back and forth through to develop and debug. These are mainly in conjunction with multi phase self processing forms. Variables I could guess would be overwritten, but if I have a function fu defined in two different files that are include in, say, a loop and I want to call one function fu on one iteration from one included file, then the next iteration I include the next file and call fu that is a different version, which function would be executed on the second iteration?
You can't have two functions with the same name for exactly this reason. $ php -a Interactive mode enabled <?php function a() { echo "1\n"; } function a() { echo "2\n"; } [ CTRL-D ] Fatal error: Cannot redeclare a() (previously declared in -:2) in - on line 3 So when script '2' is included (ie the 2nd loop), it's going to throw this sort of error. Time to rethink your design. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#250142) next »