在 PHP 中创建在 WSDL 文件中定义的类的实例

发布于 2024-10-07 05:28:14 字数 206 浏览 0 评论 0原文

我正在使用 PHP 中的 WSDL 和默认的 SoapClient 对象。在该 WSDL 内部定义了一个名为“Favorite”的对象,它有 5 个成员。有没有一种方法可以在 PHP 中创建该类的实例,因为该 WSDL 的某些方法要求我将该对象传递给它。我尝试过:

$favorite = new favorite();

在我学习了 WSDL 之后,但这不起作用。

I am consuming a WSDL in PHP with the default SoapClient object. Inside that WSDL is defines an object called Favorite that has 5 members. Is there a way I can create and instance of the class in PHP as some fo the method of that WSDL required me to pass that object to it. I have tried:

$favorite = new Favorite();

after I have comsumed the WSDL but that did not work.

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

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

发布评论

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

评论(1

红衣飘飘貌似仙 2024-10-14 05:28:14

您不能直接创建该类。通常,您只需创建一个具有对象正确属性的关联数组,PHP SoapClient 将完成剩下的工作。否则,请使用 SoapVar

$data = array(
    "abc" => 123,
    "xyz" => 456,
);
$ns = "http://example.com/soap/namespace";
$var = new SoapVar($data, SOAP_ENC_OBJECT, "Favorite", $ns);

You can't create the class directly. Usually, you can simply create an associative array with the correct properties for the object and the PHP SoapClient will do the rest. Otherwise, use SoapVar:

$data = array(
    "abc" => 123,
    "xyz" => 456,
);
$ns = "http://example.com/soap/namespace";
$var = new SoapVar($data, SOAP_ENC_OBJECT, "Favorite", $ns);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文