0

The following function in my Wordpress functions.php file

405   function get_first_name($full_name) {
406     return explode(" ",$full_name)[0];
407   }

works fine on my test server, but as soon as I move it to the test server it causes this error:

Parse error: syntax error, unexpected '[' in ...functions.php on line 406

Actual file location removed for brevity and security.

This is a very common error which usually means you've forgotten a closing bracket, quote etc. However, I can't see anything like that missing here, and also if that were the case it'd would also error on my test server.

Could it be something further up the in the code - this is the last function on the page?

Sinister Beard
  • 3,570
  • 12
  • 59
  • 95
  • 4
    Probably you have different versions of PHP in your test and production servers, the production server's one being older. – Amarnasan Oct 02 '15 at 07:33
  • 2
    The issue is different php vesions support for the array short cut –  Oct 02 '15 at 07:34

1 Answers1

1

Check your PHP version. Calling a array member right out of a function is hint for bugs like that. I think, your php versions differ.

Paladin
  • 1,637
  • 13
  • 28
  • Yep, that got it - changed it to `$first_name = explode(" ",$full_name ); $first_name = $first_name[0];` and if works fine now. – Sinister Beard Oct 02 '15 at 07:38