©
本文檔使用 php中文網手册 發布
(PHP 5 >= 5.0.1)
SoapParam::SoapParam — SoapParam constructor
$data
, string $name
)Constructs a new SoapParam object.
data
The data to pass or return. This parameter can be passed directly as PHP value, but in this case it will be named as paramN and the SOAP service may not understand it.
name
The parameter name.
Example #1 SoapParam::SoapParam() example
<?php
$client = new SoapClient ( null ,array( 'location' => "http://localhost/soap.php" ,
'uri' => "http://test-uri/" ));
$client -> SomeFunction (new SoapParam ( $a , "a" ),
new SoapParam ( $b , "b" ),
new SoapParam ( $c , "c" ));
?>
[#1] lyroe_chan at hotmail dot com [2014-01-16 12:33:55]
If you want to create a SOAP parameter like:
<a n="something">DATA</a>
You can try like this:
array('a' => array('_' => 'DATA', 'n'=>'something'));
This will generated xml like this:
<a n="something">DATA</a>
[#2] mjordan at sfu dot ca [2013-11-15 00:52:18]
You can also pass parameters (at least simple ones) to SOAP functions like this:
<?php
$return = $client->someFunction(array('paramName' => 'paramValue'));
?>
[#3] Alex [2010-02-24 17:20:47]
You probably want to try SoapVar instead of SoapParam if you want to specify attributes/namespace.
[#4] Alex [2010-02-24 17:18:59]
Make sure to always cast your parameters prior to creating a SoapParam. Otherwise you will wind up with an incorrect xsi:type and possibly no value.
$value = 0;
$param0 = new SoapParam(
$value, $param0_name);
will give you:
<$param0_name xsi:type="xsd:null"></$param0_name>
while:
$value = 0;
$param0 = new SoapParam(
(int)$value, $param0_name);
<$param0_name xsi:type="xsd:int">0</$param0_name>
which is probably what you want.
[#5] barryking93 at gmail dot com [2007-12-05 14:42:21]
You have to use SoapVar instead of SoapParam if you want it to do something fancy like using different opening and closing tags. I ran into this using the SOAP API for Zimbra.
[#6] Jeremy [2007-07-12 08:31:50]
Is there anyway to create a SOAP parameter like:
<a n="something">DATA</a>
If I try to form a param using the following code the resulting request is:
Code: SoapParam("DATA", "a n=\"something\"");
Result: <a n="something">DATA</a n="something">
This is giving me an error from the SOAP server because its expecting a properly formed closing tag without the encapsulated attribute.