Skip to content

Commit

Permalink
Add support for using final properties in stubs (php#17306)
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate authored Jan 6, 2025
1 parent e4ad271 commit 684ef01
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Zend/tests/type_declarations/typed_properties_095.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ object(_ZendTestClass)#1 (3) {
uninitialized(Traversable&Countable)
["readonlyProp"]=>
uninitialized(int)
["finalProp"]=>
uninitialized(int)
["dnfProperty"]=>
uninitialized(Iterator|(Traversable&Countable))
}
Expand All @@ -93,6 +95,8 @@ object(Test)#4 (3) {
uninitialized(Traversable&Countable)
["readonlyProp"]=>
uninitialized(int)
["finalProp"]=>
uninitialized(int)
["dnfProperty"]=>
uninitialized(Iterator|(Traversable&Countable))
}
Expand Down
9 changes: 9 additions & 0 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"));
Expand Down
1 change: 1 addition & 0 deletions ext/zend_test/test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
12 changes: 11 additions & 1 deletion ext/zend_test/test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 684ef01

Please sign in to comment.