Eval()¶
The eval() function executes a string as a PHP code.
eval() has been used originally to obtain features that PHP did not offer. Nowadays, those features are rare enough that it is recommended to find a safe alternative, before using on it.
When used, it is recommended to enclose eval() in a try-catch block, to catch syntax error.
<?php
$name = 'v';
$value = 'vvvv';
// Set a variable with a dynamic name
eval('$'.$name.' = '.$value);
// equivalent to $$name = $value;
?>
See also Eval function in PHP and The Land where PHP uses eval().
Related : ParseError, Try-catch, Code Injection, Execution