Monday, 27 March 2017

Re: [dcphp-dev] Global Variables Question

This use is mostly a hangover from when PHP development was more procedural than object-oriented.  I agree it is best avoided altogether, but it can be used when you need to access a global variable while inside a function.

The discussion of static variables in the manual's entry on variable scope is fruitful reading: http://php.net/manual/en/language.variables.scope.php.

--dan mills

On Sun, Mar 26, 2017 at 10:08 AM, Whitney Yiu <wyiu416@gmail.com> wrote:
Hi all,

I am reading a book (PHP and MySQL Web Development - Thomson, Welling; 5th Ed.; Addison-Wesley) and am trying to understand the following passage regarding global variables:

You can also use the global keyword at the top of a script when a variable is first used to declare that it should be in scope throughout the script. This is possibly a more common use of the global keyword.

Can someone explain a use case for using a global variable at the top of a script? I thought that if a variable is declared outside of a function, then it is accessible throughout the script (except inside functions). I think I am missing something here.

Thanks,
Whitney 

--
You received this message because you are subscribed to the Google
Group: "Washington, DC PHP Developers Group" - http://www.dcphp.net
To post, send email to washington-dcphp-group@googlegroups.com
To unsubscribe, send email to washington-dcphp-group+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/washington-dcphp-group?hl=en
---
You received this message because you are subscribed to the Google Groups "Washington, DC PHP Developers Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to washington-dcphp-group+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google
Group: "Washington, DC PHP Developers Group" - http://www.dcphp.net
To post, send email to washington-dcphp-group@googlegroups.com
To unsubscribe, send email to washington-dcphp-group+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/washington-dcphp-group?hl=en
---
You received this message because you are subscribed to the Google Groups "Washington, DC PHP Developers Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to washington-dcphp-group+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

0 comments:

Post a Comment