View Full Version : looks like i still need to use create_function() in php 5.3?

03-03-2010, 11:51 PM
i'm putting together a function currently like this (it's inside a for-loop):

// standard comparison operators
if (preg_match('/^((==|<|>|!=)=?|<>)$/', $mode) == 1) {
$cmp = create_function('$a, $b', "return \$a $mode \$b;");
if (!$cmp($objval, $val))
return FALSE;

this is my concise way of running a comparison of 2 values from operators passed in from a config file as a string, eg '==' or '<='.

i dont think there is an alternative in 5.3 to using this construction; lambdas would not really solve this. you'd still need to create a 9-case switch for all operators.

if anyone knows otherwise, let me know.