Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Eval
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== PHP === In [[PHP]], <code>eval</code> executes code in a string almost exactly as if it had been put in the file instead of the call to <code>eval()</code>. The only exception is that errors are reported as coming from a call to <code>eval()</code>, and return statements become the result of the function. Unlike some languages, the argument to <code>eval</code> must be a string of one or more complete statements, not just expressions; however, one can get the "expression" form of <code>eval</code> by putting the expression in a return statement, which causes <code>eval</code> to return the result of that expression. Unlike some languages, PHP's <code>eval</code> is a "language construct" rather than a function,<ref>{{cite web|url=https://php.net/eval|website=[[PHP]].net|access-date=September 10, 2015|title=PHP: eval - Manual}}</ref> and so cannot be used in some contexts where functions can be, like higher-order functions. Example using echo: <syntaxhighlight lang="php"> <?php $foo = "Hello, world!\n"; eval('echo "$foo";'); ?> </syntaxhighlight> Example returning a value: <syntaxhighlight lang="php"> <?php $foo = "Goodbye, world!\n"; //does not work in PHP5 echo eval('return $foo;'); ?> </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)