/** * Construct expression * * @param string $expression Expression to create * @param string $defaultName Default name in expression * @param bool $descending Descending order? * @param string $comparer Comparer function */ public function __construct($expression, $defaultName = '', $descending = false, $comparer = null) { // Default name $this->_defaultName = $defaultName; // Internal expression $this->_expression = new PHPLinq_Expression($expression, $defaultName); // Comparer function set? if (is_null($comparer)) { $comparer = 'strcmp'; } // Descending? if ($descending) { $comparer = '-1 * ' . $comparer; } $this->_descending = $descending; // Compile comparer function // Check http://www.php.net/manual/nl/function.create-function.php#14322 for this chr(0).'$f' approach... $f = substr($this->_expression->getFunctionReference(), 1); $this->_functionReference = new PHPLinq_Function($defaultName . 'A, ' . $defaultName . 'B', "return {$comparer}(\n\t\t\t\t\tcall_user_func(chr(0).'{$f}', {$defaultName}A),\n\t\t\t\t\tcall_user_func(chr(0).'{$f}', {$defaultName}B)\n\t\t\t\t);"); }