summaryrefslogtreecommitdiff
path: root/ext/reflection/php_reflection.c
diff options
context:
space:
mode:
authorChristopher Broadbent <chris-broadbent@zencontrol.com>2020-07-15 14:47:21 +1000
committerNikita Popov <nikita.ppv@gmail.com>2020-07-15 10:58:56 +0200
commitee7c7a8e26b99e3b25a7d41abfe1a2c37b3f6968 (patch)
treebd5afd98753989fdea4686ed3a270806ec17b114 /ext/reflection/php_reflection.c
parentf855b59994ff9d9bd2493098a5327f2f44a2d899 (diff)
downloadphp-git-ee7c7a8e26b99e3b25a7d41abfe1a2c37b3f6968.tar.gz
Fixed bug #79820
Similar to what is done for ReflectionType itself, copy the type name stored inside ReflectionProperty. Also make sure the type field is always initialized for dynamic properties. This is a non-issue in PHP 8, because we store a pointer to the property_info there, rather than a copy.
Diffstat (limited to 'ext/reflection/php_reflection.c')
-rw-r--r--ext/reflection/php_reflection.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index c3c29d880b..f62dd15e1c 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -238,6 +238,11 @@ static void reflection_free_objects_storage(zend_object *object) /* {{{ */
case REF_TYPE_PROPERTY:
prop_reference = (property_reference*)intern->ptr;
zend_string_release_ex(prop_reference->unmangled_name, 0);
+
+ if (ZEND_TYPE_IS_NAME(prop_reference->prop.type)) {
+ zend_string_release(ZEND_TYPE_NAME(prop_reference->prop.type));
+ }
+
efree(intern->ptr);
break;
case REF_TYPE_GENERATOR:
@@ -1233,6 +1238,11 @@ static void reflection_property_factory(zend_class_entry *ce, zend_string *name,
intern = Z_REFLECTION_P(object);
reference = (property_reference*) emalloc(sizeof(property_reference));
reference->prop = *prop;
+
+ if (ZEND_TYPE_IS_NAME(reference->prop.type)) {
+ zend_string_addref(ZEND_TYPE_NAME(reference->prop.type));
+ }
+
reference->unmangled_name = zend_string_copy(name);
reference->dynamic = dynamic;
intern->ptr = reference;
@@ -4258,6 +4268,7 @@ ZEND_METHOD(reflection_class, getProperty)
property_info_tmp.name = name;
property_info_tmp.doc_comment = NULL;
property_info_tmp.ce = ce;
+ property_info_tmp.type = 0;
reflection_property_factory(ce, name, &property_info_tmp, return_value, 1);
return;
@@ -4339,6 +4350,7 @@ static void _adddynproperty(zval *ptr, zend_string *key, zend_class_entry *ce, z
property_info.name = key;
property_info.ce = ce;
property_info.offset = -1;
+ property_info.type = 0;
reflection_property_factory(ce, key, &property_info, &property, 1);
add_next_index_zval(retval, &property);
}
@@ -5319,10 +5331,15 @@ ZEND_METHOD(reflection_property, __construct)
reference->prop.name = name;
reference->prop.doc_comment = NULL;
reference->prop.ce = ce;
+ reference->prop.type = 0;
reference->dynamic = 1;
} else {
reference->prop = *property_info;
reference->dynamic = 0;
+
+ if (ZEND_TYPE_IS_NAME(reference->prop.type)) {
+ zend_string_addref(ZEND_TYPE_NAME(reference->prop.type));
+ }
}
reference->unmangled_name = zend_string_copy(name);
intern->ptr = reference;