In PHP the function eval() will evaluate a string as a PHP code.
For example,
eval ( "echo 'Hello Name';" );
in the above code eval will take the contents of the string and execute it and hence will produce the same output as
echo 'Hello Name';
There may be lot of cases when eval() can be useful. You can store blocks of code in a database, and retrieve and eval() them at a later point. You can generate code in a loop, and then use eval() to execute it. You can safely use eval() to update or correct existing code.
If you had a large collection of scripts that needed a predictable change, it would be possible (but inefficient) to write a script that loads an old script into a string, runs a regexp to make changes, and then uses eval() to execute the modified script.
It is even conceivable that a very trusting person somewhere might want to allow PHP code to be entered in a browser and executed on her server.
- Kiran's blog
- 328 reads













Post new comment