【问题标题】:Fatal Error, ArrayObject::offsetGet() must be compatible with that ArrayAccess:offsetGet() with Zend framework 2.3 on Linux Debian 2.6.32-46致命错误,ArrayObject::offsetGet() 必须与 ArrayAccess:offsetGet() 与 Linux Debian 2.6.32-46 上的 Zend framework 2.3 兼容
【发布时间】:2014-12-13 16:01:13
【问题描述】:

您好,我对 ZF2 有疑问,

当试图从浏览器访问公共/索引时,我从服务器收到了这个致命错误:

PHP Fatal error:  Declaration of Zend\\Stdlib\\ArrayObject::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in /var/www/somevirtualhost/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php on line 23

我已经从以下位置更新了 composer.json:

{
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
        "framework",
        "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.3.*"
    }
}

到:

{
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
        "framework",
        "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.2.*"
    }
}

我还在 init_autoloader.php 上添加了以下几行:

 require $zf2Path . '/Zend/Stdlib/compatibility/autoload.php';
 require $zf2Path . '/Zend/Session/compatibility/autoload.php';

这就是 init_autoloader 的样子:

if ($zf2Path) {
    if (isset($loader)) {
        $loader->add('Zend', $zf2Path);
        $loader->add('ZendXml', $zf2Path);
    } else {
        include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
        Zend\Loader\AutoloaderFactory::factory(array(
            'Zend\Loader\StandardAutoloader' => array(
                'autoregister_zf' => true
            )
        ));

        //Fix for PHP 5.3.3
        require $zf2Path . '/Zend/Stdlib/compatibility/autoload.php';
        require $zf2Path . '/Zend/Session/compatibility/autoload.php';
    }
}

除了上述所有更改之外,我仍然收到相同的错误。 顺便说一下,这是我的 PHP 版本:

PHP 5.3.3-7+squeeze19 with Suhosin-Patch (cli) (built: Feb 18 2014 13:59:15) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

【问题讨论】:

  • 从 2013 年 2 月起在 Github 上有一个已关闭的问题。它指出了完全相同的情况,似乎与作曲家自动加载过程有关。 github.com/zendframework/ZFTool/issues/26
  • 如果您尝试在太旧的 PHP 版本上运行 ZF 2.3,就会出现此错误。在更新 composer.json 以将其降回 2.2 后,你确定你运行了 composer update 吗?检查Zend\Version\Version.php 以查看您拥有的版本。
  • 正如@TimFountain 所说。 2.3.* 所需的最低 PHP 版本为 >=5.3.23。所以要么更新你的 PHP 环境,你必须使用 ZF 2.2.*
  • 问题已解决。 @TimFountain,确实我对作曲家进行了自我更新,但在 Zend\Version\Version.php 上,版本仍然相同:const VERSION = '2.3.1'。我要做的是再次下载最新的zendframework,将composer.json编辑为以前的2.2.*,然后执行自我更新和安装选项。

标签: php zend-framework2 debian arrayobject


【解决方案1】:

今天在做软件考古时,我在“ZF 2.2.x”和“ZF 2.3.x”都遇到了这个问题。使用“ZF 2.4.x”在黑暗中拍摄成功解决了这个问题。

我的项目的composer.json 被修改为使用这个:

(...)
    "zendframework/zendframework": "2.4.*",
(...)

【讨论】:

    【解决方案2】:

    我刚搬到 ZF 2.2 来修复

    Fatal error: Declaration of Zend\Stdlib\ArrayObject::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in /path/application/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php on line 22
    

    通过将 2.3 更改为 2.2 来编辑 composer.json

    "zendframework/zendframework": "2.2.*",
    

    然后php composer.phar update

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 2016-10-23
      • 1970-01-01
      • 2012-04-12
      • 1970-01-01
      相关资源
      最近更新 更多