2

嗨,我对 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
4

2 回答 2

1

我刚搬到 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

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

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

然后php composer.phar update

于 2015-01-28T14:49:12.750 回答
0

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

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

(...)
    "zendframework/zendframework": "2.4.*",
(...)
于 2021-11-18T15:58:45.893 回答