note 84874 added to function.include

From: Date: Sun, 03 Aug 2008 04:08:20 +0000
Subject: note 84874 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-143085@lists.php.net to get a copy of this message
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 ---- Server IP: 209.41.74.194 Probable Submitter: 131.191.14.252 ---- Manual Page -- http://www.php.net/manual/en/function.include.php Edit -- https://master.php.net/note/edit/84874 Del: integrated -- https://master.php.net/note/delete/84874/integrated Del: useless -- https://master.php.net/note/delete/84874/useless Del: bad code -- https://master.php.net/note/delete/84874/bad+code Del: spam -- https://master.php.net/note/delete/84874/spam Del: non-english -- https://master.php.net/note/delete/84874/non-english Del: in docs -- https://master.php.net/note/delete/84874/in+docs Del: other reasons-- https://master.php.net/note/delete/84874 Reject -- https://master.php.net/note/reject/84874 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143085) next »