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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to