Literal Types
Edit pageLast modified: 02 February 2025As a type description, specific values corresponding to a specific type are allowed:
bool
string
int
float
null
.
Boolean And Null
The literals true
and false
are used as the value of the PHP bool
type.
tip
Note:
true
andfalse
values are not case sensitive.TruE
For PHP null
types, the null
literal is used.
tip
Note:
null
value is not case sensitive.NulL
For other types the logic is more complicated.
Strings
The syntax of string types is similar to that in PHP: The string allows single ('
) and double ("
) quotes, which can be escaped using a backslash (\
).
tip
Single-quoted string wrapped by
'
symbol.'I am single-quoted string wrapped by \' symbol'
tip
Double-quoted string wrapped by
"
symbol."I am double-quoted string wrapped by \" symbol"'
Strings in single quotes are processed "as is", strings in double quotes allow insertion of special sequences.
Escape Sequences
All control sequences are similar to the PHP language: https://www.php.net/manual/en/language.types.string.php
\n
— Line break (0x0A
code)\r
— Carriage return (0x0D
code)\t
— Tab (0x09
code)\v
— Vertical Tab (0x0B
code)\e
— Escape (0x1B
code)\f
— Form Feed (0x0C
code)\$
— Dollar Sign (0x24
code)
tip
Double-quoted string with new line (
0x0A
) escape sequence."String with\nNew Line"
String with New Line
tip
Single-quoted string with ignored escape sequence.
'String without\nNew Line'
String without\nNew Line
Hexadecimal Sequences
The sequence of characters matching the regular expression [0-9A-Fa-f]{1,2}
is a character in hexadecimal notation (e.g. "\x41" === "A"
).
tip
"Hello World"
string equivalent in hexadecimal sequences format."\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64"
Hello World
tip
Single-quoted string does not process such sequences.
'\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64'
\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64
Unicode Sequences
the sequence of characters matching the regular expression [0-9A-Fa-f]+
is a Unicode codepoint, which will be output to the string as that codepoint's UTF-8 representation. The braces are required in the sequence. E.g. "\u{41}" === "A"
tip
tip
Single-quoted string does not process such sequences.
'\u{1F60A}'
\u{1F60A}
Integer
The syntax of integer numbers is similar to the PHP language. Binary, octal, decimal and hexadecimal number systems are supported.
note
Please note that in addition to numbers, underscores (
_
) are allowed.
Decimal numbers can contain any digits from 0
to 9
(leading 0
not allowed) and must match the regular expression [1-9][0-9]*
. For any other numbers, a special prefixed format is used, described below. Negative values are prefixed with a minus (-
).
Binary
Every binary number is prefixed with 0b
or 0B
and can only contain the numbers 1
and 0
and must match the regular expression 0b[0-1]+
.
tip
Number
173
in binary format.0b10101101
tip
Also number
173
in binary format with_
delimiters.0b10_10_11_01
tip
Number
10
in binary format:
The
0b
or0B
prefix can be in any case.0B1010
tip
Negative number
10
in binary format.-0b1010
warning
Binary numbers can only contain
1
and0
digits.0b101042
An error similar to the one below should occur
ParseException: Syntax error, unexpected "42"
Octal
Every octal number is prefixed with 0o
or 0O
and can only contain the numbers between 0
and 7
and must match the regular expression 0o[0-7]+
or [0-7]+
.
note
For compatibility with older versions of PHP, the prefix
0
is also allowed.
tip
Number
34
in octal format.0o42
tip
Also number
34
in octal format:
The
0o
or0O
prefix can be in any case.0O42
tip
Also number
34
in "legacy" octal format.042
tip
Number
2195
in octal format with_
delimiters.0o42_23
warning
Octal numbers can only contain digits between
0
and7
.0o4281
An error similar to the one below should occur
ParseException: Syntax error, unexpected "81"
Hexadecimal
Every hexadecimal number is prefixed with 0x
or 0X
and can only contain the numbers between 0
and F
and must match the regular expression 0x[0-9a-fA-F]+
.
tip
Number
57005
in hexadecimal format.0xDEAD
tip
Also number
57005
in hexadecimal format:
The
0x
or0X
prefix can be in any case.The
A-F
letters can also be in any case.0XDeaD
tip
Number
3735928559
in hexadecimal format with_
delimiters.0xDEAD_BEEF
warning
Hexadecimal numbers can only contain digits between
0
andF
.0xHELL
Float
The syntax of float numbers is similar to the PHP language. Basic floating point syntax and scientific notation are supported.
Every floating point number accepts the format [0-9]+\.[0-9]+
. The leading or trailing number may be omitted. Negative values are prefixed with a minus (-
.
tip
Simple floating point literal value.
0.9
tip
Non-prefixed floating point literal value (equivalent of
0.9
)..9
tip
Non-suffixed floating point literal value (equivalent of
1.0
).1.
tip
Negative floating point literal value.
-0.9
warning
Only leading or trailing number may be omitted (not both).
.
An error similar to the one below should occur
ParseException: Syntax error, unexpected "."
warning
Only number between
0
and9
are allowed.0.0A
An error similar to the one below should occur
ParseException: Syntax error, unexpected "A"
Scientific Notation
Scientific notation is a way of expressing numbers that are too large or too small to be conveniently written in decimal form, since to do so would require writing out an inconveniently long string of digits.
tip
Number
1000.0
in scientific notation.10e2
tip
Also number
1000.0
in scientific notation:
The
e
orE
suffix can be in any case.10E2
tip
Number
0.1
in scientific notation (negative exponent).10e-2
warning
The exponent value must be in decimal (digits between
0
and9
) form only.10e-F
An error similar to the one below should occur
ParseException: Syntax error, unexpected "e-F"