Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128468 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 A67551A00BC for ; Wed, 13 Aug 2025 16:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1755104019; bh=gQKz2N1Dbg+2OV97D5TCZx/VLP7w188RknEm+wpCzPE=; h=Date:From:To:In-Reply-To:References:Subject:From; b=AS+yeJ6+f++X6GW1Lms2+bk+OA2tpWUte2b5XDoox7bdrLsZerRxWj7Oq/D785JjY mXvf91XZkjWJ0NFVFTDO5DOzqk7/N7pdOMf2gWEIrK9UOqt+yfEcdQ+Az8nbtn21I0 RcZlIP+AhQnBJX+3lp5PEJbChxDLaSu1EdyFf+VfGk1I3DOoehfQBMyNuaucmRorrI k5saUFmjixh//lJmaonJ6aDZ8OHTkUUagajsjEuLtPVFvsiNwQN0BgqdtYVC//QPAH 12LThwkik/l0/RtNvq6/9KrMmI3FLddOWHLWWKW5j8ycqH0Mc9DO2oWVgfqkxsq+Sm 1iEUomLymuYyw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 66F0F18005D for ; Wed, 13 Aug 2025 16:53:38 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-b3-smtp.messagingengine.com (fout-b3-smtp.messagingengine.com [202.12.124.146]) (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 ; Wed, 13 Aug 2025 16:53:38 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfout.stl.internal (Postfix) with ESMTP id 096291D000D1 for ; Wed, 13 Aug 2025 12:55:15 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Wed, 13 Aug 2025 12:55:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm3; t=1755104114; x=1755190514; bh=PUALcn6aZA6o4ObHEFo6Z sUCIkNy6ydizVshPy6OMlQ=; b=A0H0mN3V9EgARsnAFcp1JTXnrvzR2H/G3KHTF cEm6wMQxE3q5biNqppfmj1fsTBlrnNeZEjHkU7AbY5qTO2qAV+SFrT2C8vWnU5sL z77uTm96eJJ0DSBLno70CygrzbivZOYU0xNHcSb/ZbCCfGViNO2hPGDjzvlF4hpn 3Ma63q9CtK8DCaQQrdV0Aen0UEQ7NHwnOhvQd+2ej4jbJonNBnWKhZvDkS2CnoWh a2BQoUvxhIgZUJ5akQw5nVArcQPcciP8BRd4/Xe7pAFAHZsmiffnKv26Un5rnXAd Vpq6x52PfqiNO0ETPmj5XQCxKr0aCW+BhnSxDGY05vwBdzXUw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1755104114; x=1755190514; bh=P UALcn6aZA6o4ObHEFo6ZsUCIkNy6ydizVshPy6OMlQ=; b=UmvXluuRjagdAtZHq h8w7nYbpS90f724W5O8/+5Diw6+OVYJyaDM4jV+4skyZ5fQn0tOpU7qXulWHCWKw z7xtBwS+4iP9n3q00cMjN+Qx3IdR210NWJakAW5dIPoWeh/8das730lfrAzuo8gf CQ5CZ1UhJOLMqWQKYaUeKG0SKnRP3m/fcBXODx1ltebHXc6pIEAHtD2NPpt2rkTj W+ESIHe335cjdNzUdnFQuV3Lt2EBxBHguKWgqJzyTpoZOSUwlWRWouf6Rtzh5SPA 0q3xA1ReC30QRGF1HzcUJ547+WV/0BcH2k/XWA3o/FsXa3d/V8iuXGhDAnB8Iknm PEz6w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddufeekjeegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvffkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdfnrghrrhih ucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqe enucggtffrrghtthgvrhhnpeehjeefvefgfeduteffffdvheeiudekieefleevvdduiefg keehvdevheffvdegteenucffohhmrghinhepghhithhhuhgsrdgtohhmnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhf ihgvlhguthgvtghhrdgtohhmpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 8F287700068; Wed, 13 Aug 2025 12:55:14 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: Tfba3e70d676fe2d7 Date: Wed, 13 Aug 2025 11:54:25 -0500 To: "php internals" Message-ID: <870631ac-05a1-429a-94b9-6caa8ab577bf@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] [VOTE] Deprecations for PHP 8.5 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Wed, Aug 13, 2025, at 11:36 AM, Nicolas Grekas wrote: > Le mer. 13 ao=C3=BBt 2025 =C3=A0 17:34, Nicolas Grekas=20 > >=20 > a =C3=A9crit : >>=20 >>=20 >> Le mer. 13 ao=C3=BBt 2025 =C3=A0 14:33, Tim D=C3=BCsterhus a =C3=A9crit : >>> Hi >>>=20 >>> On 8/13/25 13:58, Nicolas Grekas wrote: >>> > I wish we had some process to revert that decision. Now is the les= s costly >>> > time to do it, even if it's already late. >>>=20 >>> There is always the option of =E2=80=9Dnot implementing=E2=80=9D the= decision. Reverting=20 >>> would mean another RFC that would also require a 2/3 majority. >>=20 >> I'm happy to do it this way if that's the consensus. >>=20 >> =20 >>> > The discussion period failed to raise the points made by Jakub in = the PR ( >>> > https://github.com/php/php-src/pull/19435) and failed a serious im= pact >>> > analysis IMHO. >>> > This should be enough to raise a flag and allow us to reconsider. >>> > I wonder if people that voted in favor of deprecating __sleep/wake= up would >>> > still vote the same now? >>>=20 >>> I already participated in the PR discussion and having slept over it= , I=20 >>> think it would be helpful to consider both __sleep() and __wakeup()=20 >>> separately in this discussion of whether or not to actually follow=20 >>> through with doing the deprecation. >>>=20 >>> As I've mentioned in the PR, `__sleep()` is actually broken when=20 >>> inheritance is involved and there's also a trivial way to implement=20 >>> `__serialize()` while preserving compatibility: >>>=20 >>> public function __serialize() { >>> return get_mangled_object_vars($this); >>> } >>=20 >> Well, the way to introduce __serialize while maintaining compatibilit= y with both child classes and existing payloads is to copy/paste the sam= e boilerplate over and over: >>=20 >> public function __serialize(): array >> { >> $data =3D []; >> foreach ($this->__sleep() as $key) { >> $data[$key] =3D $this->$key; >> } >> return $data; >> } >>=20 >> And then, this has exactly the same issue regarding private propertie= s, without any better way since this has to call __sleep to account for = child classes. >> This is just moving the concern elsewhere without any benefit. >> On their side, child classes that do have an issue with private prope= rties can already implement __serialize on their side, there's nothing t= o fix here: __sleep works well, and there's already an upgrade path when= it's not enough. >>=20 >> =20 >>> So while this one might result in some amount of migration work, it'= s=20 >>> reasonably easy to do. >>>=20 >>> `__wakeup()` on the other hand is not broken and migrating to=20 >>> `__unserialize()` is non-trivial. >>>=20 >>> So deprecating `__sleep()` with PHP 8.5 still makes sense to me. For=20 >>> `__wakeup()` I don't have a strong opinion either way and I've also=20 >>> intentionally abstained from voting on this deprecation. >>=20 >> implementing __unserialize to satisfy a proper upgrade path for paylo= ad and child classes might be done this way: >>=20 >> public function __unserialize(array $data): void >> { >> foreach ($data as $key =3D> $value) { >> $this->{("\0" =3D=3D=3D $key[0] ?? '') ? substr($key, 1 += strrpos($key, "\0")) : $key} =3D $value; >> } >> $this->__wakeup(); >> } >>=20 >> Again, this doesn't work with private properties. >>=20 >> The previous code was better and safer, and contained less boilerplat= e. >>=20 >> I made a draft PR for SYmfony here: https://github.com/symfony/symfon= y/pull/61407 >> I'm not sure the implementation is correct yet. >> That's just to show the kind of impact this could have. >>=20 >> Deprecating only sleep and not wakeup would at least fix the complexi= ty of the __unserialize replacement. >> But then, this would fail the purpose of the RFC, which was to get ri= d of sleep/wakeup altogether. >>=20 >> This deprecation is a net loss on every aspect. >>=20 >> Nicolas > > Here is the result of my investigation; the kind code that everybody=20 > that cares about FC/BC for child classes and payloads will have to us= e=20 > (above PR is up to date): > > public function __serialize(): array > { > $data =3D []; > foreach ($this->__sleep() as $key) { > try { > if (($r =3D new \ReflectionProperty($this,=20 > $key))->isInitialized($this)) { > $data[$key] =3D $r->getValue($this); > } > } catch (\ReflectionException) { > $data[$key] =3D $this->$key; > } > } > return $data; > } > public function __unserialize(array $data): void > { > \Closure::bind(function ($data) { > foreach ($data as $key =3D> $value) { > $this->{("\0" =3D=3D=3D $key[0] ?? '') ? substr($key, = 1 +=20 > strrpos($key, "\0")) : $key} =3D $value; > } > $this->__wakeup(); > }, $this, static::class)($data); > } Eew. :-) I support the goal of having only one serialization process for devs to = think about, but it does need to have a clear and graceful transition fo= r existing code. The above code does not strike me as "clear and gracef= ul transition." From the RFC: > Having multiple serializations methods which can be superseded by newe= r methods is somewhat confusing and add unnecessary complexity to the la= nguage.=20 I agree, which is why I voted Yes on that part. > Because the __serialize()/__unserialize() mechanism is a straight up i= mprovement over __sleep()/__wakeup() we propose to deprecate the latter = in favour of the former.=20 This claim now appears to be incorrect, given Nicolas' investigation. (= Ie, it's not a straight up improvement, nor a drop-in replacement.) I would be in favor of holding off implementing this deprecation until a= better transition process is found, and/or an RFC to reverse it. (I de= fer to the RMs on the process they want to follow.) (And I think this does lend still more weight to Juliette's frequent req= uest for more robust impact analysis for deprecations. Not because depr= ecations are bad, but because we should know what the impact is so we kn= ow how to mitigate it effectively.) --Larry Garfield