During a code review, I have found something similar to this:
function foo() {
$a = "a";
$expression = '$_GET["$a"]';
return eval('return ('.$expression.');');
}
$a = foo();
echo $a;
Don't mind the nonsense, the example is simplified and due to bad design decisions, the client "really" needs the "return eval" instruction.
My guess would be no, because $expression
is not $_GET["$a"]
, but a string representing the name of the variable, so the argument to eval()
is equivalent to a "return string".
But according to the PHP manual:
You should never use parentheses around your return variable when returning by reference, as this will not work. You can only return variables by reference, not the result of a statement. If you use
return ($a);
then you're not returning a variable, but the result of the expression($a)
(which is, of course, the value of$a
).
Is there a way this could be exploited?