Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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
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. – chris Jul 11 '12 at 4:31

marked as duplicate by hakre, DaveRandom, Ocramius, andrewsi, bažmegakapa May 2 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 Answer

up vote 5 down vote accepted

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

share|improve this answer
Yeah, it was the case... Thank`s. – Daniel Shlomo Jul 11 '12 at 4:31
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

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