0

I have a Symfony 2.3 app using Doctrine >=2.2.3,<2.4-dev. I upgraded my production server to PHP 5.6 which caused the following error with the 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

The entity is a just an extension of the FOSUserBundle BaseUser, as shown here. The FOSUserBundle BaseUser class can be found here.

After doing some initial research, I found out that the error is caused by a PHP 5.6 and Doctrine 2 compatibility issue due to a change in Serializable in PHP 5.6. The Doctrine developers have fixed the issue (see GitHub pull request), but I'm still not sure which version of Doctrine 2 I have to require in the composer.json to get the fix and I'm also not sure to which versions of Symfony 2 it is compatible.

My current composer.json:

"require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.3.*",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.2.*",
        ...
},

Update:

I've updated my composer.json to:

"require": {
    "php": ">=5.6.0",
    "symfony/symfony": "2.6.*",
    "doctrine/orm": "~2.5",
    "doctrine/doctrine-bundle": "1.2.*",
    ...
},

But unfortunately this causes a unreseovlable dependency issue:

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

I also tried to updated my composer.json to

"require": {
    "php": ">=5.6.0",
    "symfony/symfony": "2.6.*",
    "doctrine/common": "~2.5",
    ...
},

But this causes an error on the app/console clear:cache run after composer has finished updating.

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>]...
wowpatrick
  • 5,082
  • 15
  • 55
  • 86

1 Answers1

7

Actually, you can perfectly use a version such as "~2.5" of Doctrine with PHP 5.6.
For a version of PHP lower than 5.4, Doctrine 2.4.8 is surely the last compatible release.

You give too much insight and insufficient informations.
Please be precise about your error.

UPDATE

To fix this bug,
Execute the following command

php -r "echo PHP_VERSION_ID;"

OR Create a simple php script with the following content :

<?php echo PHP_VERSION_ID; ?>

Then, execute it. For my version of PHP (5.6.16), it returns :

50616

Now, take the result and go to vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php near line 827, and replace the newInstance method by :

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;
}

This solves the problem for the PHP version of your machine, using doctrine with version installed by default in Symfony 2.3 .

It's not an ideal solution because when you re-clone the repository or re-install vendors, the fix will be squashed.

chalasr
  • 12,971
  • 4
  • 40
  • 82
  • Can you add the content of your User entity ? Especially the part calling Serializable – chalasr Jan 16 '16 at 13:49
  • It exists an old question for a very similar issue http://stackoverflow.com/questions/24031048/fos-userbundle-unable-to-login . Try to implement one of the quick-and-dirty (but working) alternatives proposed in answers. See this issue https://github.com/doctrine/doctrine2/issues/3897 – chalasr Jan 17 '16 at 12:03
  • It seems like the PHP_VERSION id check dose not solve the problem for PHP 5.6. The 2.4 branch has got a correct check for 5.6 (see https://github.com/doctrine/doctrine2/blob/2.4/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L866) but for some wired reason the login fails silently without an error message when using `"doctrine/orm": "~2.4",` which I is caused by the same problem as with 2.3 – wowpatrick Jan 18 '16 at 12:09
  • Which version of FOSUserBundle are you using ? I'am trying to reproduce your problem – chalasr Jan 18 '16 at 12:22
  • Currently v1.3.6 is installed. – wowpatrick Jan 18 '16 at 12:25
  • I've added the fix in my answer. For me, just added the following check `|| PHP_VERSION_ID === 50616` in the `newInstance` method solved the issue. – chalasr Jan 18 '16 at 12:51
  • 1
    First of all, thanks for the effort you are putting into this! I tested the solution as you described in the updated question, and the behaviour I mentioned in my second comment (with Doctrine 2.4 installed) still persists: The Error thrown in the original question is gone, but when trying to log in, FOSUserBundle just reloads the login page. My first guess was this is still being caused by the original error we are currently discussing, but maybe Doctrine 2.4 fixes the original error and what I'm facing now is a other FOSUserBundle incompatibility. – wowpatrick Jan 18 '16 at 15:10
  • You should avoid all the custom requirements you have added because of the first bug. To avoid every bugs you may have in future because of compatibility, restart at the first point with good dependencies, re-add your full bundle and full configuration previously backup, and then all should work. I have implemented the FOSUserBundle to reproduce perfectly your issue and it works fully. The bug at the login_check point is caused by the first problem, and it was fixed by my answer. Furthermore, It could be a good "thanks" for me to restart at zero, apply my answer and if you are logged in ... – chalasr Jan 18 '16 at 15:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/100989/discussion-between-wowpatrick-and-chalasr). – wowpatrick Jan 18 '16 at 15:29
  • Downvote without any explanation is a bit ungrateful ! – chalasr Feb 25 '16 at 12:35