Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121975 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55651 invoked from network); 9 Dec 2023 16:29:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Dec 2023 16:29:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 550CA180035 for ; Sat, 9 Dec 2023 08:29:15 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (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 ; Sat, 9 Dec 2023 08:29:14 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 05F955C0165 for ; Sat, 9 Dec 2023 11:28:59 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Sat, 09 Dec 2023 11:28:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1702139339; x= 1702225739; bh=TVxHl4Ow/ARQgw4AUAPvYX9ba+XT3TfxArUNwqfwb8M=; b=b W/xVeahC2grT8nodBIm2ZqozC+1kvZqR4uLgUyXOOD9qEUqzsAuPNLnzHO78CwUD Cktq5veRuo8BzTdDesRRvQSJMkh+eHnRpE0QQP8ss59qWmvONz/3ipEqCItOKT0v e95KLkVbEUPNpSddPx9QRn2CNnmtG0Ie3ItvGEhimkZMKOW2z+K2W39oGT13XNtd IR3ogEH6sHrt1DqebxkvoDPiXovnKc5/I3SkFA7Aa+VugGuTH8llksyFzMigQZlv Ufuu3RyKzpeJmz1rCUlNNy7E0JtPGgzJQvZfXfbIoRxlSpfikNZUN+F7XtZj+GNt i5uDCqDg9RZpz5SIL3sJQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1702139339; x=1702225739; bh=TVxHl4Ow/ARQg w4AUAPvYX9ba+XT3TfxArUNwqfwb8M=; b=kDG3TQtIr0DCjGv4troJMUYCmpvLX 5eVufDBx3Mt3q8SqVe4K2uZAryZJ3+eaB90u2YPUkHpyQYqukFfGa/gXwj6LJAH/ WGALsoW6AItm29awR2EqEbUJjgAkeV3YO7tme3rlC9+gLGoFLcKklgdjRpO+3cm8 qyIs9WWUbJDI9WZb7sgWUxnBPEQDaAPYdd/JrhyvsdAP+/s6dk/Q5GBBvDtJNBuh z+72MVMzFcFPmBonbbCxJ2N9KgXY4d7xUKsnJlQTzYWrmNG+HQUUa9Pb1WrM28vT IPnolsb8gvRgNhoJJ/XKFCwvUy+ERjDJASVkBva1Qm16RO+iQnt4a7KMg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudekkedgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeefteevffetteeuueekgeejffduueehtdfhveefheei hfehgeehffehtdehgfeljeenucffohhmrghinhepphhhphdrnhgvthdpghhithhhuhgsrd gtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep lhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 891841700089; Sat, 9 Dec 2023 11:28:58 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-1178-geeaf0069a7-fm-20231114.001-geeaf0069 MIME-Version: 1.0 Message-ID: In-Reply-To: <20add1b7-24ed-42be-ae84-99ef81480fa2@gmail.com> References: <20add1b7-24ed-42be-ae84-99ef81480fa2@gmail.com> Date: Sat, 09 Dec 2023 10:28:38 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC][Discussion] NotSerializable attribute From: larry@garfieldtech.com ("Larry Garfield") On Sat, Dec 9, 2023, at 10:17 AM, Niels Dossche wrote: > Hi Max > > On 12/9/23 13:30, Max Semenik wrote: >> Hi, I'd like to propose a new attribute, #[NotSerializable]. This >> functionality is already available for internal classes - userspace should >> benefit from it, too. >> >> The RFC: https://wiki.php.net/rfc/not_serializable >> Proposed implementation: https://github.com/php/php-src/pull/12788 >> >> Please let me know what you think. >> > > Thanks for this proposal, it is a sensible addition in my opinion. > > I do have a question/remark though. > The example you wrote in your RFC (with MyClass implementing __sleep > and __awake) is not equivalent to adding #[NotSerializable]. > This is because if you create a child class of MyClass: > > ``` > class MyClassChild extends MyClass > { > public function __sleep(): array > { > return ...; // real implementation instead of throwing > } > > public function __wakeup(): void > { > ... // real implementation instead of throwing > } > } > ``` > > Then this subclass MyClassChild will actually be serializable. > If you instead put #[NotSerializable] on the parent class MyClass, then > the child class won't be serializable even if you implement the > serialization methods in the child. > Is this intentional? If yes, this should probably be clarified in the > text. Attributes do not inherit automatically, so it's the opposite. A child that is not marked #[NotSerializable] would be serializable. (Whether that's good or not is a separate question.) Behavior-changing ini settings are generally viewed as a terrible idea and a mistake of the past, so let's not consider that option. Given the existing code, that means a #[NotSerializable] attribute would be the only option. (Or I suppose a #[Serializable(false)], which a default of true?) My main concern is that, as noted, *most* classes probably aren't realistically serializable. Basically any service class should never be serialized, ever, and anything that depends on a service class should never be serialized, ever. So for this attribute to have the desired effect, it would need to be added to most classes in a codebase. Which seems... like a lot of work. In an ideal world serializability would be opt-in, but we do not live in that world. How significant is the problem today? The RFC doesn't make an especially compelling argument for this functionality given the current state of things, just that it's really easy to do (which is a positive, certainly) and "non-serializable objects exist". I'd like to see a stronger argument for how this will make code bases better/more resilient/harder to break/whatever. It's also unclear if this would apply only to serialize/unserialize, or also to json_encode/json_decode. If a class has this attribute, is implementing __sleep/__wakeup/__serialize/__unserialize an error? Should it be? Also, is the expectation that user-space serializers (Symfony/Serializer, JMSSerializer, Crell/Serde, etc.) would also honor this attribute? There's nothing forcing them to, naturally, but is the intent that they should respect it? I'm not opposed to this proposal, but there's lots of questions still to answer before I would be in favor. --Larry Garfield