Re: [RFC Proposal] Add #[NoSerialize] attribute for excluding properties from serialization

From: Date: Mon, 06 Oct 2025 10:02:21 +0000
Subject: Re: [RFC Proposal] Add #[NoSerialize] attribute for excluding properties from serialization
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-128787@lists.php.net to get a copy of this message
Hi Dmytro Thanks for your proposal. This seems like a reasonable use of attributes. On Mon, Oct 6, 2025 at 12:16 AM Dmytro Kulyk <lnkvisitor.ts@gmail.com> wrote: > > This proposal introduces a new attribute, #[NoSerialize], that can be > applied to class properties to explicitly exclude them from > serialization when using PHP’s built-in serialization mechanisms. A few things: * How does this interact with inheritance, i.e. is this flag inherited to overridden child properties? I would assume no, as with other attributes. But it would be good to spell it out. * There are other forms of serialization, most notably JSON and var_export(). Are these affected in any way? Does it make sense to have a universal solution? * There may also be a benefit to marking classes as entirely not serializable, which would throw when encountering the class during [un]serialization. We have some of those internally. [^1] Ilija [^1]: https://github.com/search?q=repo%3Aphp%2Fphp-src%20%40not-serializable&type=code

« previous php.internals (#128787) next »