Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125443 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 CB87A1A00BD for ; Thu, 5 Sep 2024 20:15:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1725567472; bh=1RrI6r91LfZzh1KkQbpFfaQ4IchQa9+CEGPKkQRIEA4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QNnfUBDdknsTswDjUcV3KvNEkDNYP+UMRvh4dbx5GQiVH3SOHC2dBvEpkzNnGO1mB +9pCdu7vjkF8A0F+S5z8Mps0Bt17HtkvcL0MKUBFO8PU0rfioYe2RovOIExLJHQuT2 Ee3L2K3tNOhupgB5d6p9yektFZtHhczjjpBXP9WIC6q4QmJxBRZImAGTvmX5JzFJyA hDxgP7NRLJ5eLbDcUZFfjDYVYY9CMlner8DMpN3rmwwriLmoSE49TVlsqZSLtTtYuV JMhB/6FnIDIHCAD4xwu1Ms7QwXQxOYG1utrqO68rbWvjZ4ZD6wflQy4tn6UFxZBVeP zBPlZC0Ej52xg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 33F3818006A for ; Thu, 5 Sep 2024 20:17:51 +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_PASS,FREEMAIL_FROM, 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-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.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 ; Thu, 5 Sep 2024 20:17:47 +0000 (UTC) Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6d6891012d5so11502777b3.2 for ; Thu, 05 Sep 2024 13:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725567348; x=1726172148; 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=1RrI6r91LfZzh1KkQbpFfaQ4IchQa9+CEGPKkQRIEA4=; b=gpXiW6fQsTEZqxxTYsFGxQ+hYglylS1Esyq9GzGC9sPhCsJClbA5Q1TuTUFyXryH4E h05fkjfnMNuI5mKiFaIOBZuwqEooNZpnk0NST0mGqhcpOc3lk7bQ9Q1y+RT6LRhjDdQ/ y9WVUWTh1yOMTUPhcZ41fkHxpeOaAk1gKM5TixfZr5FVulaNkWqRzJmJgeQpj7UAQxnN jTg9yxk8m52moDISydPZ/D9sSo6VTbmo8yzXvtQAiktr7BzjtbH19XjWWOEM8upl545m cWfhvsKlfaiADOlxhG4WcmX5mq1HLZpJ0aaTAa8JJVa1DGxXaNE0YX3ESR6feoCkN6ZY 0yxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725567348; x=1726172148; 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=1RrI6r91LfZzh1KkQbpFfaQ4IchQa9+CEGPKkQRIEA4=; b=WZdpWNuyuJ2EZptFjcUx5V7f6vpUOO2lNwH/xH6j8FqeAoEodzsMlD8edZXyvJFfyq BholDl9zsIeNPdhCUaD4vYG4LHJmvCHhox2CV83u2yHliMKNa5dwO1sH6U4f84tJuQqX 5FTd+l7kJtnDPrHdy9uj7KXaFtl6/KqONgfiA9rKo8Izx8Va8o1s0A8jFz3ZOrCn/VBY Q93QdJljfri7ZX5XgCvmVimY1VHffC/2qhIua/H5mp3vPPwbyp++iwWoE5xJyMeOLkmW e4TusZ0lQOEqpTvtbBoSWP/MEcJRJ32WuTILQF3AHMn1hiqn7tddZbQfSPmmSIuthSZh 87/g== X-Gm-Message-State: AOJu0YyWZnY/4h0L+PDavs6eeCliAd39THjeISYyoP1DZz5m8z0Ay56V 7fSCsKFMKqVjC6xyclHmHD6Ru4LdUj3Q4/iWjZd2vWHSw6lnuZjkr7A04+vO6C380p1GnEAbCvb cll389Q2CMp/qlkSWMYTMkPgosjqCxUhknKo= X-Google-Smtp-Source: AGHT+IHcDM32toLGUssaIOSagLctmLbTlzmXV1tDfbrkBuLN48lizh5YnEmyxb7WTUADuMZWrVl0hclSWIwxkvy0iWg= X-Received: by 2002:a05:690c:6e0a:b0:6c3:856a:388d with SMTP id 00721157ae682-6db44f41796mr4515427b3.13.1725567348434; Thu, 05 Sep 2024 13:15:48 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 5 Sep 2024 16:15:38 -0400 Message-ID: Subject: Re: [PHP-DEV] RFC: Deprecate json_encode() on classes marked as non-serializable To: Philip Hofstetter Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000d6f60c062164f4b4" From: vasilii.b.shpilchin@gmail.com (Vasilii Shpilchin) --000000000000d6f60c062164f4b4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Philip, Thank you for your RFC, which is a great effort to improve serialization in PHP. Generators are indeed super useful and working with them should not be confusing. I regret that I missed your previous emails, but I would like to suggest that you consider the following concerns: 1. The original serialization and json_encode are not symmetric nor interchangeable by definition, because JSON doesn't preserve protected properties and class names. Hence, I don't see them to be "inconsistent" as they were not designed to be consistent. 2. The reason why some objects are not serializable is because they couldn't be fully functioning after deserialization. But this is not a barrier for JSON encoding, which serializing public properties only. Current JSON encoding has a simple, straight forward logic, not tied to serialization in any way. You have suggested to cast a non-serializable objects to array as a workaround. Yet, array is the most popular type to JSON in PHP. To me, an ideal move would be make json_encode to iterate any iterators from the input structure. Well, this is a different topic. Best regards, Vasilii On Tue, Sep 3, 2024, 7:26=E2=80=AFAM Philip Hofstetter wrote: > Hello, > > As per my previous email to the list, I have now created the official RFC > to deprecate calling json_serialize() on instances of classes marked with > ZEND_ACC_NOT_SERIALIZABLE. > > https://wiki.php.net/rfc/deprecate-json_encode-nonserializable > > I have also created a PR with the implementation here: > > https://github.com/php/php-src/pull/15724 > > I have considered other options, both constraining the implementation to > just Generator and/or to add special cases for Generator (and maybe > Iterator), but they either continue to keep the asymmetry between > serialize() and json_encode() and/or are making things even more > inconsistent. > > Please tell me what you think, especially, if you agree that > blanked-deprecating all of ZEND_ACC_NOT_SERIALIZABLE classes is acceptabl= e > BC-wise (after a bit of deliberation over the weekend, I think it is and > most json-serializations of such marked classes are probably unintentiona= l). > > Thanks in advance for all comments > > Philip > > > --000000000000d6f60c062164f4b4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello Philip,

Thank you for your RFC, which is a g= reat effort to improve serialization in PHP. Generators are indeed super us= eful and working with them should not be confusing.

I regret that I = missed your previous emails, but I would like to suggest that you consider = the following concerns:

1. The original serialization and json_encod= e are not symmetric nor interchangeable by definition, because JSON doesn&#= 39;t preserve protected properties and class names. Hence, I don't see = them to be "inconsistent" as they were not designed to be consist= ent.
2. The reason why some objects are not serializable is because they= couldn't be fully functioning after deserialization. But this is not a= barrier for JSON encoding, which serializing public properties only. Curre= nt JSON encoding has a simple, straight forward logic, not tied to serializ= ation in any way.

You have suggested to cast a non-serializable obje= cts to array as a workaround. Yet, array is the most popular type to JSON i= n PHP. To me, an ideal move would be make json_encode to iterate any iterat= ors from the input structure. Well, this is a different topic.

Best = regards,
Vasilii

<= div dir=3D"ltr" class=3D"gmail_attr">On Tue, Sep 3, 2024, 7:26=E2=80=AFAM P= hilip Hofstetter <phofstetter@sensational.= ch> wrote:
Hello,

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

I have a= lso created a PR with the implementation here:


I have considered other options, both constraining the i= mplementation to just Generator and/or to add special cases for Generator (= and maybe Iterator), but they either continue to keep the asymmetry between= serialize() and json_encode() and/or are making things even more inconsist= ent.

Please tell me what y= ou think, especially, if you agree that blanked-deprecating all of ZEND_ACC= _NOT_SERIALIZABLE classes is acceptable BC-wise (after a bit of deliberatio= n over the weekend, I think it is and most json-serializations of such mark= ed classes are probably unintentional).

Thanks in advance for all comments

=
Philip


--000000000000d6f60c062164f4b4--