是否有一个PHP设置可以设置是否可以对函数的结果进行索引


Is there a PHP setting that sets whether you can index the result of a function?

我有两个服务器。它们都在运行php 5.3.3。此代码在一台服务器上工作,在另一台服务器返回语法错误。是否存在影响此行为的php.ini设置?我在PHP文档中找不到任何相关内容,但我可能找错地方了。

服务器1

> 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 ")[1];
foo

服务器2

> 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 ")[1];
Parse error: syntax error, unexpected '[', expecting ',' or ';' in php shell code on line 1

另一个想法是:两台服务器上的PHP都是自定义编译的,所以它也可以是不同的编译标志。

否。

PHP不支持这种语法。它在主干上,但尚未发布(截至PHP 5.3.3)。

我不知道它在你的第一台服务器上是如何工作的,但也许这个"Xdebug"会有所不同?

啊哈!我想明白了。

我们安装了Facebook的XHP来配置我们的开发服务器。这个语法(非常优雅)是在PHP模块中添加的。以下是php.ini文件在服务器1和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

我喜欢这种语法,所以我可能会在另一台服务器上安装XHP。感谢Michas的帮助,他建议我对ini文件进行区分。