user4802601
user4802601

Reputation:

Undefined function eval() - PHP

I'm trying to use the eval() function like that :

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

But i'm getting an error : Fatal error: Call to undefined function eval()

That's strange because the following code is working

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

Can anyone help about it ?

Upvotes: 6

Views: 3915

Answers (1)

Felix Kling
Felix Kling

Reputation: 816334

From the eval documentation:

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

Following the link in the note you will also find:

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.

Upvotes: 10

Related Questions