Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3120

Warning: Erroneous data format for unserializing PHP5.6+

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: Git Master
    • Fix Version/s: 2.5, 2.4.3
    • Component/s: ORM
    • Security Level: All
    • Labels:
    • Environment:
      Webserver Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.6.0beta2

      and

      PHP-CLI (Win32) PHP/5.6.0beta2

      Description

      Hi all,

      There seems to be something strange going on in the method newInstance() of the class \Doctrine\ORM\Mapping\ClassMetadataInfo.

      The original class method looks like this:

      \Doctrine\ORM\Mapping\ClassMetadataInfo#newInstance()

          {
              if ($this->_prototype === null) {
                  $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
              }
      
              return clone $this->_prototype;
          }
      

      What happens now when a class that implements \Serializable is that a "Warning: Erroneous data format for unserializing" shows up and the function unserialize() returns false.

      That is because a class that implements \Serializable is expected to have the letter 'C' in the serialize string instead of the letter 'O'.

      I've made a quick work-around like this:

      \Doctrine\ORM\Mapping\ClassMetadataInfo#newInstance()

          {
              if ($this->_prototype === null) {
                  $this->_prototype = @unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
                  if ($this->_prototype === false) {
                      $this->_prototype = unserialize(sprintf('C:%d:"%s":0:{}', strlen($this->name), $this->name));
                  }
              }
      
              return clone $this->_prototype;
          }
      

      That seems to work in my isolated tests and with Symfony2 and Doctrine2 and FOSUserBundle together.

      I've noticed this because the Model\User class from FOSUserBundle implements \Serializable.

      I had to implement a check in Model\User class because when using 'C:%d:"%s":0:{}' the $serialized parameter of the unserialize method in the Model\User class is a empty string then.

      That warning seems only to happen with PHP5.6+. PHP5.5.12 and below doesn't show that warning.

      I hope someone can shine some light on this, thank you,

      Cornelis.

        Activity

        Hide
        Evert Harmeling added a comment -

        Looking at http://news.php.net/php.internals/75966 it's still being discussed, and they are planning to have it fixed in RC3.

        Show
        Evert Harmeling added a comment - Looking at http://news.php.net/php.internals/75966 it's still being discussed, and they are planning to have it fixed in RC3.
        Hide
        Marco Pivetta added a comment -

        Internals still didn't get to a clear decision. Until then, we won't support 5.6 officially.

        Show
        Marco Pivetta added a comment - Internals still didn't get to a clear decision. Until then, we won't support 5.6 officially.
        Hide
        Ronan added a comment -

        Same error encountered with PHP 5.5.13 (cli) (built: May 30 2014 10:43:29)
        Copyright (c) 1997-2014 The PHP Group
        Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
        with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
        with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

        (PHP 5.5 installed via http://php-osx.liip.ch/)

        Show
        Ronan added a comment - Same error encountered with PHP 5.5.13 (cli) (built: May 30 2014 10:43:29) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans (PHP 5.5 installed via http://php-osx.liip.ch/ )
        Hide
        Marco Pivetta added a comment -

        Ronan what D2 version? We fixed it for 2.4.x (temporarily)

        Show
        Marco Pivetta added a comment - Ronan what D2 version? We fixed it for 2.4.x (temporarily)
        Hide
        Ronan added a comment - - edited

        My bad: reading my composer.lock: doctrine/orm, v2.4.2, ref 0363a5548d9263f979f9ca149decb9cfc66419ab, "time": "2014-02-08 16:35:09"... Well.. this is was an old one !

        `composer update` fixed it. Sorry for disturbing.

        Show
        Ronan added a comment - - edited My bad: reading my composer.lock: doctrine/orm, v2.4.2, ref 0363a5548d9263f979f9ca149decb9cfc66419ab, "time": "2014-02-08 16:35:09"... Well.. this is was an old one ! `composer update` fixed it. Sorry for disturbing.

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Cornelis Brouwers
          • Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: