note 108251 deleted from language.variables.scope by mazzanet

From: Date: Thu, 12 Apr 2012 06:17:38 +0000
Subject: note 108251 deleted from language.variables.scope by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187076@lists.php.net to get a copy of this message
Note Submitter: cuisdy at gmail dot com ---- 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; } ?>

« previous php.notes (#187076) next »