Monday, October 6, 2008

How To Make NuSOAP Work With PHP 5

NuSOAP is a very usefull SOAP Toolkit for developing web service with PHP. You won't have any problem when using it with PHP 4. But, if you are using PHP 5, you might find a little problem. PHP 5 has its own SOAP extension, so if that SOAP extension is loaded it will conflict with NuSOAP and you will get an error message like this:

Fatal error: Cannot redeclare class soapclient in C:\xampp\htdocs\lib\nusoap.php on line 7240

There are two alternatives to solve this problem.

First Alternative

You can de-activated PHP SOAP extension by editting the php.ini file. Give a semicolon (;)  in the front of the line says extension=php_soap.dll. So, that line should be look like this:

;extension=php_soap.dll

Restart your web server to make the change take effect.


Second Alternative

You can also modify the nusoap.php file to rename the soapclient class to another name like soap_client.  You can use your favorite text editor and replace all soapclient text with soap_client. So, if you want to make an instance from NuSOAP client you have to use the syntax like this:

$client=new soap_client($url);

This way is good if you want to use NuSOAP but you still want to retain the PHP SOAP extension.