PHP Warning raised when Virtual Property Hooks are serialized on Models #55801
Replies: 3 comments 10 replies
-
Hi. Besides the fact that the issue is legit and the proposed solution solves it, can you please elaborate why would you use property hooks on a model? Is this related to columns from db? |
Beta Was this translation helpful? Give feedback.
-
framework/src/Illuminate/Queue/SerializesModels.php Lines 39 to 41 in ae955ad Model are already handled correctly for queue, so I'm not sure manual |
Beta Was this translation helpful? Give feedback.
-
Safe alternative for property hooks in eloquent model: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
12.12.0
PHP Version
8.4.3
Database Driver & Version
No response
Description
Virtual property hooks on Models seem to cause PHP Warnings whenever the Model is serialized. The exact warning is:
WARNING serialize(): "<HOOK_NAME>" returned as member variable from __sleep() but does not exist in <PROJECT>eval()'d code.
There is a workaround: overriding
__sleep
fromIlluminate\Database\Eloquent\Model
and changing its implementation from:to
Steps To Reproduce
User
model, add this virtual property hook:This results in the serialization working, but it raises a PHP warning.
Beta Was this translation helpful? Give feedback.
All reactions