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. Inside that WSDL is defines an object called Favorite that has 5 members. I开发者_运维知识库s 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.
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);
精彩评论