Easy Tutorial
❮ Func Array Diff Key Func Array Uasort ❯

PHP eval() Function

PHP Misc Reference Manual

Example

Evaluate a string as PHP code:

<?php
$string = "beautiful";
$time = "winter";

$str = 'This is a $string $time morning!';
echo $str. PHP_EOL;

eval("\$str = \"$str\";");
echo $str;
?>

The above code will output:


Definition and Usage

The eval() function evaluates a string as PHP code.

The string must be valid PHP code and must end with a semicolon.

Note: The return statement will immediately terminate the evaluation of the string.

Tip: This function is useful for storing code in a database text field for later evaluation.


Syntax

Parameter Description
phpcode Required. Specifies the PHP code to be evaluated.

Technical Details

Return Value: Unless a return statement is called within the code string, it returns the value passed to the return statement; otherwise, it returns NULL. If there is a parse error in the code string, eval() returns FALSE.
PHP Version: 4+
--- ---

❮ Func Array Diff Key Func Array Uasort ❯