我正在开发一个基于ZendFramework3.0的CMS,用Doctrine管理DB I。在使用composer管理包时,我的问题是什么?最近,我将所有的包更新为最新版本,并将其发送到服务器,其他文件中没有任何更改。更新后,我的站点显示了以下错误:
致命错误: Uncaught : Doctrine\Common\Annotations\AnnotationRegistry::registerLoader()的返回值必须是Doctrine\公用\TypeError\void的实例,没有在/home/platne/serwer18346/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:117堆栈跟踪中返回:#0 /home/platne/serwer18346/vendor/doctrine/doctrine-module/src/DoctrineModule/Module.php(57):Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(Object(Closure)) #1 /home/platne/serwer18346/vendor/zendframework/zend-modulemanager/src/Listener/InitTrigger.php(33):DoctrineModule\Module->init(Object(Zend\ModuleManager\ModuleManager)#2 /home/platne/serwer18346/vendor/zendframework/zend-eventmanager/src/EventManager.php(322):Zend\ModuleManager\Listener\InitTrigger->__invoke(Object(Zend\ModuleManager\ModuleEvent)) #3 /home/platne/serwer18346/vendor/zendframework/zend-eventmanager/src/EventManager.php(171):Zend\EventManager\EventManager->triggerListeners(Object(Zend\ModuleManager\ModuleEvent)) #4 / /home/platne/serwer18346/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php中的第117行
一些应用程序代码(如果需要):
单元:
return [
'Zend\Router',
'Zend\Validator',
'DoctrineModule',
'DoctrineORMModule',
'Core',
];Development.local(开发人员模式是活动的):
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => Doctrine\DBAL\Driver\PDOMySql\Driver::class,
'params' => [
'host' => '******',
'user' => '*******',
'password' => '******',
'dbname' => '*******',
'charset' => 'utf8'
]
]
]
]module.config:
'doctrine' => [
'driver' => [
__NAMESPACE__ . '_driver' => [
'class' => AnnotationDriver::class,
'cache' => 'array',
'paths' => [__DIR__.'/../src/Model']
],
'orm_default' => [
'drivers' => [
__NAMESPACE__ . '\Model' => __NAMESPACE__ . '_driver'
]
]
]
]控制员工厂:
public function __invoke(ContainerInterface $container,$requestedName, array $options = null)
{
$controllerInstance = null;
switch($requestedName){
case 'Core\Controller\IndexController': $controllerInstance = $this->_invokeIndex($container); break;
case 'Core\Controller\PagesController': $controllerInstance = $this->_invokePages($container); break;
}
return $controllerInstance;
}
protected function _invokeIndex(ContainerInterface $container)
{
return new Controller\IndexController(
$container->get('doctrine.entitymanager.orm_default')
);
}
protected function _invokePages(ContainerInterface $container)
{
return new Controller\PagesController(
$container->get('doctrine.entitymanager.orm_default')
);
}主计长家长:
protected $_entityManager;
/**
* AppController constructor.
* @param EntityManager $entityManager
*/
public function __construct(EntityManager $entityManager)
{
$this->_entityManager = $entityManager;
}
/**
* @return EntityManager
*/
public function getEntityManager()
{
return $this->_entityManager;
}正如我说过的,在更新之前,这段代码有效。更新后会显示错误,更重要的是,上传之前的版本后,错误仍然存在。我试着重写代码,但效果相同。
Composer(没有项目数据):
"require": {
"zendframework/zend-mvc": "*",
"zendframework/zend-developer-tools": "*",
"zendframework/zend-session": "*",
"zendframework/zend-authentication": "*",
"zfcampus/zf-development-mode": "*",
"doctrine/doctrine-orm-module": "*"
},
"autoload": {
"psr-4": {
"Core\\": "module/Core/src/"
}
}发布于 2017-07-27 15:33:37
由最新版本的Doctrine\Common\Annotations引起的错误使用PHP7.1。这就是为什么它使用void作为return type。而且PHP7.0.*不支持它。我是PHP7.1的新特性
我使用PHP7.0在我的doctrine-orm-module 1.1项目中使用ZF3。而且效果很好。所以,只需将doctrine-orm-module版本替换为1.1即可。
"doctrine/doctrine-orm-module": "^1.1"我建议您定义在composer中使用的依赖项的版本。这是为了使您的项目在新版本的依赖项发布时不会中断。
发布于 2017-11-02 10:05:58
为了避免这类问题,一个好的做法是设置composer config.platform设置:
"config": {
"platform": {
"php": "7.0.23"
}
}这将告诉composer更新包,但只更新到仍然支持此PHP版本的版本。因此,通常情况下,这个版本号将是生产服务器的版本。
发布于 2017-07-28 09:07:00
您可以尝试使用以下配置。对我来说很管用。
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "2.5.6",
"doctrine/annotations": "1.4.*",
"doctrine/dbal": "2.5.4",
...
}在报告composer/package问题时,composer的输出显示也非常有用。我的看起来是这样的:
doctrine/annotations v1.4.0 Docblock Annotations Parser
doctrine/cache v1.7.0 Caching library offering an object-oriented API for many cache backends
doctrine/collections v1.5.0 Collections Abstraction library
doctrine/common v2.6.2 Common Library for Doctrine projects
doctrine/dbal v2.5.4 Database Abstraction Layer
doctrine/doctrine-bundle 1.6.8 Symfony DoctrineBundle
doctrine/doctrine-cache-bundle 1.3.0 Symfony Bundle for Doctrine Cache
doctrine/inflector v1.2.0 Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm v2.5.6 Object-Relational-Mapper for PHP如果将来您有这样的问题,请访问https://packagist.org/packages/并搜索导致问题的包。
例如,doctrine/annotations:https://packagist.org/packages/doctrine/annotations#v1.5.0
然后在那里查找(requires: php:^7.1),如果这个包与PHP版本匹配。(在您的例子中,使用PHP7.0并不匹配)
但是https://packagist.org/packages/doctrine/annotations#v1.4.0与您的PHP匹配(要求: php:^5.6财政^7.0),您可以尝试使用它。
https://stackoverflow.com/questions/45337962
复制相似问题