]> granicus.if.org Git - php/commit
Add flag to forbid dynamic property creation on internal classes
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 14 May 2020 09:51:36 +0000 (11:51 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 24 Jun 2020 09:52:36 +0000 (11:52 +0200)
commit653e4ea1c57def2d5cd75b7da9e3943a841b7d6c
tree479717f0e9a8eb24e733990512304fc7209ca45d
parent2a28589c7def80ecc7bb3417a8853df6b7860b46
Add flag to forbid dynamic property creation on internal classes

While performing resource -> object migrations, we're adding
defensive classes that are final, non-serializable and non-clonable
(unless they are, of course). This path 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.

Closes GH-5572.
13 files changed:
Zend/tests/weakrefs/weakmap_error_conditions.phpt
Zend/tests/weakrefs/weakrefs_003.phpt
Zend/zend_compile.h
Zend/zend_object_handlers.c
Zend/zend_weakrefs.c
ext/curl/interface.c
ext/curl/multi.c
ext/curl/share.c
ext/enchant/enchant.c
ext/sysvsem/sysvsem.c
ext/sysvshm/sysvshm.c
ext/xml/xml.c
ext/zlib/zlib.c