简体   繁体   中英

PHP: Fatal error: Class 'SoapClient' not found

First of all, I've read this question ( Fatal error: Class 'SoapClient' not found ) and have everything done the answer says. But still experience an issue.

I also found similar issue here ( https://bugs.php.net/bug.php?id=64445 ) but it is not solved there too.

I'm trying to set up a PHP + Apache environment on Win 7 64.

  1. PHP : php-5.5.17-Win32-VC11-x86. Thread safe.

  2. Apache : httpd-2.4.10-win32-VC11

So, here is my C:\\PHP\\php.ini for SOAP. Everything is set correctly:

extension=php_soap.dll

; Directory in which the loadable extensions (modules) reside.
; On windows:
extension_dir = "C:/PHP/ext"

[soap]
; Enables or disables WSDL caching feature.
; http://php.net/soap.wsdl-cache-enabled
soap.wsdl_cache_enabled=1

; Sets the directory name where SOAP extension will put cache files.
; http://php.net/soap.wsdl-cache-dir
soap.wsdl_cache_dir="/tmp"

; (time to live) Sets the number of second while cached file will be used
; instead of original one.
; http://php.net/soap.wsdl-cache-ttl
soap.wsdl_cache_ttl=86400

; Sets the size of the cache limit. (Max. number of WSDL files to cache)
soap.wsdl_cache_limit = 5

In C:/PHP/ext folder I have php_soap.dll file, C:\\PHP\\ext\\php_soap.dll .

But my phpinfo(); returns ONLY this about SOAP:

在此处输入图片说明

I DO NOT have these settings shown:

在此处输入图片说明

And I get error:

Fatal error: Class 'SoapClient' not found in C:\Apache24\htdocs\myApp\src\Em\Bundle\PlatformBundle\Services\MyAppService.php on line 46

What did I miss? How to solve it?

This is very easy.

You work with Symfony2 i think and you use namespaces. This function is in the Root-Namespace.

use:

\SoapClient()

Otherwise you are in the namespace and they can't find the class.

You have the same Problem with the Exception class for example.

If you are on linux and you are missing the soap extension, like I was and you have already enabled it in php.ini then try

apt-get install php-soap
service apache2 restart

I had the same issue in a custom module Drupal 8.

It uses Symfony2 so just add this in controller :

use SoapClient;

in PHP/7.4.11 Server

In XAMPP Control Panel

  1. Stop Apache Server
  2. Click on Config next to Apache
  3. From dropdown select PHP (php.ini)
  4. Ctrl+F to find ;extension=soap and remove ; from the line.
  5. Ctrl+S to save the file.
  6. Start Apache again.

this steps solved my problem.

Try config the extension using the path:

extension=ext/php_soap.dll

In phpinfo() you can see this important lines:

Configuration File (php.ini) Path   C:\WINDOWS
Loaded Configuration File   C:\Apache24\bin\php.ini 

But you can change the ini folder if desire in httpd.conf:

# configure the path to php.ini
#PHPIniDir "C:/php"

BUT SEE what extension dir are you using:

extension_dir   C:\php

In the "Core" section. This can be configured too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM