PHP - eval
Trieda
Metóda - eval
(PHP 4, PHP 5, PHP 7)
Evaulates given PHP code. It's a language construct, not a function.
If an error occurred during the evaluation, the whole script exits.
Tip: The output of the evaulated code can be redirected and saved e.g. in a string.
Procedurálne
- function eval (string $code) : mixed
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $code | string | Valid PHP code without the opening or closing tags
( |
Mávratovej hodnoty
Vracia: mixed
Returns null if the code sent to eval() doesn't
return anything, otherwise returns the value returned by the given code. Since
PHP 7 it throws the ParseError exception in case of a parse
error.
Príklady
<?php
$number = 42;
$name = "John";
$code = 'echo("My name is $name and I am $number years old.");';
eval("$code");
