note 61247 deleted from function.eval by googleguy

From: Date: Fri, 24 Feb 2017 21:10:27 +0000
Subject: note 61247 deleted from function.eval by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208817@lists.php.net to get a copy of this message
Note Submitter: jkuckartz1984 at hotmail dot com ---- Might you have to do eval in if statements, you will find it's quite some task to make it work. The only way to make it work is to make a reference to the eval'd variable. This example will show the different usage of eval in if-statements. It simply becomes clear that an eval() in an if() is not working as you want to. <?php $total2=5; $total3=0; $i=2; if (eval("\$total".$i.";")) { echo "eval: total2 is full<br>"; } else { echo "eval: total2 is empty<br>"; } // returns "empty" // eval without the ";" will generate a warning $str="\$refer=&\$total".$i.";"; eval($str); if ($refer) { echo "eval: total2 is full<br>"; } else { echo "eval: total2 is empty<br>"; } // returns "full" ?>

« previous php.notes (#208817) next »