I was looking through some code for work, and came across this line:
eval("\$element = \"$element\";");
I'm really confused as to why any PHP developer would've written this line. What purpose does this serve, besides setting a variable to itself?
Luckily, the function this line is in is never called.
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "\n";
eval("\$str = \"$str\";");
echo $str. "\n";
?>
The above example will output:
This is a $string with my $name in it.
This is a cup with my coffee in it.
http://php.net/manual/en/function.eval.php
I do just ctl+c ctrl+v :-)
It converts the value of the variable to a string, but I wouldn't recommend using it.
Use the function strval()
instead. Have a look at the manual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With