Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14621 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16562 invoked by uid 1010); 4 Feb 2005 00:31:25 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 16539 invoked by uid 1007); 4 Feb 2005 00:31:25 -0000 Message-ID: <20050204003125.16538.qmail@lists.php.net> To: internals@lists.php.net References: <20050128223155.81436.qmail@lists.php.net> <5.1.0.14.2.20050128145327.04025190@localhost> <20050128233054.9657.qmail@lists.php.net> <20050128234649.27693.qmail@lists.php.net> <20050128235345.42569.qmail@lists.php.net> <20050130193103.63809.qmail@lists.php.net> <20050131182732.84357.qmail@lists.php.net> <20050131211614.84286.qmail@lists.php.net> <20050131222442.61678.qmail@lists.php.net> <20050203221208.67112.qmail@lists.php.net> <20050203235225.46734.qmail@lists.php.net> <20050204001957.93389.qmail@lists.php.net> Date: Thu, 3 Feb 2005 16:31:25 -0800 Lines: 42 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Response X-Posted-By: 169.229.135.26 Subject: Re: referencing Superglobals with variable variables inside functions From: pollita@php.net ("Sara Golemon") > ok, i see. But why does it work with variables that are set as global, > e.g. the $HTTP_*_VARS: > > function test() { > global $HTTP_GET_VARS; > $a = 'HTTP_GET_VARS'; > var_dump($$a); > } > test(); > ?> > global $foo; is the equivalent of: $foo = &$GLOBALS['foo']; So when you access $$a, you're getting 'HTTP_GET_VARS' from the LOCAL symbol table (where it exists as a reference of the global symtable version). > this works inside a function. is it because of the global keyword? If so, > why can't there be a "magic" "global $_GET, $_POST, $_SESSION ..." set in > every function, for every superglobal, instead of the way it is handled > now? The thing i don't get is, why the superglobals behave differently > than "normal" global variables at all. In a word: efficiency. There's an expression: "Fast, Clean, Cheap: Pick Two". The current implementation is Fast and Cheap, but as this thread has highlighted, it's not entirely clean. > Ok, you have explained the technical reasons, but that's not what i mean. > For me as a php user (developing in php), the only difference should be, > that i don't have to use the global keyword. Everything else seems like a > bug or design flaw to me. > You won't hear a lot of argument from me. I just care less that it is the way it is. -Sara