Add internal flag to forbid dynamic properties#5572
Closed
nikic wants to merge 3 commits intophp:masterfrom
Closed
Add internal flag to forbid dynamic properties#5572nikic wants to merge 3 commits intophp:masterfrom
nikic wants to merge 3 commits intophp:masterfrom
Conversation
cmb69
approved these changes
May 18, 2020
Member
cmb69
left a comment
There was a problem hiding this comment.
Especially considering #5533 (comment), I'm very much in favor of this.
Zend/zend_weakrefs.c
Outdated
| @@ -239,36 +239,6 @@ static void zend_weakref_free(zend_object *zo) { | |||
| #define zend_weakref_unsupported(object, thing) \ | |||
Contributor
There was a problem hiding this comment.
I believe this can be dropped as well.
This is slightly weaker than the existing code, but I think this makes more sense. In particular something like isset($wr->foobar) should just return false instead of throwing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While performing resource -> object migrations, we're adding defensive classes that are final, non-serializable and non-clonable (unless they are, of course). This PR adds a ZEND_ACC_NO_DYNAMIC_PROPERTIES flag, that also forbids the creation of dynamic properties on these objects. This is a subset of #3931 and targeted at internal usage only (though may be extended to userland at some point in the future).
It's already possible to achieve this (what the removed WeakRef/WeakMap code does), but there's some caveats: First, this simple approach is only possible if the class has no declared properties, otherwise it's necessary to special-case those properties. Second, it's easy to make it overly strict, e.g. by forbidding
isset($obj->prop)as well. And finally, it requires a lot of boilerplate code for each class.I think it would be useful to provide this functionality directly, especially as it's so easy/cheap.