Skip to content

Commit 3e0e7e3

Browse files
authored
releases property attributes of internal classes (#11980)
* adds test case for internal class property attribute * releases property attributes of internal classes
1 parent f25474f commit 3e0e7e3

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

Zend/zend_opcode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ ZEND_API void destroy_zend_class(zval *zv)
447447
if (prop_info->ce == ce) {
448448
zend_string_release(prop_info->name);
449449
zend_type_release(prop_info->type, /* persistent */ 1);
450+
if (prop_info->attributes) {
451+
zend_hash_release(prop_info->attributes);
452+
}
450453
free(prop_info);
451454
}
452455
} ZEND_HASH_FOREACH_END();

ext/zend_test/test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static zend_class_entry *zend_test_parameter_attribute;
5050
static zend_class_entry *zend_test_property_attribute;
5151
static zend_class_entry *zend_test_class_with_method_with_parameter_attribute;
5252
static zend_class_entry *zend_test_child_class_with_method_with_parameter_attribute;
53+
static zend_class_entry *zend_test_class_with_property_attribute;
5354
static zend_class_entry *zend_test_forbid_dynamic_call;
5455
static zend_class_entry *zend_test_ns_foo_class;
5556
static zend_class_entry *zend_test_ns_unlikely_compile_error_class;
@@ -1021,6 +1022,12 @@ PHP_MINIT_FUNCTION(zend_test)
10211022
zend_test_class_with_method_with_parameter_attribute = register_class_ZendTestClassWithMethodWithParameterAttribute();
10221023
zend_test_child_class_with_method_with_parameter_attribute = register_class_ZendTestChildClassWithMethodWithParameterAttribute(zend_test_class_with_method_with_parameter_attribute);
10231024

1025+
zend_test_class_with_property_attribute = register_class_ZendTestClassWithPropertyAttribute();
1026+
{
1027+
zend_property_info *prop_info = zend_hash_str_find_ptr(&zend_test_class_with_property_attribute->properties_info, "attributed", sizeof("attributed") - 1);
1028+
zend_add_property_attribute(zend_test_class_with_property_attribute, prop_info, zend_test_attribute->name, 0);
1029+
}
1030+
10241031
zend_test_forbid_dynamic_call = register_class_ZendTestForbidDynamicCall();
10251032

10261033
zend_test_ns_foo_class = register_class_ZendTestNS_Foo();

ext/zend_test/test.stub.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ public function override(
107107
): int {}
108108
}
109109

110+
class ZendTestClassWithPropertyAttribute {
111+
// this attribute must be added internally in MINIT
112+
#[ZendTestAttribute]
113+
public string $attributed;
114+
}
115+
110116
final class ZendTestForbidDynamicCall {
111117
public function call(): void {}
112118
public static function callStatic(): void {}

ext/zend_test/test_arginfo.h

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Tests attributes on internal class properties.
3+
--EXTENSIONS--
4+
zend_test
5+
reflection
6+
--FILE--
7+
<?php
8+
9+
$prop = new \ReflectionProperty(ZendTestClassWithPropertyAttribute::class, 'attributed');
10+
$attr = $prop->getAttributes(ZendTestAttribute::class)[0];
11+
var_dump($attr->getName());
12+
?>
13+
--EXPECT--
14+
string(17) "ZendTestAttribute"

0 commit comments

Comments
 (0)