note 108251 added to language.variables.scope

From: Date: Wed, 11 Apr 2012 21:04:43 +0000
Subject: note 108251 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-187061@lists.php.net to get a copy of this message
Sometimes you need to import ALL global vars into a method or function, without knowing in advance which vars you will have. Maybe you're adding a plugin for a mostly procedural application, and you decided to do it the right way... but then found out the rest of the app relied on everything being global. The simplest answer would be <?php extract($GLOBALS); ?> Now, if you want vars to really act like they're global, you should import them by reference instead: <?php foreach ($GLOBALS as $var => &$value) { $$var =& $value; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 186.55.0.150 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- https://master.php.net/note/edit/108251 Del: integrated -- https://master.php.net/note/delete/108251/integrated Del: useless -- https://master.php.net/note/delete/108251/useless Del: bad code -- https://master.php.net/note/delete/108251/bad+code Del: spam -- https://master.php.net/note/delete/108251/spam Del: non-english -- https://master.php.net/note/delete/108251/non-english Del: in docs -- https://master.php.net/note/delete/108251/in+docs Del: other reasons-- https://master.php.net/note/delete/108251 Reject -- https://master.php.net/note/reject/108251 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187061) next »