Why do I need eval in php?

I can't understand why eval is needed in php? In what cases is it often used?
We need a small example with an explanation.

 3
Author: Ilnyr, 2016-02-18

2 answers

Eval ('text') I personally used as something for translates. that is, you need to insert a parameter in the translate, for example: File with language variables:

...
$lang->Hello = 'Привет $user. Во время твоего отсутствии тебя проведали $visitors друзей'
...

Use cases:

...
$user = 'Вася';
$visitors = 15;
...
eval ("\$pr_text = \"$lang->getText('Hello')\";");
print $str;
...
 -1
Author: Іван Цуркан, 2016-02-18 23:43:24

It simply executes the code that you pass as a string argument, for example, as described in http://php.net/

$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "\n";
eval("\$str = \"$str\";");
echo $str. "\n";

The result will be

This is a $string with my $name in it.
This is a cup with my coffee in it.

With eval, variables are substituted, so you can also pass function calls and something else.

But the use of this is not recommended. Think three times before using these things...

 3
Author: BorisPobeshymov, 2016-02-18 23:35:06