NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - eval

Trieda

Koreň \ Bez triedy

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ázovDátový typPredvolená hodnotaPopis
$codestring

Valid PHP code without the opening or closing tags (<?php ?>).

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");

Súvisiace manuály

        Aktivity