From a7e597c7085bd0cbed7bda9701cd06b3e7ac653c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Mon, 30 Dec 2024 20:34:05 +0100 Subject: [PATCH 1/2] Add support for using final properties in stubs --- build/gen_stub.php | 9 +++++++++ ext/zend_test/test.stub.php | 1 + ext/zend_test/test_arginfo.h | 12 +++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 19eeef52cdb7d..aef737b37e526 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -3103,6 +3103,10 @@ protected function getFlagsByPhpVersion(): array $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 @@ protected function addModifiersToFieldSynopsis(DOMDocument $doc, DOMElement $fie $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")); diff --git a/ext/zend_test/test.stub.php b/ext/zend_test/test.stub.php index fbfd93da40975..59cb9661e4e43 100644 --- a/ext/zend_test/test.stub.php +++ b/ext/zend_test/test.stub.php @@ -55,6 +55,7 @@ class _ZendTestClass implements _ZendTestInterface { public stdClass|Iterator|null $classUnionProp = null; public Traversable&Countable $classIntersectionProp; public readonly int $readonlyProp; + public final int $finalProp; public static function is_object(): int {} diff --git a/ext/zend_test/test_arginfo.h b/ext/zend_test/test_arginfo.h index eb83d34fa1f59..c558b58f65169 100644 --- a/ext/zend_test/test_arginfo.h +++ b/ext/zend_test/test_arginfo.h @@ -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); From 9965c36ee933f4834ec15287903e3586fcc82280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 31 Dec 2024 14:40:31 +0100 Subject: [PATCH 2/2] Fix test --- Zend/tests/type_declarations/typed_properties_095.phpt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Zend/tests/type_declarations/typed_properties_095.phpt b/Zend/tests/type_declarations/typed_properties_095.phpt index 321b07e34c73f..4d8e5168e15ea 100644 --- a/Zend/tests/type_declarations/typed_properties_095.phpt +++ b/Zend/tests/type_declarations/typed_properties_095.phpt @@ -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)) }