我有一个使用Doctrine> = 2.2.3,< 2.4-dev的Symfony 2.3应用程序。我将生产服务器升级到PHP 5.6,导致FOSUserBundle出现以下错误:
Warning: Erroneous data format for unserializing 'air\cms2Bundle\Entity\User' in /vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 833
Fatal error: __clone method called on non-object in /vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 837
该实体只是FOSUserBundle BaseUser的扩展,如here所示。可以找到FOSUserBundle BaseUser类here。
在做了一些初步研究之后,我发现错误是由PHP 5.6和Doctrine 2兼容性问题引起的,因为PHP 5.6中的Serializable发生了变化。 Doctrine开发人员已经解决了这个问题(请参阅GitHub pull request),但我仍然不确定在composer.json
中我需要哪个版本的Doctrine 2才能获得修复,而且我也不知道。我也不确定它兼容哪个版本的Symfony 2。
我当前的composer.json
:
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.3.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.2.*",
...
},
更新
我已将我的composer.json更新为:
"require": {
"php": ">=5.6.0",
"symfony/symfony": "2.6.*",
"doctrine/orm": "~2.5",
"doctrine/doctrine-bundle": "1.2.*",
...
},
但遗憾的是,这会导致不可撤销的依赖问题:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Conclusion: don't install doctrine/orm v2.5.4
- Conclusion: remove doctrine/doctrine-bundle v1.2.0
- Conclusion: remove doctrine/dbal v2.4.5
- Conclusion: don't install doctrine/orm v2.5.3
- Conclusion: don't install doctrine/orm v2.5.2
- Conclusion: don't install doctrine/orm v2.5.1
- Conclusion: don't install doctrine/dbal v2.4.5
- Conclusion: don't install doctrine/dbal v2.5.2|install doctrine/dbal v2.4.5
- Conclusion: don't install doctrine/dbal v2.5.3|install doctrine/dbal v2.4.5
- Conclusion: don't install doctrine/dbal v2.5.4|install doctrine/dbal v2.4.5
- Installation request for doctrine/doctrine-bundle 1.2.* -> satisfiable by doctrine/doctrine-bundle[v1.2.0].
- Installation request for doctrine/orm ~2.5 -> satisfiable by doctrine/orm[v2.5.0, v2.5.1, v2.5.2, v2.5.3, v2.5.4].
- doctrine/doctrine-bundle v1.2.0 requires doctrine/dbal >=2.2,<2.5-dev -> satisfiable by doctrine/dbal[v2.4.5, 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.3.5, v2.4.0, v2.4.1, v2.4.2, v2.4.3, v2.4.4].
- Can only install one of: doctrine/dbal[v2.5.0, 2.2.0].
- Can only install one of: doctrine/dbal[v2.5.0, 2.2.1].
- Can only install one of: doctrine/dbal[v2.5.0, 2.2.2].
- Can only install one of: doctrine/dbal[v2.5.0, 2.3.0].
- Can only install one of: doctrine/dbal[v2.5.0, 2.3.1].
- Can only install one of: doctrine/dbal[v2.5.0, 2.3.2].
- Can only install one of: doctrine/dbal[v2.5.0, 2.3.3].
- Can only install one of: doctrine/dbal[v2.5.0, 2.3.4].
- Can only install one of: doctrine/dbal[v2.5.0, 2.3.5].
- Can only install one of: doctrine/dbal[v2.5.0, v2.4.0].
- Can only install one of: doctrine/dbal[v2.5.0, v2.4.1].
- Can only install one of: doctrine/dbal[v2.5.0, v2.4.2].
- Can only install one of: doctrine/dbal[v2.5.0, v2.4.3].
- Can only install one of: doctrine/dbal[v2.5.0, v2.4.4].
- doctrine/orm v2.5.0 requires doctrine/dbal >=2.5-dev,<2.6-dev -> satisfiable by doctrine/dbal[v2.5.0, v2.5.1, v2.5.2, v2.5.3, v2.5.4].
- Conclusion: don't install doctrine/dbal v2.5.1
我还尝试将我的composer.json更新为
"require": {
"php": ">=5.6.0",
"symfony/symfony": "2.6.*",
"doctrine/common": "~2.5",
...
},
但是这会在作曲家完成更新后导致app/console clear:cache
运行时出错。
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing doctrine/orm (v2.4.8)
- Removing doctrine/doctrine-bundle (v1.2.0)
- Removing doctrine/dbal (v2.4.5)
- Removing jdorn/sql-formatter (v1.2.17)
Writing lock file
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
PHP Fatal error: Class 'Doctrine\Bundle\DoctrineBundle\DoctrineBundle' not found in /vagrant/logbookWebApp-data/app/AppKernel.php on line 16
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command.
update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--] [<packages>]...
答案 0 :(得分:6)
实际上,您可以使用PHP "~2.5"
完全使用Doctrine 5.6
等版本。
对于低于5.4
的PHP版本,Doctrine 2.4.8
肯定是最后一个兼容版本。
你提供了太多的洞察力和不充分的信息 请准确说明您的错误。
<强>更新强>
修复此错误,
执行以下命令
php -r "echo PHP_VERSION_ID;"
或使用以下内容创建一个简单的PHP脚本:
<?php echo PHP_VERSION_ID; ?>
然后,执行它。对于我的PHP版本(5.6.16
),它返回:
50616
现在,取结果并转到第827行附近的vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
,并将newInstance
方法替换为:
public function newInstance()
{
if ($this->_prototype === null) {
if (PHP_VERSION_ID === YOURPHPVERSIONHERE || PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513) {
$this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
} else {
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
}
}
return clone $this->_prototype;
}
这解决了您的机器的PHP版本的问题,使用了默认安装在Symfony 2.3中的版本的doctrine。
这不是一个理想的解决方案,因为当您重新克隆存储库或重新安装供应商时,修复程序将被压缩。