Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: Erroneous data format for unserializing PHP 5.4.29 and 5.5.13 #11056

Closed
growBremen opened this issue Jun 4, 2014 · 23 comments

Comments

@growBremen
Copy link

commented Jun 4, 2014

When using PHP Version 5.4.29 or 5.5.13 there is an Warning, which is followed by an Fatal error due to the Object expected is false.

Original Function "newInstance" in \vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\ClassMetadataInfo looks like this:

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

Quickfix for this issues:

public function newInstance()
{
    if ($this->_prototype === null) {
        // $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
        if (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;
}

See also:

doctrine/orm#1045
http://www.doctrine-project.org/jira/browse/DDC-3120
http://stackoverflow.com/questions/24031048/fos-userbundle-unable-to-login/24035854#24035854

@stof

This comment has been minimized.

Copy link
Member

commented Jun 4, 2014

This is a Doctrine issue, not a Symfony issue.

And this is already fixed in the dev version of Doctrine

@stof stof closed this Jun 4, 2014
@oopen

This comment has been minimized.

Copy link

commented Jun 23, 2014

Same error with PHP Version 5.6.0beta4

To fix it add : || PHP_VERSION_ID === 50600

public function newInstance()
{
    if ($this->_prototype === null) {
         if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513 ||  PHP_VERSION_ID === 50600) {
            $this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
        } else {
            $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
        }
    }
     return clone $this->_prototype;
}
phansys referenced this issue in doctrine/orm Jul 16, 2014
@loicfavory

This comment has been minimized.

Copy link

commented Dec 9, 2014

I have the same error with Symfony 2.3 on PHP V5.6

@sitetester

This comment has been minimized.

Copy link

commented Apr 23, 2015

Make sure you use correct PHP_VERSION_ID value :)
In my case, it was PHP_VERSION_ID = 50607 for PHP 5.6.7

@nask0

This comment has been minimized.

Copy link

commented May 14, 2015

Still exists on doctrine 2.5.0+ and PHP5.6+
https://travis-ci.org/allan-simon/oauth2-symfony2-vagrant-fosuserbundle/jobs/62429219
(This is not my bug report i just saw it few days ago on the internet)

@allan-simon

This comment has been minimized.

Copy link

commented May 15, 2015

@nask0 funny, i was looking for the error message to see if i could do something about it , and google lend me to that page ...

@timonf

This comment has been minimized.

Copy link

commented Jun 11, 2015

I had the same error message on Symfony 2.3 and 2.7 using Doctrine ORM 2.3. I'm using PHP 5.6.4-4ubuntu6. I solved this problem by upgrading Doctrine ORM to 2.4.*

@sstok

This comment has been minimized.

Copy link
Contributor

commented Aug 4, 2015

@anteriovieira Fala inglês por favor (Speak English please) ;)

@anteriovieira

This comment has been minimized.

Copy link

commented Aug 5, 2015

Hello @sstok , sorry.
The suggestion of @timonf is valid. Updated version of the doctrine to [2.4. *] and it worked fine.

@allan-simon

This comment has been minimized.

Copy link

commented Aug 7, 2015

@anteriovieira : do you mean that 2.5 does not work, but sticking on 2.4.* works ?

@anteriovieira

This comment has been minimized.

Copy link

commented Aug 7, 2015

Good morning my friend @allan-simon, in version 2.5 work. I'm using my composer as follows:

    //...
    "doctrine/orm": "~2.2,>=2.2.3,<2.5",
    //...
@allan-simon

This comment has been minimized.

Copy link

commented Aug 8, 2015

@anteriovieira , ok i'm gonna try that, thanks.

@fernandopg

This comment has been minimized.

Copy link

commented Nov 6, 2015

@anteriovieira 's fix works perfect for me! Obrigado! ;-)

@valVk

This comment has been minimized.

Copy link

commented Dec 25, 2015

@anteriovieira
Thanks 👍

@allan-simon

This comment has been minimized.

Copy link

commented Dec 25, 2015

I've upgraded the composer.lock of my project recently and now it works.

@dave-newson

This comment has been minimized.

Copy link

commented Jan 15, 2016

Another thanks to @anteriovieira, that version setting saved my bacon.

@anteriovieira

This comment has been minimized.

Copy link

commented Jan 15, 2016

Thanks for the acknowledgments, but all credit is for @timonf .

I had the same error message on Symfony 2.3 and 2.7 using Doctrine ORM 2.3. I'm using PHP 5.6.4-4ubuntu6. I solved this problem by upgrading Doctrine ORM to 2.4.*

@nask0

This comment has been minimized.

Copy link

commented Jan 18, 2016

The "PHP_VERSION_ID" fix is just ridiculous as some of symfony developers (sorry, no mean to offend anybody).

@jesmarquez

This comment has been minimized.

Copy link

commented Apr 20, 2016

Thank, i updated doctrine, in composer.json "doctrine/orm": "~2.4" and after composer update

@diriy

This comment has been minimized.

Copy link

commented Aug 3, 2016

who's more new? I use Symfony 3.1 and get this error. Windows 7 64x, PHP 5.6. How can I solve it?

@8khan

This comment has been minimized.

Copy link

commented Nov 22, 2017

i khow this it an old topic, but i solve it with this
you need khow your php version, can add a var_dump(PHP_VERSION_ID); on app.php
then add your version on line 830 on \www\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\ClassMetadataInfo.php file
another think that help is able display php errors

@MonsieurV

This comment has been minimized.

Copy link

commented Jan 24, 2018

The patch proposed @8khan and @oopen still work fine.

If you directly want to patch against any PHP version greated than PHP 5.4, you can (more radically) do:

public function newInstance()
{
    if ($this->_prototype === null) {
         if (PHP_VERSION_ID > 50429) {
            $this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
        } else {
            $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
        }
    }
     return clone $this->_prototype;
}

(Important part is PHP_VERSION_ID > 50429)

@8khan

This comment has been minimized.

Copy link

commented Feb 27, 2018

@MonsieurV yes thats a correct way to patch the issue, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.