Tags
PHP
Asked 2 years ago
27 May 2021
Views 491
kiran

kiran posted

what is use of eval() function in php ?

what is use of eval() function in php ?
how to use eval() function in php ?
is it dangerous to use eval() function in php ?
ching

ching
answered Nov 30 '-1 00:00

First of eval() is not a function but it is a language construct.

eval ( string $code )  


you can pass the string to evaluate it


eval("echo 'hello';");



it will print : hello

eval return null so if you do echo eval('...') it will print nothing

Nilesh

Nilesh
answered Nov 30 '-1 00:00

you can not pass the any string variable to eval()

 $string='Hello';
  eval($string);

here $string passed to eval() and it not executing it and so
this will print nothing
iptracker

iptracker
answered Nov 30 '-1 00:00

is it dangerous to use the eval() function in PHP ?
Answer is Yes , eval() is dangerous because by eval() hacker can inject code into the system
suppose :

  eval('echo file_get_contents("index.php");');


this code will return all code of index.php

you should disable eval() to avoid the problem
angeo

angeo
answered Nov 30 '-1 00:00

eval() construct is evil, block to use of it from server php configuration
Post Answer