Hello internals, I’d like to open a discussion about a new proposal introducing the #[NoSerialize] attribute, which allows developers to explicitly exclude properties — or even entire classes — from native PHP serialization.
RFC: https://wiki.php.net/rfc/no_serialize_attribute Implementation: https://github.com/php/php-src/pull/20074 The primary goal of my series of proposals is to gradually reduce the responsibilities of __sleep(), which today is used both to filter which properties should be serialized, and to perform pre-serialization logic. Before proposing significant behavioral changes to __sleep(), we first need to introduce clear, attribute-based alternatives for its common use cases. This RFC represents one of these preparatory steps. It introduces an explicit, engine-level mechanism (#[NoSerialize]) to declare which properties or classes should be skipped during serialization — without requiring __sleep() to handle that responsibility. Please also consider the related RFCs (to be discussed separately): - https://wiki.php.net/rfc/sleep_without_return_array - https://wiki.php.net/rfc/not_serializable_attribute Together, these proposals aim to clarify and simplify PHP’s object serialization model by moving away from overloaded magic methods toward more explicit, declarative mechanisms. Best regards, Dmytro Kulyk
