note 62316 added to function.eval
| From: | jnavratil at houston dot rr dot com | Date: | Fri, 24 Feb 2006 23:39:41 +0000 |
| Subject: | note 62316 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104388@lists.php.net to get a copy of this message | ||
"A return statement will terminate the evaluation of the string immediately. As of PHP 4,
eval() returns NULL unless return is called in the evaluated code, in which case the value passed to
return is returned." isn't strictly true as the eval can return a value through the
side-effect of setting a variable.
<?php
function getValue()
{
return 123;
}
function testEval1()
{
eval('return getValue();');
}
function testEval2()
{
eval('$rslt = getValue();');
return $rslt;
}
function testEval3()
{
return eval('return getValue();');
}
function testEval4()
{
return eval('getValue();');
}
print '1:'.testEval1()."\n";
print '2:'.testEval2()."\n";
print '3:'.testEval3()."\n";
print '4:'.testEval4()."\n";
?>
results in...
1:
2:123
3:123
4:
In case 1, the eval returns the result to an uncaring caller (contra: case 3). In case 2, the eval
makes the result available through the side-effect of setting '$rslt'. In case 4,
'eval' returns null to an apparently caring caller (contra: case 1).
----
Server IP: 64.71.164.2
Probable Submitter: 24.160.91.37
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+62316
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62316&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62316&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62316&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62316&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62316&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62316&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62316&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+62316&report=yes
Search -- http://master.php.net/manage/user-notes.php