0

Situation:

This works:

$functionCode = 'return ($myvar1 == "something") && ($myvar2 != "");';
$newfunc = create_function($functionParamsConcat, $functionCode);

But the problem is that the funcitonCode is dynamic, and the boolean expression inside it can vary (it is taken from the database). The confussing part is that that when i retrieve the SAME functionCode from the database and assign it to the variable, the $newfunc returned by create_function is always false.

Any ideas? Thank you

mpinvidio
  • 489
  • 6
  • 17
  • Are you sure a quote isn't being escaped? More importantly, why would you build functions from the database? If someone got the chance to SQL inject you, they could do some serious damage. – Jeremy Harris Oct 28 '13 at 18:37
  • I tryied using PHP built in function addslashes to escape the whole functionCode, failing, $newfunc is always false. (forget about sqlinjection in this case though I appreciate your concern) – mpinvidio Oct 28 '13 at 18:47

1 Answers1

0

$functionCode = 'return ($myvar1 == "something") && ($myvar2 != "");'; $newfunc = create_function($functionParamsConcat, $functionCode);

in checking don't use = as it will set it, but use == or ===
for ! use !==