Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11924 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59992 invoked by uid 1010); 4 Aug 2004 23:51:49 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 59933 invoked from network); 4 Aug 2004 23:51:48 -0000 Received: from unknown (HELO mail.zend.com) (80.74.107.235) by pb1.pair.com with SMTP; 4 Aug 2004 23:51:48 -0000 Received: (qmail 27114 invoked from network); 4 Aug 2004 23:51:46 -0000 Received: from localhost (HELO AndiNotebook.zend.com) (127.0.0.1) by localhost with SMTP; 4 Aug 2004 23:51:46 -0000 Message-ID: <5.1.0.14.2.20040804165109.02e94c58@127.0.0.1> X-Sender: andi@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Wed, 04 Aug 2004 16:51:42 -0700 To: "A.Rico" ,internals@lists.php.net In-Reply-To: <20040804233723.9149.qmail@pb1.pair.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] Variable Variables and Superglobals From: andi@zend.com (Andi Gutmans) References: <20040804233723.9149.qmail@pb1.pair.com> Right. Variable variables don't work with super-globals and I think it is documented in this way. This is on purpose as we decided to only support them this way both for clarity reasons and for performance. There are no plans to change this. Andi At 01:35 AM 8/5/2004 +0200, A.Rico wrote: > Using Variable Variables works fine inside functions for global >defined variables if you declare them as global inside the function. >Suprinsingly, it does not seem to work with superglobals. Take the >following example: > >// code //////////////////////////////////////////////////////////// > >$glob_var="Var 1"; > >$var_glob_var="glob_var"; >$var_ENV="_ENV"; > >echo $_ENV["OS"],"\n"; >echo $glob_var,"\n\n"; > >echo $var_glob_var,"\n"; >echo $var_ENV,"\n\n"; > >echo $$var_glob_var,"\n"; >echo ${$var_ENV}["OS"],"\n\n"; > >foo1($var_glob_var); >foo2($var_glob_var); >foo3(); >foo4(); >foo5($var_ENV); >foo6($var_ENV); >foo7(); >foo8(); >foo9(); > >function foo1($arg){ > echo "--- In foo1 --------------\n"; > echo $arg,"\n"; > echo $$arg,"\n"; > echo "--------------------------\n"; >} >function foo2($arg){ > global $glob_var; > > echo "--- In foo2 --------------\n"; > echo $arg,"\n"; > echo $$arg,"\n"; > echo "--------------------------\n"; >} >function foo3(){ > $arg="glob_var"; > echo "--- In foo3 --------------\n"; > echo $arg,"\n"; > echo $$arg,"\n"; > echo "--------------------------\n"; >} >function foo4(){ > global $glob_var; > > $arg="glob_var"; > echo "--- In foo4 --------------\n"; > echo $arg,"\n"; > echo $$arg,"\n"; > echo "--------------------------\n"; >} >function foo5($arg){ > echo "--- In foo5 --------------\n"; > echo $arg,"\n"; > echo ${$arg}["OS"],"\n"; > echo "--------------------------\n"; >} >function foo6($arg){ > global $_ENV; > > echo "--- In foo6 --------------\n"; > echo $arg,"\n"; > echo ${$arg}["OS"],"\n"; > echo "--------------------------\n"; >} >function foo7(){ > $arg="_ENV"; > > echo "--- In foo7 --------------\n"; > echo $arg,"\n"; > echo ${$arg}["OS"],"\n"; > echo "--------------------------\n"; >} >function foo8(){ > global $_ENV; > $arg="_ENV"; > > echo "--- In foo8 --------------\n"; > echo $arg,"\n"; > echo ${$arg}["OS"],"\n"; > echo "--------------------------\n"; >} >function foo9(){ > echo "--- In foo9 --------------\n"; > echo $_ENV["OS"],"\n"; > echo "--------------------------\n"; >} >?> > >// Output ///////////////////////////////////////////////////////// > >Windows_NT >Var 1 > >glob_var >_ENV > >Var 1 >Windows_NT > >--- In foo1 -------------- >glob_var > >-------------------------- >--- In foo2 -------------- >glob_var >Var 1 >-------------------------- >--- In foo3 -------------- >glob_var > >-------------------------- >--- In foo4 -------------- >glob_var >Var 1 >-------------------------- >--- In foo5 -------------- >_ENV > >-------------------------- >--- In foo6 -------------- >_ENV > >-------------------------- >--- In foo7 -------------- >_ENV > >-------------------------- >--- In foo8 -------------- >_ENV > >-------------------------- >--- In foo9 -------------- >Windows_NT >-------------------------- > >// Version ////////////////////////////////////////////// > >PHP 4.3.7 (cgi-fcgi) (built: Jun 2 2004 15:49:31) >Copyright (c) 1997-2004 The PHP Group >Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies > >// End ////////////////////////////////////////////////// > > I'm doing something wrong? Or this is the expected behavior? > >Thank you in advance > >-- >PHP Internals - PHP Runtime Development Mailing List >To unsubscribe, visit: http://www.php.net/unsub.php