Undefined function eval () - PHP

I am trying to use the eval () function as follows:

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

But I get an error: Fatal error: Call to undefined function eval ()

This is weird because the following code works

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

Can anyone help with this?

+5
source share
1 answer

From the eval documentation :

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

By following the link in the note, you will also find:

Function variables will not work with language constructs such as echo , print , unset() , isset() , empty() , include , require and the like. Use wrapper functions to use any of these constructs as variable functions.

+9
source

All Articles