Over a million developers have joined DZone.

SOAPFault When Switching PHP Versions

While updating her PHP Web Services book, Lorna Mitchell ran into an interesting bug with a very simple SOAP example. See how this odd bug was found and fixed.

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

I'm working on an update to my PHP Web Services book and with PHP 7 likely to release before the book even makes it into print, I'm testing all my example code across PHP 5.6 and PHP 7... which today gave me a weird problem with a very, very simple SOAP example.

<?php

$client = new SoapClient('http://api.radioreference.com/soap2/?wsdl&v=latest');

$countries = $client->getCountryList();
print_r($countries);

This example works fine with PHP 5 but when I ran it with PHP 7 (after realising I needed to recompile with --enable-soap), I got this error:

Fatal error: Uncaught SoapFault exception: [Client] Function ("getCountryList") is not a valid method for this service ...

Hmm. So I complained about it on IRC and someone else tried it on 7 and said it worked fine (thanks @akrabat) but that it didn't work under 5.6 for him.

I can only speculate about what changed between versions and it's probably a good thing, whatever it is, but it seems like once the WSDL is cached locally from one version of PHP, it makes no sense with the other version. To fix it, disable the WSDL cache:

ini_set("soap.wsdl_cache_enabled", "0");

This worked for me, and I am not sure how I would have found a strange SOAP fault between PHP versions other than by a lucky help from someone else, so it's here in the hope that it saves time for someone else too!

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:
php ,soap ,php 7

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}