Re: Is there a way to un include a file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux