简体   繁体   English

PHP:致命错误:找不到“SoapClient”类

[英]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.首先,我已经阅读了这个问题( 致命错误:未找到类“SoapClient” )并且已经完成了答案所说的一切。 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.我在这里也发现了类似的问题( https://bugs.php.net/bug.php?id=64445 ),但它也没有在那里解决。

I'm trying to set up a PHP + Apache environment on Win 7 64.我正在尝试在 Win 7 64 上设置 PHP + Apache 环境。

  1. PHP : php-5.5.17-Win32-VC11-x86. PHP :php-5.5.17-Win32-VC11-x86。 Thread safe.线程安全。

  2. Apache : httpd-2.4.10-win32-VC11阿帕奇:httpd-2.4.10-win32-VC11

So, here is my C:\\PHP\\php.ini for SOAP.所以,这是我用于 SOAP 的C:\\PHP\\php.ini 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 .C:/PHP/ext文件夹中,我有php_soap.dll文件, C:\\PHP\\ext\\php_soap.dll

But my phpinfo();但是我的phpinfo(); returns ONLY this about SOAP:返回有关 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.我认为您使用 Symfony2 并使用名称空间。 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.例如,您对Exception类有同样的问题。

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如果您使用的是 linux 并且您缺少 soap 扩展名,就像我一样,并且您已经在 php.ini 中启用了它,然后尝试

apt-get install php-soap
service apache2 restart

I had the same issue in a custom module Drupal 8.我在自定义模块 Drupal 8 中遇到了同样的问题。

It uses Symfony2 so just add this in controller :它使用 Symfony2,所以只需在控制器中添加:

use SoapClient;

in PHP/7.4.11 Server在 PHP/7.4.11 服务器中

In XAMPP Control Panel在 XAMPP 控制面板中

  1. Stop Apache Server停止 Apache 服务器
  2. Click on Config next to Apache单击Apache旁边的配置
  3. From dropdown select PHP (php.ini)从下拉列表中选择 PHP (php.ini)
  4. Ctrl+F to find ;extension=soap and remove ; Ctrl+F 查找;extension=soap并删除 ; from the line.从线。
  5. Ctrl+S to save the file. Ctrl+S 保存文件。
  6. Start Apache again.再次启动Apache。

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:phpinfo()您可以看到以下重要行:

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:但是如果需要,您可以在 httpd.conf 中更改 ini 文件夹:

# 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.这也可以配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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