1
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)

3
  • 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... Jul 11, 2012 at 4:29
  • Just as well to call out the line... thanks! Jul 11, 2012 at 4:30
  • you can usually get very relevant results by googling the php error messages, and this is true here.
    – goat
    Jul 11, 2012 at 4:31

1 Answer 1

11

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

2
  • i think array_walk_recursive supported in PHP5
    – diEcho
    Jul 11, 2012 at 4:33
  • 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, 2015 at 19:41

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