I have error in line 2 and 13 in PHP 5.2, I have no idea to make the correction, I tried using create_function but not working, can anyone help with this?
function _process_special_keyword($str){
$callback = function($match){
$ret = $match[1] . '[' . $match[2] . ']';
if(!empty($match[3])){
$ret .= '.[' . $match[3] . ']';
}
$ret .= $match[4];
return $ret;
};
$strSQL = preg_replace_callback('/([\s\(\.,])(' . SPECIAL_KEYWORDS . ')(?:\.(' . SPECIAL_KEYWORDS . '))?([\s\)\.,])/i', $callback, $str);
$callback = function($match){
return 'CASE WHEN ' . $match[1] . ' THEN ' . $match[2] . ' ELSE ' . $match[3] . ' END';
};
$strSQL = preg_replace_callback('/if\s*\((.+),(.+),(.+)\)/i', $callback, $strSQL);
return $strSQL;
}
Thanks.
Error: Parse error: syntax error, unexpected T_FUNCTION
When using
create_function()
, the contents of the first argument should be a string representation of the PHP code that would fill the parentheses for thefunction
declaration. The second argument should contain only the code inside the curly braces{}
of the function declaration, the actual declaration itself should be omitted.Try this code:
You can declare the callbacks outside of this function. Like this:
Note: If these functions are in a class (meaning the function would be need to called like
$this->_callback_one
), pass an array as the "callback" parameter.according with object question, the faster way I think is something like so,
note backslashes before $ and <<< FLAG FLAG; construct. In practice the answer of Rocket is more simple.