You are right, the manual explains the exact difference in theory a little vaguely, and I was surprised that so far no one has provided any detailed information or an explanation of their differences.
According to instructions
SoapParam:
Represents a parameter to invoke SOAP.
SoapVal:
A class that represents a variable or object for use with SOAP services.
I went down a bit, and the main difference that I could find was the data parameter in their representative constructors:
for SoapParam::SoapParam ( mixed $data, string $name ) where $data =
Data for transfer or return. This parameter can be passed directly as a PHP value, but in this case it will be named as paramN, and the SOAP service may not understand it.
on the other hand, we have SoapVar::SoapVar ( mixed $data, string $encoding [, string $type_name [, string $type_namespace [, string $node_name [, string $node_namespace ]]]] ) where $data =
Data for transfer or return.
Given these two aspects, an example in the PHP manual, I think that the main thing points to the main difference in passing arguments and what you can do with one that cannot be done with the other.
In the case of SoapParam
<?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")); ?>
where $a , $b and $c are PHP variables sent directly, without passing them through a structure / class. The SaopParam constructor receives the $data parameter (a PHP variable) and a String representing the parameter name.
SoapVar on the other hand
<?php class SOAPStruct { function SOAPStruct($s, $i, $f) { $this->varString = $s; $this->varInt = $i; $this->varFloat = $f; } } $client = new SoapClient(null, array('location' => "http://localhost/soap.php", 'uri' => "http://test-uri/")); $struct = new SOAPStruct('arg', 34, 325.325); $soapstruct = new SoapVar($struct, SOAP_ENC_OBJECT, "SOAPStruct", "http://soapinterop.org/xsd"); $client->echoStruct(new SoapParam($soapstruct, "inputStruct")); ?>
As you can see, arguments / variables are passed through a certain class even after an object of this class is passed as an argument. This class is a representative of the SOAP structure (this SOAP can recognize / evaluate risk using SoapParam).
Now the almost confusing part ... although there are several differences in the constructor, why is this behavior in your example?
$soapVar = new SoapVar((object) ['Foo' => 'bar'], null, null, null, 'TagName'); $soapParam = new SoapParam((object) ['Foo' => 'bar'], 'TagName');
I'm not surprised, as mentioned above, the data of either the SOAP structure or the CORRECT Soap Structure PHP variable is the same :) thanks to the Object-Oriented, we pass the object created by the PHP class. In SoapVar the object design has more options, which allows the user to adapt a more "secure" request to a SOAP call. Being in SoapParam an object can be created by passing any object and the name following it.
Your (object) ['Foo' => 'bar'] very simple and does not need to encode an XML schema, so it seems to me that receiving a SOAP call can easily understand this. It is not necessary for
Encoding identifier, one of the XSD _... constants
this is the second parameter in the SoapVar constructor.
Finally, since they both accept an object (any object) instead of the $data variable, as I understand it, SoapVar just makes it possible to build a more secure request, which will be understood by calling SOAP through additional arguments in the constructor. SoapParam is just a badass and allows you to send whatever you like, with the risk that SOAP will refuse it .... it almost wants to act like JSON @RESTful: P doesn't care about the type and structure of the data it sends :)
Recommendations: