Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add #[NoSerialize] attribute support to prevent property serialization. #20074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
dkulyk wants to merge 4 commits into php:master
base: master
Choose a base branch
Loading
from dkulyk:no_serializable_attr

Conversation

Copy link

@dkulyk dkulyk commented Oct 6, 2025
edited
Loading

RFC: https://wiki.php.net/rfc/no_serialize_attribute

This PR 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.

Motivation

When developing complex objects, it’s often necessary to exclude
specific properties from serialization — for example, resources,
closures, database connections, or transient caches.
Currently, developers must manually implement __serialize() /
__sleep() to filter these properties, which can lead to boilerplate
code and potential maintenance errors.

Adding a native attribute would provide a simple and declarative way
to express this intention directly in code.

class Example
{
 public string $name;
 #[NoSerialize]
 public $connection; // e.g., PDO, socket, or any transient resource
}

When serialize($example) is called, $connection would be excluded automatically.

Benefits

  • Reduces boilerplate for common use cases.
  • Makes serialization intent explicit and self-documenting.
  • Simplifies framework and library code that relies on serialization

Copy link
Author

dkulyk commented Oct 6, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@kocsismate kocsismate Awaiting requested review from kocsismate kocsismate will be requested when the pull request is marked ready for review kocsismate is a code owner

@bukka bukka Awaiting requested review from bukka bukka will be requested when the pull request is marked ready for review bukka is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /