note 84874 deleted from function.include by danbrown

From: Date: Mon, 18 May 2009 00:54:45 +0000
Subject: note 84874 deleted from function.include by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155445@lists.php.net to get a copy of this message
Note Submitter: darkain at darkain dot com ---- in response to pepesantillan at gmail dot com here is a much simpler way of accessing the entire global scope from within a function, reguardless of variable types. test.php <?php function my_include($file) { //get access to all globals foreach ($GLOBALS as $key => $val) { eval("global \$$key;"); } //include our file include($file); } $example = 1; my_include('example.php'); echo $example; ?> example.php <?php $example = 2; ?> display: 2

« previous php.notes (#155445) next »