Redeclaring methods serialize and unserialize on the Doctrine Proxy cache file #2501

Closed
thiagofesta opened this Issue Oct 27, 2011 · 10 comments

3 participants

@thiagofesta

Hi Symfony team,

I have an Entity called User, that implements UserInterface and Serialize classes:
class User implements Symfony\Component\Security\Core\User\UserInterface, \Serializable { ... }

When i run the code on my localhost (Windows), it generate the right cache file (Localhost - http://twitpic.com/76mtyt) but when i use that on the webserver it redeclare the serialize and unserialize methods (Webserver - http://twitpic.com/76mts5).

Thanks.

@thiagofesta

I found on Google to telling me to remove the implementation of Serializable class, and just give the functions serialize and unserialize, but didn't work.

If i remove Serializable interface it thrown this error:
Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::serialize() must return a string or NULL

@thiagofesta

More information.
I tested on my Linux too, worked perfectly, as well on my Windows, but on the my server still bugged.
The files are same, i'm making svn checkout / update

PHP Versions:

My localhost (Windows)
    PHP 5.3.6 (cli) (built: Mar 17 2011 10:37:07)
    Copyright (c) 1997-2011 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

My localhost (Linux)
    PHP 5.3.6-13ubuntu3.2 with Suhosin-Patch (cli) (built: Oct 13 2011 23:19:13) 
    Copyright (c) 1997-2011 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

My server Linux (CentOS)
    PHP 5.3.6 (cli) (built: Sep 22 2011 16:11:21)
    Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies with the ionCube PHP Loader v4.0.9, Copyright (c) 2002-2011, by ionCube Ltd., and with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies

Thanks

@thiagofesta

Hi guys,

I fixed this bug. Actually u don't know how to send here for you guys, but here my changes.

I just changed the file: \vendor\doctrine\lib\Doctrine\ORM\Proxy\ProxyFactory.php

On method _generateMethods, i changed the first lines:

private function _generateMethods(ClassMetadata $class)
    {
        $methods = '';
        $methods_arr = array(); // ADDED THIS LINE

        foreach ($class->reflClass->getMethods() as $method) {
            /* @var $method ReflectionMethod */
            if ($method->isConstructor() || in_array(strtolower($method->getName()), array("__sleep", "__clone")) || in_array(strtolower($method->getName()), $methods_arr)) { // CHANGED THIS LINE
                continue;
            }
            
            array_push($methods_arr, strtolower($method->getName())); // ADDED THIS LINE

I hope anyone here take a look at that.

Thanks

@thiagofesta

I was taking a look abit more inside the code, and i noticed that the getMethods of a ReflectionClass bring the methods of not just the one class, if get from all other classes.

So here is a nice solution (forget my last change that i mentioned before).

private function _generateMethods(ClassMetadata $class)
    {
        $methods = '';
        
        foreach ($class->reflClass->getMethods() as $method) {
            /* @var $method ReflectionMethod */
            if ($method->isConstructor() || in_array(strtolower($method->getName()), array("__sleep", "__clone")) || $class->reflClass->getName() != $method->class) { // CHANGED THIS LINE
                continue;
            }

Let me explain what i did. I just made a check if the reflection class is the same class of the method class.

My both updates works, you guys can choose, i think the best is the last one.

Thanks, i hope that all that help you guys, since i saw many requests closer with this bug like these:
http://groups.google.com/group/symfony-devs/browse_thread/thread/435a19119e9d6bdb
and this that was closed without solution!!! https://github.com/everzet/capifony/issues/60

I think it can be a PHP error, because on most SOs it didn't occur, but it is a solution.

Bye

@thiagofesta

I opened a pull-request: doctrine/doctrine2#177

@qiulihong

firstly, thanks a lot! you really survive me :)
but, why there's no a official patch to fix this, just little bit uncomfortable and anxiety to do something on 3rd party library directly, but anyway, it works. so strange problem, same as you, works on my local, windows/ubuntu/mac, not work fine on my server

@thiagofesta

Hi qiulihong, take a look the my pull request: doctrine/doctrine2#177
Send your message to the pull, and lets try to make them fix that.
Thanks

@qiulihong

done! thank you very much :)

@beberlei

This was fixed in Doctrine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment