以下划线开头的PHP SOAP操作

问题描述 投票:2回答:3

使用PHPs SOAP实现,我不能从WDSL调用方法,如果它们以下划线开头。即:

$result = $server->_-testing_-getPrices(array('Receiver'=>'John'));

不工作!

然而,

$result = $server->getPrices(array('Receiver'=>'John'));

然而,按预期工作,我请求的SOAP服务器没有此操作。 PHP使用FIRST ONE发出的错误是:

Notice: Undefined property: SoapClient::$_ in D:\SERVER\www\test123.php on line 4

Notice: Use of undefined constant testing_ - assumed 'testing_' in D:\SERVER\www\test123.php on line 4

Fatal error: Call to undefined function getPrices() in D:\SERVER\www\test123.php on line 4

这是恕我直言的一个错误,或者有谁知道如何解决这个问题?

php soap identifier
3个回答
2
投票

PHP的函数不能在其名称中包含-http://www.php.net/manual/en/functions.user-defined.php。所以,你必须使用它来调用你的方法:http://www.php.net/manual/en/soapclient.soapcall.php

$result = $server->__soapCall('_-testing_-getPrices',array('Receiver'=>'John'));

2
投票

我很确定问题不是qazxsw poi(下划线),而是qazxsw poi(减号) - 你的线被视为数学运算,如下所示:

_

显然没有任何意义(在这里你看到为什么php试图将-视为一个未定义的常量)。只需将您的功能从$result = $server->_ - testing_ - getPrices(array('Receiver'=>'John')); 重命名为testing_,它就会按预期工作。

有关更多信息,请查看_-testing_-getPrices获取有效的函数名称(也适用于对象的方法):

函数名称遵循与PHP中其他标签相同的规则。有效的函数名称以字母或下划线开头,后跟任意数量的字母,数字或下划线。作为正则表达式,它将表示为:[a-zA-Z_ \ x7f- \ xff] [a-zA-Z0-9_ \ x7f- \ xff] *。


0
投票

你的问题不是下划线,而是跟随它的破折号。 PHP命名约定阻止它成为有效的方法名称,许多其他语言也是如此,并且服务的设计者在使用它们时犯了一个根本错误。

PHP应该基于此创建有效的函数名称,我猜它会将_testing_getPrices转换为the documentation

尝试:

-

调用_方法可能会显示您需要使用,尽管我不确定这是否会返回PHP函数名称或服务逐字定义的名称。

© www.soinside.com 2019 - 2024. All rights reserved.