是否有与PHP 5.6兼容的Doctrine 2版本

wow*_*ick 0 symfony doctrine-orm fosuserbundle php-5.6

我有一个使用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
Run Code Online (Sandbox Code Playgroud)

该实体是FOSUserBundle BaseUser的只是一个扩展,如图所示这里.可以在此处找到FOSUserBundle BaseUser类.

在做了一些初步研究之后,我发现错误是由PHP 5.6和Doctrine 2兼容性问题引起的,因为PHP 5.6 中的Serializable发生了变化.Doctrine开发人员已经解决了这个问题(请参阅GitHub pull请求),但是我仍然不确定我需要哪个版本的Doctrine 2 composer.json才能获得修复,而且我也不确定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.*",
        ...
},
Run Code Online (Sandbox Code Playgroud)

更新:

我已将我的composer.json更新为:

"require": {
    "php": ">=5.6.0",
    "symfony/symfony": "2.6.*",
    "doctrine/orm": "~2.5",
    "doctrine/doctrine-bundle": "1.2.*",
    ...
},
Run Code Online (Sandbox Code Playgroud)

但不幸的是,这导致了一个不可恢复的依赖问题:

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
Run Code Online (Sandbox Code Playgroud)

我也尝试将我的composer.json更新为

"require": {
    "php": ">=5.6.0",
    "symfony/symfony": "2.6.*",
    "doctrine/common": "~2.5",
    ...
},
Run Code Online (Sandbox Code Playgroud)

但这会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>]...
Run Code Online (Sandbox Code Playgroud)

cha*_*asr 6

实际上,你可以完美地使用像"~2.5"Doctrine和PHP 这样的版本5.6.
对于低于的PHP版本5.4,Doctrine 2.4.8肯定是最后一个兼容的版本.

你提供了太多的洞察力和不充分的信息.
请准确说明您的错误.

UPDATE

要修复此错误,请
执行以下命令

php -r "echo PHP_VERSION_ID;"
Run Code Online (Sandbox Code Playgroud)

或使用以下内容创建一个简单的PHP脚本:

<?php echo PHP_VERSION_ID; ?>
Run Code Online (Sandbox Code Playgroud)

然后,执行它.对于我的PHP(5.6.16)版本,它返回:

50616
Run Code Online (Sandbox Code Playgroud)

现在,取结果并转到vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php第827行附近,并将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;
}
Run Code Online (Sandbox Code Playgroud)

这解决了机器的PHP版本的问题,使用了Symfony 2.3中默认安装的版本的doctrine.

它不是一个理想的解决方案,因为当您重新克隆存储库或重新安装供应商时,修复程序将被压缩.