Is there any other way to call this function besides using php eval?

So, in the database field there is a php function. Here's what it looks like:

'$put_fname_fn = function($filename) {
    return $filename.'.Z';
};'

I execute it as follows:

$code = fetchFromDatabase(); // Get the function string
eval($code);
$put_fname_fn('MYFILE.TXT'); // Convert it to MYFILE.TXT.Z

Is there a more graceful way to call a user-defined function? I try to avoid using eval, but I have no other way to do this.

+5
source share
1 answer

There is no other way to evaluate code in PHP. (You can write code to a file and includeit, but it's just hidden eval.)

, , . - . ( SQL-), PHP-.

+9

All Articles