-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
base: master
Are you sure you want to change the base?
Conversation
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.
Makes sense but all deprecations are going through RFC so it needs to wait till 8.5. |
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typo
json_encode() on instances of classes market with ZEND_ACC_NOT_SERIALIZABLE | |
json_encode() on instances of classes marked with ZEND_ACC_NOT_SERIALIZABLE |
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