Add support for using final properties in stubs (#17306)

This commit is contained in:
Máté Kocsis 2025-01-06 07:56:13 +01:00 committed by GitHub
parent e4ad271073
commit 684ef016e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 1 deletions

View file

@ -75,6 +75,8 @@ object(_ZendTestClass)#1 (3) {
uninitialized(Traversable&Countable)
["readonlyProp"]=>
uninitialized(int)
["finalProp"]=>
uninitialized(int)
["dnfProperty"]=>
uninitialized(Iterator|(Traversable&Countable))
}
@ -93,6 +95,8 @@ object(Test)#4 (3) {
uninitialized(Traversable&Countable)
["readonlyProp"]=>
uninitialized(int)
["finalProp"]=>
uninitialized(int)
["dnfProperty"]=>
uninitialized(Iterator|(Traversable&Countable))
}

View file

@ -3103,6 +3103,10 @@ class PropertyInfo extends VariableLike
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_STATIC", PHP_70_VERSION_ID);
}
if ($this->flags & Modifiers::FINAL) {
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_FINAL", PHP_84_VERSION_ID);
}
if ($this->flags & Modifiers::READONLY) {
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_READONLY", PHP_81_VERSION_ID);
} elseif ($this->classFlags & Modifiers::READONLY) {
@ -3125,6 +3129,11 @@ class PropertyInfo extends VariableLike
$fieldsynopsisElement->appendChild($doc->createElement("modifier", "static"));
}
if ($this->flags & Modifiers::FINAL) {
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($doc->createElement("modifier", "final"));
}
if ($this->flags & Modifiers::READONLY || $this->isDocReadonly) {
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($doc->createElement("modifier", "readonly"));

View file

@ -55,6 +55,7 @@ namespace {
public stdClass|Iterator|null $classUnionProp = null;
public Traversable&Countable $classIntersectionProp;
public readonly int $readonlyProp;
public final int $finalProp;
public static function is_object(): int {}

View file

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: a7b5de3e4868f9a4aef78da6b98bbce882e129a9 */
* Stub hash: 3082e62e96d5f4383c98638513463c676a7c3a69 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
@ -719,6 +719,16 @@ static zend_class_entry *register_class__ZendTestClass(zend_class_entry *class_e
#endif
zend_string_release(property_readonlyProp_name);
zval property_finalProp_default_value;
ZVAL_UNDEF(&property_finalProp_default_value);
zend_string *property_finalProp_name = zend_string_init("finalProp", sizeof("finalProp") - 1, 1);
#if (PHP_VERSION_ID >= 80400)
zend_declare_typed_property(class_entry, property_finalProp_name, &property_finalProp_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
#elif (PHP_VERSION_ID >= 80000)
zend_declare_typed_property(class_entry, property_finalProp_name, &property_finalProp_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
#endif
zend_string_release(property_finalProp_name);
zend_string *attribute_name_Deprecated_const_ZEND_TEST_DEPRECATED_ATTR_0 = zend_string_init_interned("Deprecated", sizeof("Deprecated") - 1, 1);
zend_attribute *attribute_Deprecated_const_ZEND_TEST_DEPRECATED_ATTR_0 = zend_add_class_constant_attribute(class_entry, const_ZEND_TEST_DEPRECATED_ATTR, attribute_name_Deprecated_const_ZEND_TEST_DEPRECATED_ATTR_0, 1);