Skip to content

Commit c0ae7cc

Browse files
DanielEScherzerjrfnl
authored andcommitted
PHP 8.4 | File::getMemberProperties(): allow for final properties (#834)
Update File::getMemberProperties() to report when a property is marked as final. Update existing tests (which are all for non-final properties) to expect that the property not be marked as final, and add a new test case for a final that should be, and is, marked as final. Part of #734
1 parent bbed906 commit c0ae7cc

File tree

3 files changed

+236
-1
lines changed

3 files changed

+236
-1
lines changed

src/Files/File.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,7 @@ public function getMethodProperties($stackPtr)
17851785
* 'scope_specified' => boolean, // TRUE if the scope was explicitly specified.
17861786
* 'is_static' => boolean, // TRUE if the static keyword was found.
17871787
* 'is_readonly' => boolean, // TRUE if the readonly keyword was found.
1788+
* 'is_final' => boolean, // TRUE if the final keyword was found.
17881789
* 'type' => string, // The type of the var (empty if no type specified).
17891790
* 'type_token' => integer|false, // The stack pointer to the start of the type
17901791
* // or FALSE if there is no type.
@@ -1854,6 +1855,7 @@ public function getMemberProperties($stackPtr)
18541855
T_STATIC => T_STATIC,
18551856
T_VAR => T_VAR,
18561857
T_READONLY => T_READONLY,
1858+
T_FINAL => T_FINAL,
18571859
];
18581860

18591861
$valid += Tokens::$emptyTokens;
@@ -1862,6 +1864,7 @@ public function getMemberProperties($stackPtr)
18621864
$scopeSpecified = false;
18631865
$isStatic = false;
18641866
$isReadonly = false;
1867+
$isFinal = false;
18651868

18661869
$startOfStatement = $this->findPrevious(
18671870
[
@@ -1897,7 +1900,10 @@ public function getMemberProperties($stackPtr)
18971900
case T_READONLY:
18981901
$isReadonly = true;
18991902
break;
1900-
}
1903+
case T_FINAL:
1904+
$isFinal = true;
1905+
break;
1906+
}//end switch
19011907
}//end for
19021908

19031909
$type = '';
@@ -1954,6 +1960,7 @@ public function getMemberProperties($stackPtr)
19541960
'scope_specified' => $scopeSpecified,
19551961
'is_static' => $isStatic,
19561962
'is_readonly' => $isReadonly,
1963+
'is_final' => $isFinal,
19571964
'type' => $type,
19581965
'type_token' => $typeToken,
19591966
'type_end_token' => $typeEndToken,

tests/Core/File/GetMemberPropertiesTest.inc

+21
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,24 @@ trait DNFTypes {
354354
// Intentional fatal error - nullable operator cannot be combined with DNF.
355355
var ?(A&\Pck\B)|bool $propD;
356356
}
357+
358+
class WithFinalProperties {
359+
/* testPHP84FinalPublicTypedProp */
360+
final public string $val1;
361+
/* testPHP84FinalProtectedTypedProp */
362+
final protected string $val2;
363+
/* testPHP84FinalMiddleTypedProp */
364+
public final string $val3;
365+
/* testPHP84FinalMiddleStaticTypedProp */
366+
public final static string $val4;
367+
/* testPHP84FinalLastTypedProp */
368+
public readonly final string $val5;
369+
/* testPHP84FinalImplicitVisibilityTypedProp */
370+
final string $val6;
371+
/* testPHP84FinalImplicitVisibilityProp */
372+
final $val7;
373+
/* testPHP84FinalNullableTypedProp */
374+
final public ?string $val8;
375+
/* testPHP84FinalComplexTypedProp */
376+
final public (Foo&\Bar)|bool $val9;
377+
}

0 commit comments

Comments
 (0)