Re: [RFC][Discussion] NotSerializable attribute
| From: | Niels Dossche | Date: | Sat, 09 Dec 2023 16:17:59 +0000 |
| Subject: | Re: [RFC][Discussion] NotSerializable attribute | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121973@lists.php.net to get a copy of this message | ||
Hi Max
On 12/9/23 13:30, Max Semenik wrote:
> Hi, I'd like to propose a new attribute, #[NotSerializable]. This
> functionality is already available for internal classes - userspace should
> benefit from it, too.
>
> The RFC: https://wiki.php.net/rfc/not_serializable
> Proposed implementation:
> https://github.com/php/php-src/pull/12788
>
> Please let me know what you think.
>
Thanks for this proposal, it is a sensible addition in my opinion.
I do have a question/remark though.
The example you wrote in your RFC (with MyClass implementing __sleep and __awake) is not equivalent
to adding #[NotSerializable].
This is because if you create a child class of MyClass:
```
class MyClassChild extends MyClass
{
public function __sleep(): array
{
return ...; // real implementation instead of throwing
}
public function __wakeup(): void
{
... // real implementation instead of throwing
}
}
```
Then this subclass MyClassChild will actually be serializable.
If you instead put #[NotSerializable] on the parent class MyClass, then the child class won't
be serializable even if you implement the serialization methods in the child.
Is this intentional? If yes, this should probably be clarified in the text.
Kind regards
Niels