[thelist] PHP variable scoping

James Spahr james at designframe.com
Tue Aug 22 12:20:50 CDT 2000


on 8/22/00 1:12 PM, deboute benjamin at deboute at nerdsoul.com wrote:

> humpf...
> 
> php4 seems rather on variable scoping, especially it does some quirks when you
> include a lot of files that include a lot of files............adlib.
> 
> however ::
> outside a function a variable is global.
> 
> inside a function a variable is local.
> 
> you can call/set a global variable in a function by using GLOBAL $variable
> 
> help resolved ?

Yes. I'm stumbling through this. (4 weeks into learning PHP). I've never had
scoping problems like this in the other languages I've used. Eventually I'll
get the hang of it.

This is what I don't understand. This is the first line in my file

<?php
    df_vars[]="";
    ?>

I thought that -

a. variables defined outside a function on the primary page (not an include)
are global, everywhere.

b. and I could define an array and stick values into it and keep 'em all
global no matter where I set them.

turns out why assumptions are wrong... (grumble, grumble, grumble)

James
http://spahr.org/






More information about the thelist mailing list