Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125435 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 qa.php.net (Postfix) with ESMTPS id F22A21A00BD for ; Thu, 5 Sep 2024 09:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1725529818; bh=WSlo5DTW8hqP5kywUdSoHS0eYMnI/FwMw9T9LZ0l+Dw=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=EWo4L+KNUSC3PMpPf+e+ovYhdg8Pr3fezIjV6+enxo2Oznv+zrqJnR4vVIlDxajjE pYoaFaUXGj93RBdiwT7Si3BCAeSJKHry6VkBQFY3YBb4+pRWDHIVc/x33MKD5xSsus 7h9W2WenbhwuYpoiE51rbiJHEyDZSvlJmrPvx6UwrOYCnF1pL7DIkzLKshBhKGNRqt sCI7zl5CGUIjQHJqcorEN7fugBCFTwbsCL87rTsRNGQL947gWOxHfnTcbu5/KtowS6 M9TtDdcws0AsntPJbDpGppltDmmeAMYRfRI/rkF+9aBEcwHo6ozP+YHgZraidTFw8+ HHzGjcZn8fYLw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1B171180052 for ; Thu, 5 Sep 2024 09:50:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 ; Thu, 5 Sep 2024 09:50:17 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 0513213802BE; Thu, 5 Sep 2024 05:48:19 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-03.internal (MEProxy); Thu, 05 Sep 2024 05:48:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc: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=fm2; t=1725529698; x= 1725616098; bh=WSlo5DTW8hqP5kywUdSoHS0eYMnI/FwMw9T9LZ0l+Dw=; b=v ICcqN9rZFA85VAmCY/T74N18ur9K29nUYRUWYLmcAreaYlpJhpguKnclFSwJe/F2 8Q17/WrO2ZdWpMz5bfOptR13hejJYc13KNrR/Pec/kxOsqRAgLwNULBI5w5p4RoO yj0maGehlJVBJgm9zUvvhl32Mzljquyk+NqMfKetpa4Y9StNJmCBb75A3vIet+0U rq0lbGZlCXUlfmmhGqD/T5nxg/3BwnyMb9ugtJ1D2b51OnXA/v6447WAiP1f6YSn ZQAzUnD+yJlhIzrcgun6Bv1OdyEd3AUZ7k46VXhDQZ8pFlWMLV3oOYqnSOtQ661c Ve2qsCz2CiIuT3evssfOw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725529698; x=1725616098; bh=WSlo5DTW8hqP5kywUdSoHS0eYMnI /FwMw9T9LZ0l+Dw=; b=KuIwKIAOYX07yAKvnUMqVnj5Ygytv1eZ6pEKxnfaypYG tW/G8CdqkGXLeHAuKIGYYPW6BxDb46vVQZ56fz11zz+QzCxvF0E5SB7lgw41Tyvo prAAAkH4SlgdHlDcsL5TMAKKaCnAj/ZrCxpUG5AiV5uNcdffaHLWj6+KKA/GGeXN m3pWxOcsRgaOnuqDFRNBrtquNWrGT6yLA4zU+83gsZL0xpMOUo0gy18JJcWvInnt 95QNUazOMCHvxuNbZ6IQT6BRCqegD6jTOKfnK0zfYpoHrO2lJLzEL4AH7TcnQZ3v rXbz4sgj8p4AEsvmgVG5ebGjLjUAXqHCS4NHIA9w+Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepofggfffhvfevkfgjfhfutgesrgdtreerredtjeen ucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtoh guvghsqeenucggtffrrghtthgvrhhnpeffgeevveegtdffgfffvdfftddvheeuleegveek teffueeliedtgeekjeettdetkeenucffohhmrghinhepphhhphdrnhgvthenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhl vggurdgtohguvghspdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprh gtphhtthhopegurhgvrghlvggtshesghhmrghilhdrtghomhdprhgtphhtthhopehinhht vghrnhgrlhhssehlihhsthhsrdhphhhprdhnvghtpdhrtghpthhtohepphhhohhfshhtvg htthgvrhesshgvnhhsrghtihhonhgrlhdrtghh X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 4F025780067; Thu, 5 Sep 2024 05:48:18 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 05 Sep 2024 11:47:57 +0200 To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= , "Philip Hofstetter" Cc: "PHP internals" Message-ID: <24ee415a-5963-4b3d-a034-eacf4fed29ca@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] RFC: Deprecate json_encode() on classes marked as non-serializable Content-Type: multipart/alternative; boundary=3af0aeaaff8a4917ba21d376c995e973 From: rob@bottled.codes ("Rob Landers") --3af0aeaaff8a4917ba21d376c995e973 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Sep 5, 2024, at 10:55, Alexandru P=C4=83tr=C4=83nescu wrote: >=20 > On Tue, Sep 3, 2024 at 2:27=E2=80=AFPM Philip Hofstetter wrote: >> Hello, >>=20 >> As per my previous email to the list, I have now created the official= RFC to deprecate calling json_serialize() on instances of classes marke= d with ZEND_ACC_NOT_SERIALIZABLE. >>=20 >> https://wiki.php.net/rfc/deprecate-json_encode-nonserializable >>=20 >>=20 >=20 > Sharing my experience, I never use json_encode on objects but on array= s (that are both JSON objects or JSON arrays). > When I see an object implementing JsonSerializable, I think it is the = wrong approach, and I am usually able to find a better way. > Maybe if we could go back in time, we would not allow json_encode on a= n object, except if it implemented JsonSerializable, but that ship saile= d long ago. >=20 > To your proposal, I think the BC break would be pretty big and I don't= see a way it would pass. > On https://www.php.net/json_encode we can read: > > If a value to be serialized is an object, then by default only publi= cly visible properties will be included. > So that's the expected behaviour. >=20 > Yes, you can say that encoding as JSON is just "another serialization = method", but the default method in PHP, using json_encode()/json_decode(= ), is not symmetrical when using objects. > And here lies the difference with serialize()/unserialize(), as this o= ne aims to be symmetrical, and where it can't be, it has a way to stop t= he serialization. >=20 > I am happy with the current way it works, getting an empty JSON object= if there are no public properties for a Generator or Closure. > And I don't think having an error for them would improve the language = in a meaningful way, and the BC break is not worth it. >=20 > Regards, > Alex >=20 To add to this, we apparently use json_encode at work to serialize custo= m exceptions, which appears to work. This RFC would break that, I think.=20 =E2=80=94 Rob --3af0aeaaff8a4917ba21d376c995e973 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

=
On Thu, Sep 5, 2024, at 10:55, Alexandru P=C4=83tr=C4=83n= escu wrote:

On Tue, Sep 3, 2024 at 2:27=E2=80= =AFPM Philip Hofstetter <phofstetter@sensational.ch> wrote:
Hello,

As per my previous email to the list, I have now c= reated the official RFC to deprecate calling json_serialize() on instanc= es of classes marked with ZEND_ACC_NOT_SERIALIZABLE.




Sharing my experience, I never use json_encode = on objects but on arrays (that are both JSON objects or JSON arrays).
When I see an object implementing JsonSerializable, I think = it is the wrong approach, and I am usually able to find a bett= er way.
Maybe if we could go back in time, we would not al= low json_encode on an object, except if it implemented JsonSerializable,= but that ship sailed long ago.

To your pro= posal, I think the BC break would be pretty big and I don't see a way it= would pass.
&g= t; If a value to be serialized is an object, then by default only p= ublicly visible properties will be included.
So that's the= expected behaviour.

Yes, you can say that = encoding as JSON is just "another serialization method", but the de= fault method in PHP, using json_encode()/json_decode(), is not symmetric= al when using objects.
And here lies the difference w= ith serialize()/unserialize(), as this one aims to be symmetrical, and w= here it can't be, it has a way to stop the serialization.
=
I am happy with the current way it works, getting an empt= y JSON object if there are no public properties for a Generator or Closu= re.
And I don't think having an error for them would impro= ve the language in a meaningful way, and the BC break is not worth it.

Regards,
Alex

To add to this, we = apparently use json_encode at work to serialize custom exceptions, which= appears to work. This RFC would break that, I think. 
=E2=80=94 Rob
--3af0aeaaff8a4917ba21d376c995e973--