2015-04-17 26 views
5

Sto cercando di utilizzare la funzione eval() come quella:funzione non definita eval() - PHP

$foo = 'eval'; 
$bar = 'echo 1;'; 
$foo($bar); 

Ma sto ottenendo un errore: Fatal error: Call to undefined function eval()

Questo è strano perché il seguente codice funziona

$foo = 'base64_encode'; 
$bar = 'foobar'; 
echo $foo($bar); 

chiunque può aiutare a questo proposito?

+1

E 'perché è il male! – adeneo

risposta

9

Dal eval documentation:

Note: Because this is a language construct and not a function, it cannot be called using variable functions .

seguendo il link nella nota puoi trovare anche:

Variable functions won't work with language constructs such as echo , print , unset() , isset() , empty() , include , require and the like. Utilize wrapper functions to make use of any of these constructs as variable functions.

+1

@ficuscr Ci possono essere usi estremamente pratici e utili per 'eval'. Il problema è che è abusato. – Anonymous

+0

A malincuore d'accordo ... Anche se sono pochi e lontani tra loro. E non in questo modo - è abbastanza sicuro che la funzione variabile non sia leggibile. Hai visto casi d'uso più validi per 'goto' ... – ficuscr

Problemi correlati