in src/Parser.php [821:863]
private function parseParameterFn() {
return function ($parentNode) {
$parameter = new Parameter();
$parameter->parent = $parentNode;
if ($this->token->kind === TokenKind::AttributeToken) {
$parameter->attributes = $this->parseAttributeGroups($parameter);
}
// Note that parameter modifiers are allowed to be repeated by the parser in php 8.1 (it is a compiler error)
//
// TODO: Remove the visibilityToken in a future backwards incompatible release
$parameter->visibilityToken = $this->eatOptional([TokenKind::PublicKeyword, TokenKind::ProtectedKeyword, TokenKind::PrivateKeyword]);
$parameter->modifiers = $this->parseParameterModifiers() ?: null;
$parameter->questionToken = $this->eatOptional1(TokenKind::QuestionToken);
$parameter->typeDeclarationList = $this->tryParseParameterTypeDeclarationList($parameter);
if ($parameter->typeDeclarationList) {
$children = $parameter->typeDeclarationList->children;
if (end($children) instanceof MissingToken && ($children[\count($children) - 2]->kind ?? null) === TokenKind::AmpersandToken) {
array_pop($parameter->typeDeclarationList->children);
$parameter->byRefToken = array_pop($parameter->typeDeclarationList->children);
if (!$parameter->typeDeclarationList->children) {
$parameter->typeDeclarationList = null;
}
}
} elseif ($parameter->questionToken) {
// TODO ParameterType?
$parameter->typeDeclarationList = new MissingToken(TokenKind::PropertyType, $this->token->fullStart);
}
if (!$parameter->byRefToken) {
$parameter->byRefToken = $this->eatOptional1(TokenKind::AmpersandToken);
}
// TODO add post-parse rule that prevents assignment
// TODO add post-parse rule that requires only last parameter be variadic
$parameter->dotDotDotToken = $this->eatOptional1(TokenKind::DotDotDotToken);
$parameter->variableName = $this->eat1(TokenKind::VariableName);
$parameter->equalsToken = $this->eatOptional1(TokenKind::EqualsToken);
if ($parameter->equalsToken !== null) {
// TODO add post-parse rule that checks for invalid assignments
$parameter->default = $this->parseExpression($parameter);
}
return $parameter;
};
}