Basic Types
Edit pageLast modified: 02 February 2025The parser does not impose restrictions on type naming. The type name must begin with the characters [a-zA-Z\x80-\xff]
(any letter) and _
(underscore) and can contain any characters within the limit [a-zA-Z0-9\x80-\xff]
(any letter), as well as the characters _
(underscore) and -
(dash).
tip
For our purposes here, a letter is
a-z
,A-Z
, and the bytes from 128 through 255 (0x80-0xff
).
In this case, the only difference from the PHP grammar is that a dash (-
) symbol is allowed in the middle of the name.
In addition, it is worth noting that the case-insensitive names true
, false
and null
are registered PHP literals, so their use as a custom type name is unacceptable.
tip
Example of a simple Identifier.
ExampleTypeName
tip
Dashes (
-
) in Identifier are also acceptable.example-type
tip
The reserved keyword (
true
) is allowed as part of the Identifier.true-type
warning
The standalone keywords (
true
) is NOT available as an Identifier regardless of case and is parsed as a literal value rather than an Identifier.TrUe
warning
Identifiers cannot begin with digits (
0-9
) or a dash (-
) symbol.42type
An error similar to the one below should occur
ParseException: Syntax error, unexpected "type"
Namespace
Each name can contain a namespace symbol (\
— backslash), which is similar to that in PHP. The separator can be located either in the middle or at the beginning of any Identifier. End position is not allowed.
The namespace delimiter can be used in conjunction with keywords such as true
, false
, or null
to explicitly indicate a type reference.
tip
Relative class FQN reference.
Example\Name
tip
Absolute class FQN reference.
\Absolute\Type\Name
warning
Identifiers cannot contain keywords reserved for literal values.
true\null
An error similar to the one below should occur
ParseException: Syntax error, unexpected "\"
warning
FQN type names cannot end in
\
delimiter.example\name\
An error similar to the one below should occur
ParseException: Syntax error, unexpected end of input