0

I run the following PHP-code:

$client = new SoapClient("https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");

var_dump($client->checkVat(array(
  'countryCode' => 'BE',
  'vatNumber' => '0861091467'
)));

foreach ($client as $key => $value) {
   echo $key . ' = ' . $value . "\n";
}

It procudes the following output on screen:

object(stdClass)#2 (6) {
  ["countryCode"]=>
  string(2) "BE"
  ["vatNumber"]=>
  string(10) "0861091467"
  ["requestDate"]=>
  string(16) "2021-03-10+01:00"
  ["valid"]=>
  bool(true)
  ["name"]=>
  string(8) "BV myKMO"
  ["address"]=>
  string(26) "Kapellebaan 55
2560 Nijlen"
}
_soap_version = 1
sdl = Resource id #2
httpsocket = Resource id #3
_use_proxy = 0
httpurl = Resource id #4

Then how can we store "BV myKMO" in a one-dimensional variable ? I'm looking for something like

$varname = $client->sdl->name;

Thank you,

11
  • 3
    Your var_dump and foreach output are totally different and neither shows the sdl property. Commented Mar 10, 2021 at 13:30
  • and the following loop...would produce...not from the previous data you showed, it wouldn't. If you're going to use examples that's great, but please at least check that they make sense before posting them :-) Commented Mar 10, 2021 at 13:33
  • echo $myvar->name; should be what you need to in order to refer to the value. It's unclear where sdl comes into it. Simple demo: sandbox.onlinephpfunctions.com/code/… Commented Mar 10, 2021 at 13:34
  • 1
    Your issue is that $client doesn't contain the data. It contains your SOAP client. Your data is contained in the object returned by the call to the checkVat() function...but you're only feeding that to var_dump, you aren't retaining it for later use. And I still have no idea why you think sdl is relevant to anything, it's unclear what's in it just from that foreach output. (why you didn't var_dump($client) too for your debugging instead of using foreach, I don't understand). Commented Mar 10, 2021 at 14:53
  • 1
    Try this: $result = $client->checkVat(array( 'countryCode' => 'BE', 'vatNumber' => '0861091467' )); echo $result->name; Commented Mar 10, 2021 at 14:54

1 Answer 1

1

Your issue is that $client doesn't contain the data. It merely contains your SOAP client - i.e. it contains functions which enable you to request data from the server, but not the data which is obtained from executing those requests.

The result data you want is contained in the object returned by the call to the checkVat() function...but you're only feeding that to var_dump, you aren't retaining it for later use.

Try this instead:

$result = $client->checkVat(array( 'countryCode' => 'BE', 'vatNumber' => '0861091467' )); 
echo $result->name;
Sign up to request clarification or add additional context in comments.

Comments

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.