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

Warning: Erroneous data format for unserializing PHP5.6+

    Details

    • Type: Bug Bug
    • Status: Reopened
    • Priority: Critical Critical
    • Resolution: Unresolved
    • 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.

        Issue Links

          Activity

          Hide
          Chase Noel added a comment - - edited

          Im still getting this error running php 5.6RC2 and the dev-master(6ac19b04bfbd7a97aad5ed8c2abd6279ff5e0022) build of D2/orm. Am i missing something?

          Show
          Chase Noel added a comment - - edited Im still getting this error running php 5.6RC2 and the dev-master(6ac19b04bfbd7a97aad5ed8c2abd6279ff5e0022) build of D2/orm. Am i missing something?
          Hide
          Marco Pivetta added a comment -

          This was semi-fixed in PHP5.6-RC3, and it will be patched into ORM once doctrine/instantiator is out

          Show
          Marco Pivetta added a comment - This was semi-fixed in PHP5.6-RC3, and it will be patched into ORM once doctrine/instantiator is out
          Hide
          Chase Noel added a comment -

          Ok good to know. Thanks

          Show
          Chase Noel added a comment - Ok good to know. Thanks
          Hide
          Marco Pivetta added a comment -

          Not yet fixed for PHP 5.6

          Show
          Marco Pivetta added a comment - Not yet fixed for PHP 5.6
          Hide
          Marco Pivetta added a comment -

          Provided a hotfix proposal at https://github.com/doctrine/doctrine2/pull/1109 - please check it out with PHP 5.6.0-RC3 or later

          Show
          Marco Pivetta added a comment - Provided a hotfix proposal at https://github.com/doctrine/doctrine2/pull/1109 - please check it out with PHP 5.6.0-RC3 or later

            People

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

              Dates

              • Created:
                Updated: