Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

This question already has an answer here:

class test
{
    public $do;
    function __construct($data="")
    {
        $this->parse($data);
    }
    private function parse($data)
    {
        // Decoding the functions
        $decoded_data = json_decode($data,true); 
        array_walk_recursive($decoded_data,function(&$function) {
            $first_line = strtok($function, "\n");
            preg_match("/\/\*#(.*?)\#*\//",$first_line,$matches);
            $function = create_function($matches[1],$function);
        });
        $this->do = $decoded_data;  
    }
}

Parse error: syntax error, unexpected T_FUNCTION

The error is in:

array_walk_recursive($decoded_data,function(&$function)

share|improve this question

marked as duplicate by hakre, DaveRandom, Ocramius, andrewsi, kapa May 2 '13 at 14:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Can you ensure that the code above is pasted exactly as it exists in your file? Start the copy/paste from the VERY first line: <?php... – ctrahey Jul 11 '12 at 4:29
    
Just as well to call out the line... thanks! – ctrahey Jul 11 '12 at 4:30
    
what does $function have? – diEcho Jul 11 '12 at 4:31
    
you can usually get very relevant results by googling the php error messages, and this is true here. – goat Jul 11 '12 at 4:31
up vote 11 down vote accepted

Check your PHP version, anonymous functions are only supported on 5.3+

share|improve this answer
    
i think array_walk_recursive supported in PHP5 – diEcho Jul 11 '12 at 4:33
    
But not anonymous functions. – Daniel Shlomo Jul 11 '12 at 4:40
    
I had a similar problem, changed PHP version to 5.4. Means mysql will be deprecated, so you have to use mysqli or PDO – William Aug 6 '15 at 19:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.