You are here: Re: Declare variable as superglobal? « PHP Programming Language « IT news, forums, messages
Re: Declare variable as superglobal?

Posted by JDS on 08/23/05 22:56

On Tue, 23 Aug 2005 12:01:04 -0700, Super Mango wrote:

> Hi -
>
> Is it possible to change the status of a variable to superglobal so
> it'll be valid inside functions without declaring it with "global"
> inside each function?
>
> Thanks -

All you have to do is put it inside one of the superglobal arrays. Use
those arrays directly inside the function.

e.g. instead of

function donut(){
global $holes;
return $holes - 1;
}

do

function donut(){
return $GLOBALS['holes'] - 1;
/* or $_SESSION['holes'] or $_POST['holes'] or other superglobal */
}

However, the real answer to your question is DO NOT USE GLOBALS INSIDE
FUNCTIONS!!!! You are just asking for trouble down the line, take my word
for it.

--
JDS | jeffrey@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

 

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

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