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
Closed

Comments

@growBremen
Copy link

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
Copy link
Member

stof 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 as completed Jun 4, 2014
@oopen
Copy link

oopen 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
Copy link

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

@sitetester
Copy link

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

@nask0
Copy link

nask0 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
Copy link

@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
Copy link

timonf 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
Copy link
Contributor

sstok commented Aug 4, 2015

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

@anteriovieira
Copy link

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

@allan-simon
Copy link

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

@anteriovieira
Copy link

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
Copy link

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

@fernandopg
Copy link

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

@valVk
Copy link

valVk commented Dec 25, 2015

@anteriovieira
Thanks 👍

@allan-simon
Copy link

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

@dave-newson
Copy link

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

@anteriovieira
Copy link

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
Copy link

nask0 commented Jan 18, 2016

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

@jesmarquez
Copy link

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

@diriy
Copy link

diriy 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
Copy link

8khan 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
Copy link

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
Copy link

8khan 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
Labels
None yet
Projects
None yet
Development

No branches or pull requests