FOSUserBundle icon indicating copy to clipboard operation
FOSUserBundle copied to clipboard

Strange behavior while adding __clone function in User class

Open lilworks opened this issue 7 years ago • 2 comments

Is it possible to use the __clone function inside de User class? Each time I implement this class I get really strange beahavior... The app always return to the login check route!

lilworks avatar Sep 27 '17 16:09 lilworks

I've also just encountered this. Very strange. If anyone has an answer as to why this is, it'd be good to know!

I only needed to nullify a couple of properties in my entity on clone so I've been able to do this in the controller after cloning the entity object but admittedly it would be nicer to have these in __clone()

$obj = new Obj();
$obj2 = clone $obj;
$obj2->setId(null);

jbarton123 avatar Oct 05 '17 13:10 jbarton123

In fact, I've just found this; http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/architecture.html#entities

This seems to suggest that using __clone() in entities is really a no no unless you safely implement the method. However, even using the example there and only running when the check for an ID passes seems to log me back out...

jbarton123 avatar Oct 05 '17 13:10 jbarton123