-
Notifications
You must be signed in to change notification settings - Fork 52
Description
I was working on upgrading to 5.5 and ran into some issues with the serialization. To be exact I upgraded analogue/orm from 5.4.0 to 5.5.18.
Basically in 5.5 the EntityProxy was replaced with a new ProxyFactory and when creating the generated class there is a closure inside. PHP is unable to serialize closures and fails with an exception:
Serialization of 'Closure' is not allowed
I ran into this when passing in my User entity to Notification::send(...) or when calling $user->notify(...). My User entity is still using the 5.4 base class and implements Notifiable. The serialization issue happened when the Queue tried to serialize the job (which contains the notifiable user).
I tried to work around this by implementing the Serializable interface and calling $this->toArray() and such but was not able to cover all the cases. Also upon a fresh boot Analogue ORM would throw an exception due to not being able to serialize() the dummy entity. Removing my overrides restored the original behavior.
I hacked a workaround by manually unsetting any proxied entites or collections but this isn't maintainable. I can probably separate User from Notifiable and create another class to deal with this but it all worked in 5.4 without issue.
My questions are:
- Is it intended for the new proxy behavior to not serialize?
- Any workarounds or fixes possible here?
- If no workarounds or fixes: do you know what is the correct way to deal with serialization issues like this?
I would greatly appreciate any insight into this problem. Maybe I'm just doing something wrong but since this all worked in 5.4 it feels like a regression.