Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Account for PHP 8.5 deprecating __sleep()/__wakeup()#61407
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
bd46163 to0ce7a72Compare| return ['string']; | ||
| } | ||
| publicfunction__wakeup():void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We have to add the method so that __unserialize can call it, in case a child class defines it.
We could do a method_exists check, but that's be adding more boilerplate.
| /** | ||
| * @internal | ||
| */ | ||
| publicfunction__serialize():array | ||
| { | ||
| $data = []; | ||
| foreach ($this->__sleep()as$key) { | ||
| $data[$key] =$this->$key; | ||
| } | ||
| return$data; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| publicfunction__unserialize(array$data):void | ||
| { | ||
| foreach ($dataas$key =>$value) { | ||
| $this->$key =$value; | ||
| } | ||
| $this->__wakeup(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Might these make more sense as a trait or two, for easier reuse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this concern is cross-components - we could have one trait per component, but that'd be just garbage code...
My patch doesn't work BTW, I forgot to account for mangled property names. |
fixed, more garbage code... |
well, not so so This deprecation is a net loss. |
nicolas-grekas commentedAug 13, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I found the way to fix this: closure rebinding + reflection. Not pretty at all. |
579912b to30d0ed7Compare…n't a concern (nicolas-grekas)This PR was merged into the 7.4 branch.Discussion---------- Replace __sleep/wakeup() by __(un)serialize() when BC isn't a concern| Q | A| ------------- | ---| Branch? | 7.4| Bug fix? | no| New feature? | no| Deprecations? | no| Issues | -| License | MITSubset of#61407* Final classes can be moved to `__(un)serialize()` - payload compatibility is preserved* Throwing sleep/wakeup - even-though those could be considered BC breaks, I don't expect anyone overwrote them to make the corresponding classes serializableCommits-------246daf3 Replace __sleep/wakeup() by __(un)serialize() when BC isn't a concern
…nd data collectors and make `Profile` final (nicolas-grekas)This PR was merged into the 7.4 branch.Discussion----------[HttpKernel] Deprecate `__sleep/wakeup()` on kernels and data collectors and make `Profile` final| Q | A| ------------- | ---| Branch? | 7.4| Bug fix? | no| New feature? | yes| Deprecations? | yes| Issues | -| License | MITRelated to#61407FTR, I searched for code extending `Profile` on github and found none.Commits-------c54120e [HttpKernel] Deprecate `__sleep/wakeup()` on kernels and data collectors and make `Profile` final
…ace `__sleep/wakeup()` by `__(un)serialize()` (nicolas-grekas)This PR was merged into the 8.0 branch.Discussion----------[HttpKernel][Mime][Serializer][String][Validator] Replace `__sleep/wakeup()` by `__(un)serialize()`| Q | A| ------------- | ---| Branch? | 8.0| Bug fix? | no| New feature? | yes| Deprecations? | no| Issues |Fix#61407| License | MITThis gets rid of all usages of `__sleep/wakeup()` while preserving FC/BC for payloads.Commits-------2b841c1 [HttpKernel][Mime][Serializer][String][Validator] Replace `__sleep/wakeup()` by `__(un)serialize()`
Except for final and test classes, we have to account for inheritance and for existing payloads in both directions (old apps accepting payloads from updated apps and updated apps accepting them from old apps.)
This means the fix is to mimic what the engine does currently, with all the existing quirks regarding private properties.
Don't merge unlessphp/php-src#19435 is.