我在PHP5中为我的SOAPClient添加了一个压缩选项,我收到了这条消息。
为什么呢?我见过很多使用完全相同语法的例子。
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5
返回:
Parse error: syntax error, unexpected '|', expecting ')' in /home/absolute/public_html/book/bin/class/wsdl.class.php on line 5042
选项数组
$options = array( 'cache_wsdl' => 0,'trace' => 1,'encoding' => 'utf-8','soap_version' => SOAP_1_2,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5 )
public function WEBService($wsdl = "x.x.x.x/Service.asmx?wsdl", $options = array( 'cache_wsdl' => 0,
'trace' => 1,
'encoding' =>'utf-8',
'soap_version' => SOAP_1_2,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5 ))
{
// some class mapping and other wonderful things going on
}
答案 0 :(得分:4)
问题与SOAP无关。在这个简化的测试用例中见证了同样的错误:
function foo($x = 1 | 2) {}
Quoth the documentation:
默认值必须是常量表达式,而不是(例如)变量,类成员或函数调用。
虽然SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5
在“编译”时可以有效地保持常量,但PHP显然不会进行这样的常量折叠,因此会对非常量表达式产生阻塞。
您之前已经看过这样的代码,而不是函数参数的默认值。一个简单的方法是将arg默认为false
或null
,然后在函数测试的主体中为此指定并分配所需的值。
答案 1 :(得分:0)
你只需要括号:
'compression' => (SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5)
由于运营商优先权。