-
-
Notifications
You must be signed in to change notification settings - Fork 9.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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bd46163
to
0ce7a72
Compare
public function __sleep(): array | ||
{ | ||
return ['string']; | ||
} | ||
|
||
public function __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 | ||
*/ | ||
public function __serialize(): array | ||
{ | ||
$data = []; | ||
foreach ($this->__sleep() as $key) { | ||
$data[$key] = $this->$key; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public function __unserialize(array $data): void | ||
{ | ||
foreach ($data as $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. |
0ce7a72
to
7d26536
Compare
fixed, more garbage code... |
well, not so so This deprecation is a net loss. |
7d26536
to
ad1893c
Compare
I found the way to fix this: closure rebinding + reflection. Not pretty at all. |
579912b
to
30d0ed7
Compare
30d0ed7
to
d7488da
Compare
…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 | MIT Subset 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 serializable Commits ------- 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 | MIT Related to #61407 FTR, 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 | MIT This 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 unless php/php-src#19435 is.