Re: [RFC][Discussion] Add #[NoSerialize] attribute for excluding properties or classes from serialization

From: Date: Fri, 31 Oct 2025 12:29:36 +0000
Subject: Re: [RFC][Discussion] Add #[NoSerialize] attribute for excluding properties or classes from serialization
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-129026@lists.php.net to get a copy of this message
On Fri, Oct 31, 2025, 8:23 AM Tim Düsterhus <tim@bastelstu.be> wrote:

> Hi
>
> Am 2025-10-31 13:16, schrieb Eric Norris:
> > 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".
>
> I don't have a particularly strong opinion on naming, but I'd like to
> note that #[\NoSerialize] is in line with #[\NoDiscard] (added in PHP
> 8.5, https://wiki.php.net/rfc/marking_return_value_as_important).
>

Fair. I had considered that this might already be inconsistent with other
attributes, but I was responding by phone and didn't look it up - thanks.
I'm still partial to something that sounds more "natural" from a language
perspective to me, but I can appreciate the argument to prefer consistency.

(This may come up in the future, so I wonder if we have / should have a
naming policy?)

>


Thread (16 messages)

« previous php.internals (#129026) next »