Skip to content

Commit edecc8a

Browse files
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 f668a5b commit edecc8a

File tree

3 files changed

+236
-1
lines changed

3 files changed

+236
-1
lines changed

src/Files/File.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,7 @@ public function getMethodProperties($stackPtr)
18451845
* 'scope_specified' => boolean, // TRUE if the scope was explicitly specified.
18461846
* 'is_static' => boolean, // TRUE if the static keyword was found.
18471847
* 'is_readonly' => boolean, // TRUE if the readonly keyword was found.
1848+
* 'is_final' => boolean, // TRUE if the final keyword was found.
18481849
* 'type' => string, // The type of the var (empty if no type specified).
18491850
* 'type_token' => integer|false, // The stack pointer to the start of the type
18501851
* // or FALSE if there is no type.
@@ -1917,6 +1918,7 @@ public function getMemberProperties($stackPtr)
19171918
T_STATIC => T_STATIC,
19181919
T_VAR => T_VAR,
19191920
T_READONLY => T_READONLY,
1921+
T_FINAL => T_FINAL,
19201922
];
19211923

19221924
$valid += Tokens::$emptyTokens;
@@ -1925,6 +1927,7 @@ public function getMemberProperties($stackPtr)
19251927
$scopeSpecified = false;
19261928
$isStatic = false;
19271929
$isReadonly = false;
1930+
$isFinal = false;
19281931

19291932
$startOfStatement = $this->findPrevious(
19301933
[
@@ -1960,7 +1963,10 @@ public function getMemberProperties($stackPtr)
19601963
case T_READONLY:
19611964
$isReadonly = true;
19621965
break;
1963-
}
1966+
case T_FINAL:
1967+
$isFinal = true;
1968+
break;
1969+
}//end switch
19641970
}//end for
19651971

19661972
$type = '';
@@ -2016,6 +2022,7 @@ public function getMemberProperties($stackPtr)
20162022
'scope_specified' => $scopeSpecified,
20172023
'is_static' => $isStatic,
20182024
'is_readonly' => $isReadonly,
2025+
'is_final' => $isFinal,
20192026
'type' => $type,
20202027
'type_token' => $typeToken,
20212028
'type_end_token' => $typeEndToken,

tests/Core/File/GetMemberPropertiesTest.inc

Lines changed: 21 additions & 0 deletions
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)