【问题标题】:Undefined type 'Psr\Log\LoggerInterface'未定义类型 'Psr\Log\LoggerInterface'
【发布时间】:2022-01-22 19:38:42
【问题描述】:

我正在寻找解决此问题的方法 我使用 php 7.4,这个错误在 phpMailer 文件夹中的 SMTP.php 我的代码:

 //Is this a PSR-3 logger?
    if ($this->Debugoutput instanceof \Psr\Log\LoggerInterface) {
        $this->Debugoutput->debug($str);
        return;
    }

这个错误: Undefined type 'Psr\Log\LoggerInterface

【问题讨论】:

  • 是的,这是一个 PSR-3 记录器接口,您可以通过 composer 安装 psr/log 包来解决问题

标签: php smtp phpmailer


【解决方案1】:

首先这不应该是一个错误。当使用instanceOf 时,您正在检查的类不需要存在,就像它也不需要存在于use 语句中一样。例如:

$a = 1;
if ($a instanceOf \Cocktails\Gin\Tonic) {
    echo 'true';
} else {
    echo 'false';
}
exit;

这只会显示 false,即使它要查找的类没有定义也不会产生错误 - 它只是意味着 instanceOf 检查将由于不同的原因而失败。

【讨论】:

    【解决方案2】:

    似乎 Visual Studio Code 没有看到您的供应商文件夹,或者您没有通过 composer 安装 psr/log 包。

    尝试运行命令

    composer require psr/log
    

    为了获得 PSR-3 接口

    【讨论】:

      猜你喜欢
      • 2015-08-23
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      相关资源
      最近更新 更多