note 115434 deleted from reserved.variables.globals by salathe
| From: | salathe@php.net | Date: | Wed, 23 Jul 2014 07:52:09 +0000 |
| Subject: | note 115434 deleted from reserved.variables.globals by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-200036@lists.php.net to get a copy of this message | ||
Note Submitter: Adam Bee
----
Here's how to get a copy of the $GLOBALS array without running into recursion or including
local environment variables.
<?php
foreach( $GLOBALS as $k => $v ){
if( $k != 'GLOBALS' && !ctype_lower($k) ){ $a[$k] = $v; }
}
extract($a); // (or $my_globals = var_export($a,true))
?>
Using extract() makes $FOO equivalent to $GLOBALS['FOO'], so you can use shorthand like
with constants, for brevity and string literals (like "$FOO bar" versus
"{$GLOBALS['FOO']} bar").