Skip to content

deprecate json_encode() of non-serializable instances #15724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pilif
Copy link
Contributor

@pilif pilif commented Sep 3, 2024

there's a good reason for classes being marked as non-serializable, so it follows that the same should probably be true for json_encoding them as well.

As this flag is only available to internal classes, no userland code should be affected.

This is the implementation of an RFC I'm currently in the process of authoring after there was some mild agreement about this making sense when I asked on internals.

RFC (in draft): https://wiki.php.net/rfc/deprecate-json_encode-nonserializable

there's a good reason for classes being marked as non-serializable, so
it follows that the same should probably be true for json_encoding them
as well.

As this flag is only available to internal classes, no userland code
should be affected.
@pilif pilif requested a review from bukka as a code owner September 3, 2024 10:06
@bukka bukka added the RFC label Sep 3, 2024
@bukka
Copy link
Member

bukka commented Sep 3, 2024

Makes sense but all deprecations are going through RFC so it needs to wait till 8.5.

@pilif
Copy link
Contributor Author

pilif commented Sep 3, 2024

yes. absolutely. this is meant for 8.5

anonymous classes are market as ZEND_ACC_NOT_SERIALIZABLE because
unserisalizing them for later use is hard to impossible. However, in the
case jon json_encode(), as long as the parent class is serializable,
there's very little reason to forbidding to json_encode() anonymous
classes, indeed, that's probably very useful in case of userland parent
classes.
@@ -0,0 +1,24 @@
--TEST--
json_encode() on instances of classes market with ZEND_ACC_NOT_SERIALIZABLE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should be located in the corresponding tests directory for json extension, ext/json/tests. And despite the outcome of the discussion on the internal list, I would see the benefit of including the tests now. I was surprised that those paths were not tested already.

@@ -0,0 +1,24 @@
--TEST--
json_encode() on instances of classes market with ZEND_ACC_NOT_SERIALIZABLE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo

Suggested change
json_encode() on instances of classes market with ZEND_ACC_NOT_SERIALIZABLE
json_encode() on instances of classes marked with ZEND_ACC_NOT_SERIALIZABLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants