note 98263 deleted from function.eval by danbrown

From: Date: Fri, 04 Jun 2010 19:00:26 +0000
Subject: note 98263 deleted from function.eval by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169897@lists.php.net to get a copy of this message
Note Submitter: Christopher K. ---- Reply to john dot risken at gmail dot com: This is NOT the way to do this. Eval is far too risky for this purpose and there are much better ways to do what you are doing: The easiest is using $$theVarStem: <?php $emailName="me@example.com"; $theVarStem="emailName"; $theVarValue=$$theVarStem; echo $theVarValue; // me@example.com ?> This does exactly what you did without using eval. Note that this only works with $$var, not $foo$var. So to do things like $foo$var, you need to set $var='foo'.$var first and then use $$var. I think in nearly any circumstance, using an array would be even better, especially if you're doing this for more than one variable: <? $myarray['emailName']="me@example.com"; $theVarStem="emailName"; $theVarValue=$myarray[$theVarStem]; echo $theVarValue; // me@example.com ?>

« previous php.notes (#169897) next »