note 51872 deleted from function.eval by nlopess

From: Date: Wed, 13 Apr 2005 18:28:10 +0000
Subject: note 51872 deleted from function.eval by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-87968@lists.php.net to get a copy of this message
Note Submitter: dAxpHpNIzER at lukydeluxe dot org ---- I had a very big problem, because I'm using Functions in my program and I don't knew which variables I needed in each function. So i created following: <?php // Developed by dAxpHpNIzER $myvar1 = 1; $myvar2 = 2; $myvar3 = 3; $myvar4 = 4; $arr = get_defined_vars(); function dAfunction() { global $arr; foreach ($arr as $key => $value) { $blah = $key; @eval("\$".$blah." = \"$value\"; global \$".$blah.";"); } echo $myvar1; // So you get $myvar1 without writing 'global $myvar1;' } ?> If you put global $arr; foreach ($arr as $key => $value) { $blah = $key; @eval("\$".$blah." = \"$value\"; global \$".$blah.";"); } in every of your Function, you wont have to set every used variable as global. Of course you have to declare $arr = get_defined_vars(); first.

« previous php.notes (#87968) next »