note 53706 added to function.eval

From: Date: Thu, 09 Jun 2005 19:58:01 +0000
Subject: note 53706 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-90196@lists.php.net to get a copy of this message
Just a note when using eval and expecting return values - the eval()'ed string must do the returning. Take the following example script: <?php function ReturnArray() { return array("foo"=>1, "bar"=>2); } $test = eval("ReturnArray();"); print("Got back $test (".count($test).")\n"); $test = eval("return ReturnArray();"); print("Got back $test (".count($test).")\n"); ?> You will get back: Got back (0) Got back Array (2) This ran me afoul for a little bit, but is the way eval() is supposed to work (eval is evaluating a new PHP script). ---- Manual Page -- http://www.php.net/manual/en/function.eval.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53706 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53706&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53706&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53706&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53706&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53706&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53706&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90196) next »