About passing the values by reference:
function test_reference_in(&$array) {
$array['a'] = 2;
}
$test_array['a'] = 1;
test_reference_in($test_array);
echo $test_array; //-> it prints 2
About nusoap:
Now in nusoap
the client class is nusoap_client
.
In that class you have nusoap_client::call()
to make the soap call.
This is what appen in nusoap_client::call()
to the array $params
which is your $sendParams
in your example.
I'm going to omit all the rest of the method that is not related to $params
to explain better what's going on.
/**
* Pseudocode of call to explain the operations on $params
* @see nusoap_client::call()
*/
function call($operation,$params=array(),$namespace='http://tempuri.org',$soapAction='',$headers=false,$rpcParams=null,$style='rpc',$use='encoded'){
/*
some code
.
.
.
*/
// varDump is just var_dump so print $params
$this->appendDebug('params=' . $this->varDump($params));
/*
some code
.
.
.
*/
/*
* Here $params has been read, no write operation in there
* about serializeRPCParameters @see class.wsdl.php again is just reading
*/
if (is_string($params)) {
$this->debug("serializing param string for WSDL operation $operation");
$payload = $params;
} elseif (is_array($params)) {
$this->debug("serializing param array for WSDL operation $operation");
$payload = $this->wsdl->serializeRPCParameters($operation,'input',$params,$this->bindingType);
} else {
$this->debug('params must be array or string');
$this->setError('params must be array or string');
return false;
}
/*
* Here again $params has been read, no write operation in there
*/
if (is_string($params)) {
$this->debug("serializing param string for operation $operation");
$payload = $params;
} elseif (is_array($params)) {
$this->debug("serializing param array for operation $operation");
foreach($params as $k => $v){
$payload .= $this->serialize_val($v,$k,false,false,false,false,$use);
}
} else {
$this->debug('params must be array or string');
$this->setError('params must be array or string');
return false;
}
}
So as you can see here there are no advantages to pass $params by reference.
Because:
- $params is not modified in any way in nusoap_client::call()
- Even if you modify $params somewhere else after you have to use again nusoap_client::call()
What if you want to pass $params by reference in any case? Can I do it?
Well yes you can!
To achieve that you have to copy nusoap_client.php
and call it nusoap_client_new.php
.
In there modify the class name form nusoap_client
to nusoap_client_new
.
// From this
class nusoap_client extends nusoap_base {
// To this
class nusoap_client_new extends nusoap_base {
Modify the nusoap_client_new::call()
method adding the ref in params like this :
/*
* Please note &$params=array() instead of $params=array()
*/
function call($operation,&$params = array(),$namespace='http://tempuri.org',$soapAction='',$headers=false,$rpcParams=null,$style='rpc',$use='encoded'){
/**
* Of course here you have to modify your code to make some operation on $params
* according to your needs.
*/
/*
original code
.
.
.
*/
}
At the end update your code to require and use nusoap_client_new::call()
instead of nusoap_client::call()
.