ID: 16185
Updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
Status: Bogus
Bug Type: Feature/Change Request
Operating System: WinXP
PHP Version: 4.1.2
New Comment:
Interestingly, the one-line solution for accessing globals seems to be
causing PHP.exe to hang.
I have narrowed it down to the following code which makes php die under
WinXP (at least it does here)
<?
session_start();
session_register("Ses");
$Ses->UserAdvanced = true;
function test()
{
foreach($GLOBALS as $key => $value) global $$key; // get access
to
all globals
}
test();
?>
Previous Comments:
------------------------------------------------------------------------
[2002-03-20 18:18:19] [EMAIL PROTECTED]
Thanks for the suggestions, I think I will stick all my globals in a
structure since this won't be changed.
I agree that globals are not good in an object oriented language, but I
still disagree about this - I would venture to guess that PHP is used
mostly for small scale scripting, and the needs of the many - smallness
and simplicity - outweigh the needs of the few poor saps who are trying
to write an OS with it.
------------------------------------------------------------------------
[2002-03-20 10:44:42] [EMAIL PROTECTED]
bogusified
------------------------------------------------------------------------
[2002-03-20 10:44:04] [EMAIL PROTECTED]
#1 don't use globals. period. we are *not* going to change the language
to support bad design techniques
#2 you can get all global symbols by doing
foreach($GLOBALS as $key => $value) global $$key;
------------------------------------------------------------------------
[2002-03-20 10:07:18] [EMAIL PROTECTED]
Changing this would break waaay to much, and it's against the nature of
PHP.
i think it's a bad idea to change this.
Derick
------------------------------------------------------------------------
[2002-03-20 10:06:40] [EMAIL PROTECTED]
I agree with Rasmus (and I really like his story :-), but to help you
shoot yourself in the foot:
Declare and use your globals like this:
$g->id = 1000;
$g->username = "Marc";
// etc. until you have 20 of them
function fn() {
global $g;
$g->username = "Rasmus";
}
with the added benefit of auto-global for any new global var you add in
a later stage of the project.
This looks very similar to using $GLOBALS["username"] inside your
function, which is what I use if I desperately _need_ a global.
Cheerio, Marc.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/16185
--
Edit this bug report at http://bugs.php.net/?id=16185&edit=1