Closed nsfisis closed 2 years ago
empty
match
readonly
unset
empty and unset are function-like keywords. Previously they are parsed as built-in functions like this:
cf. https://www.php.net/manual/en/reserved.keywords.php
They should be parsed as keywords as isset() and die().
isset()
die()
Also, match expression is introduced since PHP 8.0.
cf. https://www.php.net/manual/en/control-structures.match.php
Previously, static property declaration with type hint like public static int $x; was parsed as the following:
public static int $x;
public
static
int
$x
int should be parsed as a type.
The previous parser state :in_visibility defines these rules:
:in_visibility
state :in_visibility do rule %r/(?=(abstract|const|function|static)\b)/i, Keyword, :pop! rule %r/\??#{id}/, Keyword::Type, :pop! # ... end
Because a parser pops the current state once it find static, it cannot recognize a type hint following the static keyword.
I split the rule into two, static and other. If a parser encounters static, it stays in the current state and then parses a type hints.
readonly is a new property modifier, available in PHP 8.1 or later.
cf. https://www.php.net/manual/en/language.oop5.properties.php#language.oop5.properties.readonly-properties
Since PHP 8.0, you can prepend visibility modifiers to parameters of constructors. These parameters are "promoted" to class properties. Since 8.1, you can specify readonly modifier as class properties.
cf. https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor.promotion
Thank you for your contribution @nsfisis ππΌ Looks great to me π
Summary
empty
match
readonly
unset
readonly
modifiersDetails
Add missing keywords
empty
andunset
are function-like keywords. Previously they are parsed as built-in functions like this:cf. https://www.php.net/manual/en/reserved.keywords.php
They should be parsed as keywords as
isset()
anddie()
.Also,
match
expression is introduced since PHP 8.0.cf. https://www.php.net/manual/en/control-structures.match.php
Fix parsing of static properties
Previously, static property declaration with type hint like
public static int $x;
was parsed as the following:public
)static
)int
)$x
)int
should be parsed as a type.The previous parser state
:in_visibility
defines these rules:Because a parser pops the current state once it find
static
, it cannot recognize a type hint following thestatic
keyword.I split the rule into two,
static
and other. If a parser encountersstatic
, it stays in the current state and then parses a type hints.Support
readonly
modifiersreadonly
is a new property modifier, available in PHP 8.1 or later.cf. https://www.php.net/manual/en/language.oop5.properties.php#language.oop5.properties.readonly-properties
Support constructor property promotion
Since PHP 8.0, you can prepend visibility modifiers to parameters of constructors. These parameters are "promoted" to class properties. Since 8.1, you can specify
readonly
modifier as class properties.cf. https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor.promotion