note 77328 added to language.variables.scope

From: Date: Fri, 24 Aug 2007 15:04:52 +0000
Subject: note 77328 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-129756@lists.php.net to get a copy of this message
Another way of dealing with a large number of globals is to declare a single global array and then put all your global variables into it. Like this: $_G = array( 'foo' => 'some text', 'bar' => 4, 'boo' => 'more text, 'far' => 'yet more text' ); Now you just declare the one global array in each function: function blah() { global $_G; echo $_G['foo']; // or whatever } You can freely add to it without having to go back and add variable declarations to your functions. Kinda like using the $GLOBALS superglobal, except you don't have to type so much. ---- Server IP: 208.69.120.35 Probable Submitter: 128.61.161.92 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- https://master.php.net/note/edit/77328 Del: integrated -- https://master.php.net/note/delete/77328/integrated Del: useless -- https://master.php.net/note/delete/77328/useless Del: bad code -- https://master.php.net/note/delete/77328/bad+code Del: spam -- https://master.php.net/note/delete/77328/spam Del: non-english -- https://master.php.net/note/delete/77328/non-english Del: in docs -- https://master.php.net/note/delete/77328/in+docs Del: other reasons-- https://master.php.net/note/delete/77328 Reject -- https://master.php.net/note/reject/77328 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129756) next »