[thelist] PHP, functions, include() and precedence
Ken Moore
psm2713 at hotmail.com
Thu Dec 11 16:33:23 CST 2003
Hi all,
Rich Gray wrote:
>
> > Let's say I have a PHP script (script.php) which includes two files
> > (functions.php and newerfunctions.php).
> >
> > If both functions.php and newerfunctions.php have a function called
> > foo(), which foo() will I have when I call it in script.php:
> >
> > * The one called first?
> > * The one called last?
> > * Neither, because PHP will throw an error on the second include?
>
>No 3 is the answer - PHP will throw an error..
>Rich
He is right. It is a scoping error. Imagine a big box, called script.php and
inside are two smaller boxes, called functions.php and newfunctions.php.
Inside of each small box the local foo() will be seen and run. Outside of
them and inside the big box, neither will be seen.
Since I am new to PHP, I do not know if the error happens during parsing -
trying to read the script - or if it hapens at runtime. Regardless, it will
not work. However, it will still work if there is a foo() in the big box
also. The parser will find the version that is most local to the calling
line.
If you are trying to reference both of them from the big box, using the
exact same name, then you deserve to get tied in knots and should find
another line of work.
Ken
_________________________________________________________________
Our best dial-up offer is back. Get MSN Dial-up Internet Service for 6
months @ $9.95/month now! http://join.msn.com/?page=dept/dialup
More information about the thelist
mailing list