Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've been creating a php script for a project and have been running it on my development server which is running PHP 5.4.17

I need to move it over to my production server which is running PHP 5.4.19

When using the array_map function on my development server I got the results I needed with no problem.

On my production server I get the parse error:

Parse error: syntax error, unexpected '[' in /path/to/script/ on line 219

My code used was:

$arr = array_map(
    function($results_titles, $results_image, $results_summary, $results_dates, $results_links) {
        return ['title' => $results_titles, 'image' => $results_image, 'summary' => $results_summary, 'date' => $results_dates, 'link' => $results_links];
    },
    $results_titles, $results_image, $results_summary, $results_dates, $results_links
);
share|improve this question
1  
You've confused PHP and JS syntax) In PHP array initialized with: array(...), not [...] –  hindmost Feb 18 '14 at 8:15
1  
I don't remember since which version using [array_elements] was valid, maybe the problem is there, try using the classic structure: return array('title => $result_titles, etc...); I would keep using that syntax for a while, just in case xD –  aleation Feb 18 '14 at 8:16
    
Are you 2000% sure it's running on 5.4 on your server? –  deceze Feb 18 '14 at 8:18
    
@hind Nope, PHP supports this syntax now as well. –  deceze Feb 18 '14 at 8:18
    
@hindmost since 5.4.0 you can use [] directly for the arrays too. OP, I think you are on a version prior to 5.4.0, check this link, your code should be valid on >5.4 php.net/manual/en/migration54.new-features.php –  aleation Feb 18 '14 at 8:20

1 Answer 1

The new array syntax comes up with PHP 5.4.

So make sure your php version in your server is >= PHP 5.4

Note: the cli and the web server(eg: apache) could run different version of php.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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