更新magento 2.4.2 错误 PHP Fatal error:  Declaration of Psr\Log\LoggerInterface\Proxy::emergency 问题解决

46 篇文章 2 订阅
20 篇文章 0 订阅

目录

问题:PHP Fatal error:  Declaration of Psr\Log\LoggerInterface\Proxy::emergency($message, array $context)

解决办法

1、在app目录下新建psrfix.php文件

 2、修改composer.json

3、更新 composer 的 autoload_files.php 文件

更新Magento2.4.2时一些坑的修复记录:

1.Your requirements could not be resolved to an installable set of packages.

2.composer update更新一直没有反应


问题:PHP Fatal error:  Declaration of Psr\Log\LoggerInterface\Proxy::emergency($message, array $context)

更新到magento 2.4.2 错误提示:PHP Fatal error:  Declaration of Psr\Log\LoggerInterface\Proxy::emergency($message, array $context)

PHP Fatal error:  Declaration of Psr\Log\LoggerInterface\Proxy::emergency($message, array $context) must be compatible with Psr\Log\LoggerInterface::emergency($message, array $context = Array) in /www/wwwroot/magento/generated/code/Psr/Log/LoggerInterface/Proxy.php on line 7

这是由于PHP版本问题,参考https://github.com/jbboehr/php-psr/issues/78 

修改generated/code/Psr/Log/LoggerInterface/Proxy.php代码只能临时解决,只要刷新后文件就会被恢复,不能解决问题

官网安装说明要PHP7.4.0版本:https://devdocs.magento.com/guides/v2.4/install-gde/system-requirements.html  ,哪就先更新PHP吧参考 ubuntu 20 php-7.4.15 编译安装

编译安装好后测试了好几个版本还是不行,不能再耗下去了,先临时写个类来解决问题。

解决办法

1、在app目录下新建psrfix.php文件

内容如下:参考https://github.com/jbboehr/php-psr/issues/78#issuecomment-722290110

<?php
namespace Psr\Log\LoggerInterface;

/**
 * Proxy class for @see \Psr\Log\LoggerInterface
 */
class Proxy implements \Psr\Log\LoggerInterface, \Magento\Framework\ObjectManager\NoninterceptableInterface
{
    /**
     * Object Manager instance
     *
     * @var \Magento\Framework\ObjectManagerInterface
     */
    protected $_objectManager = null;

    /**
     * Proxied instance name
     *
     * @var string
     */
    protected $_instanceName = null;

    /**
     * Proxied instance
     *
     * @var \Psr\Log\LoggerInterface
     */
    protected $_subject = null;

    /**
     * Instance shareability flag
     *
     * @var bool
     */
    protected $_isShared = null;

    /**
     * Proxy constructor
     *
     * @param \Magento\Framework\ObjectManagerInterface $objectManager
     * @param string $instanceName
     * @param bool $shared
     */
    public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = '\\Psr\\Log\\LoggerInterface', $shared = true)
    {
        $this->_objectManager = $objectManager;
        $this->_instanceName = $instanceName;
        $this->_isShared = $shared;
    }

    /**
     * @return array
     */
    public function __sleep()
    {
        return ['_subject', '_isShared', '_instanceName'];
    }

    /**
     * Retrieve ObjectManager from global scope
     */
    public function __wakeup()
    {
        $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    }

    /**
     * Clone proxied instance
     */
    public function __clone()
    {
        $this->_subject = clone $this->_getSubject();
    }

    /**
     * Get proxied instance
     *
     * @return \Psr\Log\LoggerInterface
     */
    protected function _getSubject()
    {
        if (!$this->_subject) {
            $this->_subject = true === $this->_isShared
                ? $this->_objectManager->get($this->_instanceName)
                : $this->_objectManager->create($this->_instanceName);
        }
        return $this->_subject;
    }

    /**
     * {@inheritdoc}
     */
    public function emergency($message, array $context = [])
    {
        return $this->_getSubject()->emergency($message, $context);
    }

    /**
     * {@inheritdoc}
     */
    public function alert($message, array $context = [])
    {
        return $this->_getSubject()->alert($message, $context);
    }

    /**
     * {@inheritdoc}
     */
    public function critical($message, array $context = [])
    {
        return $this->_getSubject()->critical($message, $context);
    }

    /**
     * {@inheritdoc}
     */
    public function error($message, array $context = [])
    {
        return $this->_getSubject()->error($message, $context);
    }

    /**
     * {@inheritdoc}
     */
    public function warning($message, array $context = [])
    {
        return $this->_getSubject()->warning($message, $context);
    }

    /**
     * {@inheritdoc}
     */
    public function notice($message, array $context = [])
    {
        return $this->_getSubject()->notice($message, $context);
    }

    /**
     * {@inheritdoc}
     */
    public function info($message, array $context = [])
    {
        return $this->_getSubject()->info($message, $context);
    }

    /**
     * {@inheritdoc}
     */
    public function debug($message, array $context = [])
    {
        return $this->_getSubject()->debug($message, $context);
    }

    /**
     * {@inheritdoc}
     */
    public function log($level, $message, array $context = [])
    {
        return $this->_getSubject()->log($level, $message, $context);
    }
}

 2、修改composer.json

...
"autoload": {
      ...
        "files": [
            "app/etc/NonComposerComponentRegistration.php",
            "app/psrfix.php"
        ],
...

 

3、更新 composer 的 autoload_files.php 文件

composer dump-autoload

 


更新Magento2.4.2时一些坑的修复记录:

1.Your requirements could not be resolved to an installable set of packages.

运行composer update 提示Your requirements could not be resolved to an installable set of packages.

查看magento/magento2-functional-testing-framework新版本

composer show magento/magento2-functional-testing-framework 3.*.* --all | grep -m 1 versions

 打开composer.json修改magento/magento2-functional-testing-framework版本成3.2.1

2.composer update更新一直没有反应

composer update

发现更新一直没有反应,ctrl+c结束进程加-vvv的方式来运行

composer update -vvv

 我这里有发现因为friendsofphp/php-cs-fixer导致一直重试。试了几个版本多不行,后改成^2.14.0可以过了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值