mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
releases property attributes of internal classes (#11980)
* adds test case for internal class property attribute * releases property attributes of internal classes
This commit is contained in:
@@ -447,6 +447,9 @@ ZEND_API void destroy_zend_class(zval *zv)
|
||||
if (prop_info->ce == ce) {
|
||||
zend_string_release(prop_info->name);
|
||||
zend_type_release(prop_info->type, /* persistent */ 1);
|
||||
if (prop_info->attributes) {
|
||||
zend_hash_release(prop_info->attributes);
|
||||
}
|
||||
free(prop_info);
|
||||
}
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
|
||||
@@ -50,6 +50,7 @@ static zend_class_entry *zend_test_parameter_attribute;
|
||||
static zend_class_entry *zend_test_property_attribute;
|
||||
static zend_class_entry *zend_test_class_with_method_with_parameter_attribute;
|
||||
static zend_class_entry *zend_test_child_class_with_method_with_parameter_attribute;
|
||||
static zend_class_entry *zend_test_class_with_property_attribute;
|
||||
static zend_class_entry *zend_test_forbid_dynamic_call;
|
||||
static zend_class_entry *zend_test_ns_foo_class;
|
||||
static zend_class_entry *zend_test_ns_unlikely_compile_error_class;
|
||||
@@ -1021,6 +1022,12 @@ PHP_MINIT_FUNCTION(zend_test)
|
||||
zend_test_class_with_method_with_parameter_attribute = register_class_ZendTestClassWithMethodWithParameterAttribute();
|
||||
zend_test_child_class_with_method_with_parameter_attribute = register_class_ZendTestChildClassWithMethodWithParameterAttribute(zend_test_class_with_method_with_parameter_attribute);
|
||||
|
||||
zend_test_class_with_property_attribute = register_class_ZendTestClassWithPropertyAttribute();
|
||||
{
|
||||
zend_property_info *prop_info = zend_hash_str_find_ptr(&zend_test_class_with_property_attribute->properties_info, "attributed", sizeof("attributed") - 1);
|
||||
zend_add_property_attribute(zend_test_class_with_property_attribute, prop_info, zend_test_attribute->name, 0);
|
||||
}
|
||||
|
||||
zend_test_forbid_dynamic_call = register_class_ZendTestForbidDynamicCall();
|
||||
|
||||
zend_test_ns_foo_class = register_class_ZendTestNS_Foo();
|
||||
|
||||
@@ -107,6 +107,12 @@ namespace {
|
||||
): int {}
|
||||
}
|
||||
|
||||
class ZendTestClassWithPropertyAttribute {
|
||||
// this attribute must be added internally in MINIT
|
||||
#[ZendTestAttribute]
|
||||
public string $attributed;
|
||||
}
|
||||
|
||||
final class ZendTestForbidDynamicCall {
|
||||
public function call(): void {}
|
||||
public static function callStatic(): void {}
|
||||
|
||||
23
ext/zend_test/test_arginfo.h
generated
23
ext/zend_test/test_arginfo.h
generated
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: b458993ee586284b1e33848313d9ddf61273604e */
|
||||
* Stub hash: f2d1e5675f75661048645bedc2e73b7d4894f8dc */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
@@ -392,6 +392,11 @@ static const zend_function_entry class_ZendTestChildClassWithMethodWithParameter
|
||||
};
|
||||
|
||||
|
||||
static const zend_function_entry class_ZendTestClassWithPropertyAttribute_methods[] = {
|
||||
ZEND_FE_END
|
||||
};
|
||||
|
||||
|
||||
static const zend_function_entry class_ZendTestForbidDynamicCall_methods[] = {
|
||||
ZEND_ME(ZendTestForbidDynamicCall, call, arginfo_class_ZendTestForbidDynamicCall_call, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(ZendTestForbidDynamicCall, callStatic, arginfo_class_ZendTestForbidDynamicCall_callStatic, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
|
||||
@@ -725,6 +730,22 @@ static zend_class_entry *register_class_ZendTestChildClassWithMethodWithParamete
|
||||
return class_entry;
|
||||
}
|
||||
|
||||
static zend_class_entry *register_class_ZendTestClassWithPropertyAttribute(void)
|
||||
{
|
||||
zend_class_entry ce, *class_entry;
|
||||
|
||||
INIT_CLASS_ENTRY(ce, "ZendTestClassWithPropertyAttribute", class_ZendTestClassWithPropertyAttribute_methods);
|
||||
class_entry = zend_register_internal_class_ex(&ce, NULL);
|
||||
|
||||
zval property_attributed_default_value;
|
||||
ZVAL_UNDEF(&property_attributed_default_value);
|
||||
zend_string *property_attributed_name = zend_string_init("attributed", sizeof("attributed") - 1, 1);
|
||||
zend_declare_typed_property(class_entry, property_attributed_name, &property_attributed_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
|
||||
zend_string_release(property_attributed_name);
|
||||
|
||||
return class_entry;
|
||||
}
|
||||
|
||||
static zend_class_entry *register_class_ZendTestForbidDynamicCall(void)
|
||||
{
|
||||
zend_class_entry ce, *class_entry;
|
||||
|
||||
14
ext/zend_test/tests/attribute-internal-property.phpt
Normal file
14
ext/zend_test/tests/attribute-internal-property.phpt
Normal file
@@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
Tests attributes on internal class properties.
|
||||
--EXTENSIONS--
|
||||
zend_test
|
||||
reflection
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$prop = new \ReflectionProperty(ZendTestClassWithPropertyAttribute::class, 'attributed');
|
||||
$attr = $prop->getAttributes(ZendTestAttribute::class)[0];
|
||||
var_dump($attr->getName());
|
||||
?>
|
||||
--EXPECT--
|
||||
string(17) "ZendTestAttribute"
|
||||
Reference in New Issue
Block a user