kektex Posted April 15, 2010 Share Posted April 15, 2010 Just from searching the board I realize this has been asked sooo many times, but I can't seem to locate the problem in this code: usort($status, function($a, $b) {global $sort; return strcmp($a[$sort], $b[$sort]); }); foreach(array_merge(array($cols), $status) as $line) call_user_func_array('printf', array_merge(array($fmt), $line)); print_r($print); I'm getting a " Parse error: syntax error, unexpected T_FUNCTION in ui.php " on the first line of this script. The weird thing is that when I run the script on my PC using EasyPHP I don't get the error, it only happens on my Linux server. Any ideas? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/198600-parse-error-syntax-error-unexpected-t_function/ Share on other sites More sharing options...
Alex Posted April 15, 2010 Share Posted April 15, 2010 Anonymous functions are only available in PHP 5.3.0+. Use create_function. Quote Link to comment https://forums.phpfreaks.com/topic/198600-parse-error-syntax-error-unexpected-t_function/#findComment-1042155 Share on other sites More sharing options...
kektex Posted April 15, 2010 Author Share Posted April 15, 2010 Hi Alex, Thanks for your help . How can I use create_function to solve this problem? Im not very knowledgeable in PHP , I am just trying to fix an error in an existing script. Quote Link to comment https://forums.phpfreaks.com/topic/198600-parse-error-syntax-error-unexpected-t_function/#findComment-1042390 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 kektex, click here - create_function Quote Link to comment https://forums.phpfreaks.com/topic/198600-parse-error-syntax-error-unexpected-t_function/#findComment-1042395 Share on other sites More sharing options...
TeddyKiller Posted April 15, 2010 Share Posted April 15, 2010 Anonymous functions are defined by the arguement string, then the code string. The syntax would look like this $func_name = create_function(args_string, code_string); An example could be.. $myvariable = '1'; $myfunction = create_function('$myvariable', '$myvariable * 2'); echo $myfunction; The result should be 2 Here is an example using usort(). $function = create_function('$a, $b', 'return(strlen($a) - strlen($b));'); $array = array('a massive string', 'it', 'huge length', 'cat poop'); usort($array, $function); print_r($array); I'm not saying this will work or not, but it's an example. I hope you understand! Quote Link to comment https://forums.phpfreaks.com/topic/198600-parse-error-syntax-error-unexpected-t_function/#findComment-1042400 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 $lambda is undefined. Quote Link to comment https://forums.phpfreaks.com/topic/198600-parse-error-syntax-error-unexpected-t_function/#findComment-1042401 Share on other sites More sharing options...
TeddyKiller Posted April 15, 2010 Share Posted April 15, 2010 $lambda is undefined. oops, just changed that. Quote Link to comment https://forums.phpfreaks.com/topic/198600-parse-error-syntax-error-unexpected-t_function/#findComment-1042402 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.