> I'm a bit troubled with the fact that variables declared at the top of your
> script are not then global to functions within that script.  That in order
> to see that variable within a function you'd have to declare it as global in
> the function (understanding that the variable could have been set at the top
> of the script).  This seems extremely backwards to me (me being a VB guy).
>
> Would someone kindly shine the light down upon me with an explanation of
> this logic?  And why can't I possibly declare the variable as Global at the
> top of my script?

Once upon a time in a cold land far far away, a brave programming team was
building a castle.  The castle was large and complex with countless rooms
and secret passageways.  On one frightful day the team got stuck.  They
had built one too many rooms with one too many secret passageways and
suddenly the castle was beginning to crumble.  A desperate plea went out
to the local wizard who was strong and powerful.  The local wizard looked
at the problem, saw the many rooms and the many secret passageways and
gave the following decree:  "Thou must post a sign in each and every room
declaring which secret passageways connect to this room."  The brave
programming team feared the wizard and implemented the decree immediately
although they really didn't understand how it would help.  What they found
was that a number of secret passageways did not connect to anything and
others connected to places that didn't make any sense.  After fixing these
the castle was solid again.

The moral of this tale is that one must declare ones' global variables
that one intends to use within a function.  In languages like C where this
is not required one can end up with all sorts of weird side effects when a
function changes a variable that the programmer intended to be local to
the function and it affects code elsewhere in the system.  This is almost
impossible to track down.  The tale of the brave programming team led to
this being a requirement in PHP.

-Rasmus



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to