Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

SOAPFault When Switching PHP Versions

DZone's Guide to

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 ·
Free Resource

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

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!

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

Topics:
php ,soap ,php 7

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}