PHP object iteration

I run the following PHP-code:

$client = new SoapClient("");

  'countryCode' => 'BE',
  'vatNumber' => '0861091467'

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

It procudes the following output on screen:

object(stdClass)#2 (6) {
  string(2) "BE"
  string(10) "0861091467"
  string(16) "2021-03-10+01:00"
  string(8) "BV myKMO"
  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,


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;

Leave a Reply

Your email address will not be published. Required fields are marked *