简体   繁体   English

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

[英]Create an instance of a class in PHP that is defined in a WSDL file

I am consuming a WSDL in PHP with the default SoapClient object. 我在PHP中使用带有默认SoapClient对象的WSDL。 Inside that WSDL is defines an object called Favorite that has 5 members. 在WSDL中定义了一个名为Favorite的对象,该对象具有5个成员。 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. 有没有一种方法可以用PHP创建类的实例,就像该WSDL方法要求我将该对象传递给它那样。 I have tried: 我努力了:

$favorite = new Favorite(); $ favorite = new Favorite();

after I have comsumed the WSDL but that did not work. 在我弄清楚了WSDL之后,那还是行不通。

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. 通常,您可以简单地为对象创建具有正确属性的关联数组,其余的工作由PHP SoapClient完成。 Otherwise, use SoapVar : 否则,请使用SoapVar

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM