News for hackers. Stuff that matters.
Re:Functional PHP 5.3 - What are Anonymous Functions and Clo... by phicou on Tuesday August 18, 2009 @12:16PM (#770766)
This should be a big help in writing clean server-side sorts by an arbitrary column in tabular data.

Previously we've had to do some rather ugly things with "create_function" and lots of escaping in order to make arbitrary sort comparator functions.

An example of the old style:

    private function makeCompare($field, $desc) {
        return create_function('$a,$b', "
            \$r = strcasecmp(\$a['$field'], \$b['$field']);
            return " . ($desc ? '-1' : '1') . " * \$r;");
    }
Not my proudest moment, to be sure.

There are no comments on this comment yet.