I have two servers. They are both running php 5.3.3. This code works on one server and returns a syntax error on the other. Is there a php ini setting that affects this behaviour? I can’t find anything related in the PHP documentation, but I may be looking in the wrong place.
> php -v PHP 5.3.3 (cli) (built: Sep 23 2010 14:15:16) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Xdebug v2.0.3, Copyright (c) 2002-2007, by Derick Rethans php > echo explode(" ", " foo "); foo
> php -v PHP 5.3.3 (cli) (built: Jan 31 2011 15:57:29) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies php > echo explode(" ", " foo "); Parse error: syntax error, unexpected '[', expecting ',' or ';' in php shell code on line 1
Another idea: PHP on both servers is custom-compiled, so it could also be a different compile flag.
PHP doesn’t support this syntax. It’s on the trunk, but not yet released (as of PHP 5.3.3).
I have no idea how it’s working on your first server, but perhaps this “Xdebug” is making a difference?
Aha! I figured it out.
We installed Facebook’s XHP to profile our development server. This syntax (which is quite elegant) was added in in the PHP module. Here’s a diff of the php.ini file between server 1 and 2:
> ; XHP https://github.com/facebook/xhp/wiki/Building-XHP > extension=xhp.so > ; adds support for the  operator on the return value of a function > xhp.idx_expr = 1 > ; Tracking errors in XHP applications is very difficult without annotations. > xhp.include_debug = 1
I like this syntax, so I’ll probably install XHP on the other server. Thanks for the help Michas for suggesting I diff the ini files.