Re: [RFC][Discussion] Add #[NoSerialize] attribute for excluding properties or classes from serialization
| From: | Eric Norris | Date: | Fri, 31 Oct 2025 12:16:47 +0000 |
| Subject: | Re: [RFC][Discussion] Add #[NoSerialize] attribute for excluding properties or classes from serialization | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-129024@lists.php.net to get a copy of this message | ||
On Fri, Oct 31, 2025, 4:47 AM Tim Düsterhus <tim@bastelstu.be> wrote:
> Hi
>
> Am 2025-10-30 23:24, schrieb Dmytro Kulyk:
> > If we go in that direction, I’d suggest keeping the name
> > #[NoSerialize], because it’s more general and clearly describes the
> > action rather than the failure mode.
> > #[NotSerializable] reads more like an error state, while
> > #[NoSerialize] works naturally for both contexts — skipping properties
> > silently and preventing class serialization (by throwing).
> >
> > This way, the attribute name remains short and declarative, while the
> > actual behavior (throwing vs skipping) can be determined by where it’s
> > applied — on a class or on a property — without introducing another
> > attribute.
>
> That makes sense to me and I don't have a suggestion for a better name.
>
I hope I'm not starting a bikeshed discussion, but I've been following
along - can I suggest "DoNotSerialize"? "NoSerialize" sounds odd to me,
whereas "DoNotSerialize" can be seen as both an instruction to PHP - "don't
serialize this property when serializing the class" - and an instruction to
developers - "do not attempt to serialize this class".
>