Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128784 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id B667D1A00BC for ; Sun, 5 Oct 2025 22:15:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1759702479; bh=uWntoeArlrSZIOhMr7QHktKsPNKj/Sno2lgsRmk6yQA=; h=From:Date:Subject:To:From; b=K7BauZQ+dIw2QYBQbJXUhm+fnuCEyD8Yg3/C5etI2zh6dARYKKG9HH1Ptz3y9HHrj SA7Axr5HX3RgaSPkgKADOr0V/pf9BEwW/Sdd23Lj3WS5pO5pk0+j47PKfceW5xftFg +rluaaYpHZIst2bDpjpahPbYBsLJpLycbcciYTaePzIdvJ8yBYW1xcxHF3BnrLHQcI C97/GDnzk06N6/tjoEgPJc+pePxB3QwMVjNlF/O70163HeAEJx51s/PNWTe2AOq0Dw xQsjIqVTxz00Q5CJEKbQxDNo0vRQljCsgA/hHKN54kp4iYMGGVR474imfT+GI+ivtf 8EBkA/iqjL7ZA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1A79118005D for ; Sun, 5 Oct 2025 22:14:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 5 Oct 2025 22:14:38 +0000 (UTC) Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-b54a588ad96so2953153a12.1 for ; Sun, 05 Oct 2025 15:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759702554; x=1760307354; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=NZIfKs6/h3GWWIcVBUK9XQktWV7GKmLc+r2D3qQ1T4Q=; b=Q+4QL7riEFO2XQOoIZEm4fpzONo5K5R7D0yeIudB94NhK1PgSZoLVch0rgJD/QF0Rv AiohMFExF53FA87M1yZaMw02QmbSOHY59+TR7JaJLJ0O0oBwQN9bFMFEq8so16/piE5B nyvLC4P9tY+/BJgtU2DMvCgi11jyx7uBIXk14tvyfpCINzHtxvZSvJHCJCIIEPpp2Dkr UtwssoOiWTY3PuneIQOx1CfCBm1hXGPi6VwON85NuuJwndLrQxZFI7LEZY7hqbVcvsZf 138ySJi3HUj26B+GF/u3zYzfDwyvNOJ9DMZrVds5QDeRF+OTBc8q+ZpXBGIeTYtzgYcl evxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759702554; x=1760307354; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NZIfKs6/h3GWWIcVBUK9XQktWV7GKmLc+r2D3qQ1T4Q=; b=BoIVv9nQdBmMW1COMbtU/RhoXAICyRCNMQyEeFFeY7KHVbzaDiHUdmT/S0FAdQH7Vz NgOAo+UYFNuD+YSAMD/mmwESzsLyqKRqdYEzsrsCD75dHk4OeGKXrxrMNZ5T/CIbFNN9 O+NlrBtKGrft/cbGXujaGMmQpDpKCFyHes9FUncpLBWKIVLNeqKIMp5LyNju1JJ6itcT cJ3WjVHLbed+fys658uV63vRLnBj+AfUwUHWllME6BYGmVHqUPD/4AgC7UlmfwJb90zT Fg718xScGZ3LVNACCgEpgChMhimIuCJAyQ99u5gUCDTJKHDxUy4na8fyXLMIjrzp6HCd BzHw== X-Gm-Message-State: AOJu0Yz9xOJKwtilyfbP5AQbtl0wew0ho3znTQfo5wVsB1v2mZ5TDBFB 70Dkas0rIOOrZtcYLyBWG4KTdwJNRDSn+FKer+jYElvpXis4Dh4PzrPuwb2e+nyxIYlzm/Xjo1v QtCWV5xtXjKoLP+ELa6EEt1P/FZs7jVRSizsyNJ0= X-Gm-Gg: ASbGncstWZoAB1QGd0jee8C+4FnVDBSsUoQIgduRrDyD2dYEdo483JbuMzAEOVoAuUy bYEX4bR4oNORU7Q5UZ5NEFt8m7vD6ozQ2nsZO6yYrqDOgOqylIM6QZDbb0k2ghHzKCEhNvVOUBJ mw6kv5B22zADrgqXSQAOP0eZV6L4JF3KzcoAFalbBdU8nJ+riyjFttsBFrLxg1yi0F+eSJJpZVO 3wLy4Peu2gzmh4KZ3BILLCIjWPZ6hvt72c/zjjP6Q== X-Google-Smtp-Source: AGHT+IHDH59TIHioDJrCQ2cC10akB31vTg9KhjdOqdBrWwEX45vhyj0Hc0YMZoxVjY/8dRxf/jGFw4oxM1ViFDJJiSo= X-Received: by 2002:a17:903:3b86:b0:269:8ace:cd63 with SMTP id d9443c01a7336-28e99de2cf6mr126669975ad.30.1759702554521; Sun, 05 Oct 2025 15:15:54 -0700 (PDT) Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 6 Oct 2025 01:15:42 +0300 X-Gm-Features: AS18NWAQ_3xRuXwf0SqDzbHT3p8GnNsH2B603hyIzMF_c72-6jDBnZ_wbLSXYnc Message-ID: Subject: [PHP-DEV] [RFC Proposal] Add #[NoSerialize] attribute for excluding properties from serialization To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: lnkvisitor.ts@gmail.com (Dmytro Kulyk) This proposal introduces a new attribute, #[NoSerialize], that can be applied to class properties to explicitly exclude them from serialization when using PHP=E2=80=99s built-in serialization mechanisms. # Motivation When developing complex objects, it=E2=80=99s often necessary to exclude specific properties from serialization =E2=80=94 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. ```php 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 automatic= ally. # Benefits - Reduces boilerplate for common use cases. - Makes serialization intent explicit and self-documenting. - Simplifies framework and library code that relies on serialization # Implementation Sketch Internally, the engine could mark properties with a flag (e.g., ZEND_ACC_NO_SERIALIZE) during class compilation. During serialization, such properties would be skipped automatically unless overridden by user-defined serialization logic. Best regards, Dmytro Kulyk