1

I have 3 classes: server, client, service. used to implement a SOAP web service.

The service constructs an associative array, then passes it to the client which finally passes it to the server. And a response is sent back.

Relevant code:

service.php

<?php
include './client.php';

$id_array = array("country_code"=> "+36");
echo $client->getName($id_array);
?>

client.php

public function getName($id_array)
{
    return $this->instance->__soapCall('getCountryName', $id_array);
}

and server.php

public function getCountryName($id_array)
    {
    $country_code = array();

    $country_code = $id_array['country_code'];
//this return value to debug (not actual function)
    return $country_code;
}

The problem occurs at: $country_code = $id_array['country_code']; At which point $country_code is given the value +, instead of +36.

Why is that happening?

P.S. __soapCall passes the $id_array to the function getCountryName() in server.php Also, everything works as intended if I use $country_code of length 1.

2
  • Without the code for __soapCall() there is no way to see what happens to $id_array. The rest of the code does not do anything wrong with it. Commented Jun 14, 2016 at 15:41
  • @DennisB. php.net/manual/en/soapclient.soapcall.php ;) Commented Jun 14, 2016 at 15:45

1 Answer 1

2

I'm not a SOAP user, but I believe __soapCall('getCountryName', $id_array) should be __soapCall('getCountryName', array($id_array)).

Why? Because each array index gets mapped to a param in the server method that gets called.

So, I think that in the server method, $id_array's value is the first character of the country code string, if you added an $id_array2 in the method param list, it would probably be the second in the string.

If that's the case, you're probably surpressing notices / warnings (check your errors logs) complaining about an illegal offset.

Sign up to request clarification or add additional context in comments.

1 Comment

@Airwavezx You can thank him by upvoting and accept his answer .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.