Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125404 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 5B0401A00BD for ; Tue, 3 Sep 2024 06:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1725345076; bh=nuauvLRa8IGveaXniiK2HmY960uZVYNsu1I/nOnBh/s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=md7Bbaq1gxj6Yz6t0qgazd9+WIhbKefzaqJQ7mZl+cUqrDYV0rNFv52NPsfI+eqm/ hn8mo77mQ7w1YW1c1P36NhqNbJD7zn+1eg77Vub4qQWagM1ymO4ds9TJ/Ve3wfmvor 7ujakuiZ7Dloyc4ucEsZiLSaIBkVN+WCs8M1ZFDJ+TKUdc0lg4wJbdJIyIWFzLJlV7 oRwcDx61jXti52VTeNH+YzcOxgadz8IGcooYfy0k/+CT0oq/dn8VsfbfNt16NVBMlx komnnUay0XAAajFgKigp3lZBe5c0gCG2RDddCTJllAF1ag1VGNR+K+XRicb0SNDRXq CGvmhTscGcm3A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B79EC180032 for ; Tue, 3 Sep 2024 06:31:14 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (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 ; Tue, 3 Sep 2024 06:31:14 +0000 (UTC) Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3df0f0b8111so2828404b6e.3 for ; Mon, 02 Sep 2024 23:29:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sensational.ch; s=google; t=1725344956; x=1725949756; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=a/TefKYEM4/p0v9dEn9HypJn9znE9xVwyMieKI/5qQg=; b=AXymF5KegyQwijzPTbXxjZqg3XLuarkg4Efn5gSJVIv6fRTW0wpQnp+cZy8OQBcHlA hwlG5AmRJ3FOmDMOD9neLQsg6YilR22MCe3QXyP/RJpT1As53cQuEZFIb40fEUv4ilPx iOzMN18INrxcUQ3NwOQEDZBFLJg4tMVnler6Ib6hxC91PpPQvd4NoOFrOPXRvQ0ELqhH f0UdOJKuHJj2vw3bmBef2wBud/9x5WwuyligyIw2PS9waOvxv26ufytoPP9qC2EJfNHE rIIzKWPygiS/VEBwMoh5+xZCPl/gwyCFiej/W5eHZYMOToYGl9H6rBKCwTGM417ONC85 sZTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725344956; x=1725949756; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=a/TefKYEM4/p0v9dEn9HypJn9znE9xVwyMieKI/5qQg=; b=MKmpT03Shdyz/upl0x4wVTRYdk249qfwbVmyZBA995KIILl3UoVWKHOHrRGQigK+Qq 0R2Zxi3Wq/CeUaGsL6MCgCmYGWbc6ekiwFJD/umVBtFQSfzwtQRAuYjI8gS7L2GsmxSg HGhNrfJnvT5n9UTcqF7XooVJCjwSXPwnNuGJOQhKa63ksWXHXIm5tOz2uT8tvGcouwTu 1pi2B1ImfiQHObDmHHkn0nYjbkGiz4r8Iqoxn//QddwGplqDF29LqsOT6Ovqu/llfIh5 ST2VYIx0BxBymBNPXllqcAJTiDdqSgxvhVlhf/FwwBah3reJ3rFBp9xJrtjh/i2tFYlh KWdA== X-Gm-Message-State: AOJu0Yy1FI4RWcDfpViVO9dILmaHxMC+xrhmYBKrk5nPjWQQv9aQXJ92 DXpL5Q8Xykvefg0JjIa7ncBNXFzl5zHvUk1lVMbK7iAwC7nYicQWhBuWFTuQ5LYQ0BVAZe79ILT gS4mvYjN6XJ531i3Gg9/yvHS8OMVDo3s5UKzO5msmV6lwPck2qPQ= X-Google-Smtp-Source: AGHT+IGtVlh1WNRyCbMc/H9rBPWjhMg+OtpC+Q2AU33pZdm2OrUmJ/xBX9IDrTrlIR2sivexFysqzYvGuW0g2NABMIk= X-Received: by 2002:a05:6808:238b:b0:3de:e7cd:c7d4 with SMTP id 5614622812f47-3e00cb903dbmr850981b6e.26.1725344956217; Mon, 02 Sep 2024 23:29:16 -0700 (PDT) Received: from 1064022179695 named unknown by gmailapi.google.com with HTTPREST; Mon, 2 Sep 2024 23:29:15 -0700 Received: from 1064022179695 named unknown by gmailapi.google.com with HTTPREST; Mon, 2 Sep 2024 23:29:12 -0700 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 (Mimestream 1.3.8) References: <783E4F90-4823-4224-B45C-E9D6EFC4479F@gmail.com> In-Reply-To: <783E4F90-4823-4224-B45C-E9D6EFC4479F@gmail.com> Date: Mon, 2 Sep 2024 23:29:15 -0700 Message-ID: Subject: Re: [PHP-DEV] json_encode() and Generators / RFC Karma To: Claude Pache Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000003b1cdb0621312dcc" From: phofstetter@sensational.ch (Philip Hofstetter) --0000000000003b1cdb0621312dcc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Aug 30, 2024 at 16:47:43, Claude Pache wrote: > > Note that the issue is not limited to Generators. For instance a Closure > object is also json-encodable but not serialisable. > > IMO, every internal class (not just Generator) that is marked as > non-serialisable, should also be non-json-encodable. > Thank you for brining this up. When working on the implementation to link to the RFC, I came across ZEND_ACC_NOT_SERIALIZABLE and its usage with serialize() and it occurred to me that there=E2=80=99s probably some sense in making json_enco= de look at that flag in general. Of course this would greatly increase the amount of possible deprecation warnings thrown and other objects flagged with ZEND_ACC_NOT_SERIALIZABLE (resource handles, reflection, and, yes, Closure) are not as likely to cause harm as Generators do because refactoring something from arrays to Generators is a relatively common operation which also is mostly transparent to the majority of callers, so a deprecation warning and later error will provide actual value in this case whereas json_encode() over an accidentally present, say, CurlHandle is of no consequence for a user, so little value is provided by the eventually thrown exception. Implementation-wise, I can say that using ZEND_ACC_NOT_SERIALIZABLE is super simple and turning this into a 2 line patch (plus a few lines of test code), but I=E2=80=99m a bit concerned about the large BC surface, even tho= ugh I do agree that conceptionally ZEND_ACC_NOT_SERIALIZABLE should be used. I will write the RFC based on ZEND_ACC_NOT_SERIALIZABLE and if it turns out in discussion or in the voting phase that the BC concerns are too grave, I will find and propose an implementation that=E2=80=99s more specific to Gen= erators. Philip --0000000000003b1cdb0621312dcc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,


On Aug 30, 2024 at 16:47:43, Clau= de Pache <claude.pache@gmail.c= om> wrote:
=20

Note that the issue is not limited to Generators. For instance a C= losure object is also json-encodable but not serialisable.

IMO, ever= y internal class (not just Generator) that is marked as non-serialisable, s= hould also be non-json-encodable.

Thank you for brining this up.=C2=A0

When working on the implementation to link to the RFC, I ca= me across=C2=A0ZEND_ACC_NOT_SERIALIZABLE and its usage with serialize() and= it occurred to me that there=E2=80=99s probably some sense in making json_= encode look at that flag in general.

Of course this would= greatly increase the amount of possible deprecation warnings thrown and ot= her objects flagged with=C2=A0ZEND_ACC_NOT_SERIALIZABLE (resource handles, = reflection, and, yes, Closure) are not as likely to cause harm as Generator= s do because refactoring something from arrays to Generators is a relativel= y common operation which also is mostly transparent to the majority of call= ers, so a deprecation warning and later error will provide actual value in = this case whereas json_encode() over an accidentally present, say, CurlHand= le is of no consequence for a user, so little value is provided by the even= tually thrown exception.

Implementation-wise, I can say t= hat using=C2=A0ZEND_ACC_NOT_SERIALIZABLE is super simple and turning this i= nto a 2 line patch (plus a few lines of test code), but I=E2=80=99m a bit c= oncerned about the large BC surface, even though I do agree that conception= ally=C2=A0ZEND_ACC_NOT_SERIALIZABLE should be used.

I wil= l write the RFC based on ZEND_ACC_NOT_SERIALIZABLE and if it turns out in d= iscussion or in the voting phase that the BC concerns are too grave, I will= find and propose an implementation that=E2=80=99s more specific to Generat= ors.

Philip
--0000000000003b1cdb0621312dcc--