note 61247 added to function.eval

From: Date: Sun, 29 Jan 2006 12:01:59 +0000
Subject: note 61247 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-102663@lists.php.net to get a copy of this message
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" ?> ---- Server IP: 194.109.193.119 Probable Submitter: 82.75.226.178 ---- Manual Page -- http://www.php.net/manual/en/function.eval.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61247 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61247&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61247&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61247&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61247&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61247&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61247&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61247&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61247&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102663) next »