以下划线开头的 PHP SOAP 操作

发布于 2024-12-27 20:48:12 字数 663 浏览 0 评论 0原文

使用 PHP SOAP 实现,我无法从 WDSL 调用方法(如果它们以下划线开头)。即:

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

不起作用!

然而,

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

按预期工作,但是,我请求的 SOAP 服务器没有此操作。 PHP 在第一个错误中吐出的错误是:

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

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

With PHPs SOAP implementation, I can't call methods from the WDSL, if they start with an underscore. I.e.:

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

DOESN'T WORK!

However,

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

WORKS AS EXPECTED, however, the SOAP server i'm requesting to doesn't have this operation. The error that PHP spits out with the FIRST ONE is:

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

This is IMHO a bug, or does anyone know how to go around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

孤独陪着我 2025-01-03 20:48:12

PHP 函数的名称中不能包含 -http ://www.php.net/manual/en/functions.user-define.php
因此,您必须使用它来调用您的方法: http://www.php .net/manual/en/soapclient.soapcall.php

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

PHP's functions cannot contain - in their names: http://www.php.net/manual/en/functions.user-defined.php .
So, you have to use this to call your method: http://www.php.net/manual/en/soapclient.soapcall.php

$result = $server->__soapCall('_-testing_-getPrices',array('Receiver'=>'John'));
猛虎独行 2025-01-03 20:48:12

我很确定问题不是 _ (下痛)而是 - (减号) - 你的行被视为这样的数学运算:

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

这显然不'这是没有意义的(在这里你可以看到为什么 php 尝试将 testing_ 视为未定义的常量)。只需将您的函数从 _-testing_-getPrices 重命名为 _testing_getPrices ,它就会按预期工作。

有关详细信息,请查看文档以获取有效信息函数名称(也适用于对象的方法):

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

i'm pretty sure the problem isn't the _ (undersore) but the - (minus) - your line is treated as mathematical operation like this:

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

wich clearly doesn't make sense (and here you see why php tries to treat testing_ as a constant wich isn't defined). just rename your function from _-testing_-getPrices to _testing_getPrices and it'll work as expected.

for more information, please take a look at the documentation for valid function-names (wich applies to methods of objects, too):

Function names follow the same rules as other labels in PHP. A valid
function name starts with a letter or underscore, followed by any
number of letters, numbers, or underscores. As a regular expression,
it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.

合久必婚 2025-01-03 20:48:12

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

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

尝试:

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

调用 __getFunctions() 方法可能表明您希望需要使用,尽管我不确定这是否返回 PHP 函数名称或由逐字服务。

Your problem is not the underscore, it is the dash that follows it. PHP naming conventions prevent this from being a valid method name, this is also true of many other languages and the designer of the service has made a fundamental error in using them.

PHP should have created valid function names based on this, and I'm guessing it will have converted the - to _.

Try:

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

Calling the __getFunctions() method may show you want you need to use, although I'm not sure if this returns the PHP function names or the ones defined by the service verbatim.

皇甫轩 2025-01-03 20:48:12

我知道我迟到了,但这可能会有所帮助&也工作

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

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

I know I am late but this might help & work too

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

// OR
$method = '_-testing_-getPrices';
$result = $server->$method(array('Receiver'=>'John'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文