What's the proper way to implement safe wakeup after deserializing immutable object? #10180
Answered
by
weirdan
andrew-demb
asked this question in
Q&A
-
https://psalm.dev/r/0b9d93cacf <?php
/**
* @psalm-immutable
*/
class Some
{
// it was a `?string $locale` in past
private string $locale;
public function __construct(
string $locale,
) {
$this->locale = $locale;
}
public function __wakeup(): void
{
// it was a `?string $locale` in past
if (false === isset($this->locale)) {
$this->locale = '';
}
}
}
What's the proper way to handle it? |
Beta Was this translation helpful? Give feedback.
Answered by
weirdan
Sep 5, 2023
Replies: 1 comment 1 reply
-
I think Psalm should treat |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
andrew-demb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think Psalm should treat
__wakeup()
and__unserialize()
as constructors (alsounserialize()
when the class implementsSerializable
, with appropriate deprecation warnings).