You are here: Re: global variables « PHP Programming Language « IT news, forums, messages
Re: global variables

Posted by Toby A Inkster on 02/14/07 17:08

Oliver Grätz wrote:

> - Global variables in PHP are not as global as they are in other
> languages where you can sometimes always see the global variables. Some
> languages even have the keyword "local" to prohibit a variable from
> becoming global. PHP instead has the "global" keyword to define a
> variable as global.

In PHP the global keyword basically pulls a variable from the global
namespace into the local namespace.

What most other languages refer to as "globals" PHP calls "superglobals".
There's no way to define superglobals though -- PHP defines a few on its
own (depends on your version, but in recent ones, $_POST, $_GET, $SERVER,
$_SESSIOM, $_ENV, $_FILES and $GLOBALS) and you're stuck with them.

Although I steer away from globals (in my current project, over 4000 lines
of PHP so far, and not a single global!), sometimes I really would
appreciate having a method of defining superglobals. Not going to happen
though. :-(

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация