0

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
);
9
  • 1
    You've confused PHP and JS syntax) In PHP array initialized with: array(...), not [...] Commented Feb 18, 2014 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 Commented Feb 18, 2014 at 8:16
  • Are you 2000% sure it's running on 5.4 on your server? Commented Feb 18, 2014 at 8:18
  • @hind Nope, PHP supports this syntax now as well. Commented Feb 18, 2014 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 Commented Feb 18, 2014 at 8:20

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.