The grammar notation is described in §§.
input-file:: input-element input-file input-element input-element:: comment white-space token
comment:: single-line-comment delimited-comment single-line-comment:: // input-charactersopt # input-charactersopt input-characters:: input-character input-characters input-character input-character:: Any source character except new-line new-line:: Carriage-return character (U+000D) Line-feed character (U+000A) Carriage-return character (U+000D) followed by line-feed character (U+000A) delimited-comment:: /* No characters or any source character sequence except /* */
white-space:: white-space-character white-space white-space-character white-space-character:: new-line Space character (U+0020) Horizontal-tab character (U+0009)
token:: variable-name name keyword literal operator-or-punctuator
variable-name:: $ name name:: name-nondigit name name-nondigit name digit name-nondigit:: nondigit one of the characters U+007f–U+00ff nondigit:: one of _ a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
keyword:: one of abstract arraykey as async break case catch class classname clone const continue default do echo else elseif enum extends final finally for foreach function if implements instanceof insteadof interface mixed namespace new newtype noreturn num parent private protected public require require_once return self shape static switch throw trait try tuple type use while yield
literal:: boolean-literal integer-literal floating-literal string-literal null-literal
boolean-literal:: true false
integer-literal:: decimal-literal octal-literal hexadecimal-literal binary-literal decimal-literal:: nonzero-digit decimal-literal digit octal-literal:: 0 octal-literal octal-digit hexadecimal-literal:: hexadecimal-prefix hexadecimal-digit hexadecimal-literal hexadecimal-digit hexadecimal-prefix:: one of 0x 0X binary-literal:: binary-prefix binary-digit binary-literal binary-digit binary-prefix:: one of 0b 0B digit:: one of 0 1 2 3 4 5 6 7 8 9 nonzero-digit:: one of 1 2 3 4 5 6 7 8 9 octal-digit:: one of 0 1 2 3 4 5 6 7 hexadecimal-digit:: one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F binary-digit:: one of 0 1
floating-literal:: fractional-literal exponent-partopt digit-sequence exponent-part fractional-literal:: digit-sequenceopt . digit-sequence digit-sequence . exponent-part:: e signopt digit-sequence E signopt digit-sequence sign:: one of + - digit-sequence:: digit digit-sequence digit
string-literal:: single-quoted-string-literal double-quoted-string-literal heredoc-string-literal nowdoc-string-literal single-quoted-string-literal:: bopt ' sq-char-sequenceopt ' sq-char-sequence:: sq-char sq-char-sequence sq-char sq-char:: sq-escape-sequence \opt any member of the source character set except single-quote (') or backslash (\) sq-escape-sequence:: one of \' \\ double-quoted-string-literal:: bopt " dq-char-sequenceopt " dq-char-sequence:: dq-char dq-char-sequence dq-char dq-char:: dq-escape-sequence any member of the source character set except double-quote (") or backslash (\) \ any member of the source character set except "\$efnrtvxX or octal-digit dq-escape-sequence:: dq-simple-escape-sequence dq-octal-escape-sequence dq-hexadecimal-escape-sequence dq-simple-escape-sequence:: one of \" \\ \$ \e \f \n \r \t \v dq-octal-escape-sequence:: \ octal-digit \ octal-digit octal-digit \ octal-digit octal-digit octal-digit dq-hexadecimal-escape-sequence:: \x hexadecimal-digit hexadecimal-digitopt \X hexadecimal-digit hexadecimal-digitopt heredoc-string-literal:: <<< hd-start-identifier new-line hd-char-sequenceopt new-line hd-end-identifier ;opt new-line hd-start-identifier:: name hd-end-identifier:: name hd-char-sequence:: hd-char hd-char-sequence hd-char hd-char:: hd-escape-sequence any member of the source character set except backslash (\) \ any member of the source character set except \$efnrtvxX or octal-digit hd-escape-sequence:: hd-simple-escape-sequence dq-octal-escape-sequence dq-hexadecimal-escape-sequence hd-simple-escape-sequence:: one of \\ \$ \e \f \n \r \t \v nowdoc-string-literal:: <<< ' hd-start-identifier ' new-line hd-char-sequenceopt new-line hd-end-identifier ;opt new-line
null-literal:: null
operator-or-punctuator:: one of [ ] ( ) { } . -> ++ -- ** * + - ~ ! $ / % << >> < > <= >= == === != !== ^ | & && || ? ?? : ; = **= *= /= %= += -= .= <<= >>= &= ^= |= , @ :: => ==> ?-> \ ... |> $$
script: <?hh // strict declaration-listopt declaration-list: declaration declaration-list declaration declaration: inclusion-directive enum-declaration function-definition class-declaration interface-declaration trait-declaration namespace-definition namespace-use-declaration alias-declaration
type-specifier: bool int float num string arraykey void resource alias-type-specifier vector-like-array-type-specifier map-like-array-type-specifier enum-specifier class-interface-trait-specifier tuple-type-specifier shape-specifier closure-type-specifier nullable-type-specifier generic-type-parameter-name this classname-type-specifier type-constant-type-name alias-type-specifier: qualified-name enum-specifier: qualified-name class-interface-trait-specifier: qualified-name generic-type-argument-listopt type-specifier-list: type-specifiers ,opt type-specifiers: type-specifier type-specifiers , type-specifier type-constraint: as type-specifier type-constant-type-name: name :: name self :: name this :: name type-constant-type-name :: name
vector-like-array-type-specifier: array < array-value-type-specifier > map-like-array-type-specifier: array < array-value-type-specifier , array-value-type-specifier > array-value-type-specifier: type-specifier array-key-type-specifier: type-specifier
tuple-type-specifier: ( type-specifier , type-specifier-list )
shape-specifier: shape ( field-specifier-listopt ) field-specifier-list: field-specifier field-specifier-list , field-specifier field-specifier: single-quoted-string-literal => type-specifier qualified-name => type-specifier scope-resolution-expression => type-specifier
closure-type-specifier: ( function ( type-specifier-listopt ) : type-specifier )
nullable-type-specifier: ? type-specifier mixed
classname-type-specifier: classname < qualified-name generic-type-argument-listopt >
alias-declaration: attribute-specificationopt type name generic-type-parameter-listopt = type-specifier ; attribute-specificationopt newtype name generic-type-parameter-listopt type-constraintopt = type-specifier ;
function-static-declaration: static static-declarator-list ; static-declarator-list: static-declarator static-declarator-list , static-declarator static-declarator: variable-name function-static-initializeropt function-static-initializer: = const-expression
primary-expression: variable-name qualified-name literal const-expression intrinsic collection-literal tuple-literal shape-literal anonymous-function-creation-expression awaitable-creation-expression ( expression ) $this $$ intrinsic: array-intrinsic echo-intrinsic exit-intrinsic invariant-intrinsic list-intrinsic array-intrinsic: array ( array-initializeropt ) echo-intrinsic: echo expression echo ( expression ) echo expression-list-two-or-more expression-list-two-or-more: expression , expression expression-list-two-or-more , expression exit-intrinsic: exit expressionopt exit ( expressionopt ) invariant-intrinsic: invariant ( condition , format ) invariant ( condition , format , values ) list-intrinsic: list ( list-expression-listopt ) list-expression-list: expression , list-expression-list , expressionopt collection-literal: non-key-collection-class-type { cl-initializer-list-without-keysopt } key-collection-class-type { cl-initializer-list-with-keysopt } pair-type { cl-element-value , cl-element-value } non-key-collection-class-type: qualified-name non-key-collection-class-type-hintopt key-collection-class-type: qualified-name key-collection-class-type-hintopt non-key-collection-class-type-hint: < type-specifier &rt; key-collection-class-type-hint: < type-specifier , type-specifier &rt; pair-type: qualified-name cl-initializer-list-without-keys: cl-element-value cl-initializer-list-without-keys , cl-element-value cl-initializer-list-with-keys: cl-element-key => cl-element-value cl-initializer-list-with-keys , cl-element-key => cl-element-value cl-element-key: expression cl-element-value: expression tuple-literal: tuple ( expression-list-one-or-more ) expression-list-one-or-more: expression expression-list-one-or-more , expression shape-literal: shape ( field-initializer-listopt ) field-initializer-list: field-initializers ,opt field-initializers: field-initializer field-initializers , field-initializer field-initializer: single-quoted-string-literal => expression integer-literal => expression qualified-name => expression scope-resolution-expression => expression anonymous-function-creation-expression: asyncopt function ( anonymous-function-parameter-listopt ) anonymous-function-returnopt anonymous-function-use-clauseopt compound-statement anonymous-function-parameter-list: ... anonymous-function-parameter-declaration-list anonymous-function-parameter-declaration-list , anonymous-function-parameter-declaration-list , ... anonymous-function-parameter-declaration-list: anonymous-function-parameter-declaration anonymous-function-parameter-declaration-list , anonymous-function-parameter-declaration anonymous-function-parameter-declaration: attribute-specificationopt type-specifieropt variable-name default-argument-specifieropt anonymous-function-return: : return-type anonymous-function-use-clause: use ( use-variable-name-list ,opt ) use-variable-name-list: variable-name use-variable-name-list , variable-name awaitable-creation-expression: async { async-statement-listopt } async-statement-list: statement async-statement-list statement
postfix-expression: -expression clone-expression object-creation-expression array-creation-expression subscript-expression function-call-expression member-selection-expression null-safe-member-selection-expression postfix-increment-expression postfix-decrement-expression scope-resolution-expression exponentiation-expression clone-expression: clone expression object-creation-expression: new class-type-designator ( argument-expression-listopt ) class-type-designator: parent self static member-selection-expression null-safe-member-selection-expression qualified-name scope-resolution-expression subscript-expression variable-name array-creation-expression: array ( array-initializeropt ) [ array-initializeropt ] array-initializer: array-initializer-list ,opt array-initializer-list: array-element-initializer array-element-initializer , array-initializer-list array-element-initializer: element-value element-key => element-value element-key: expression element-value expression subscript-expression: postfix-expression [ expressionopt ] postfix-expression { expressionopt } [Deprecated form] function-call-expression: postfix-expression ( argument-expression-listopt ) argument-expression-list: argument-expressions ,opt argument-expressions: expression argument-expressions , expression member-selection-expression: postfix-expression -> name postfix-expression -> variable-name null-safe-member-selection-expression: postfix-expression ?-> name postfix-expression ?-> variable-name postfix-increment-expression: unary-expression ++ postfix-decrement-expression: unary-expression -- scope-resolution-expression: scope-resolution-qualifier :: name scope-resolution-qualifier :: variable-name scope-resolution-qualifier :: class scope-resolution-qualifier: qualified-name variable-name self parent static exponentiation-expression: expression ** expression
unary-expression: postfix-expression prefix-increment-expression prefix-decrement-expression unary-op-expression error-control-expression cast-expression await-expression prefix-increment-expression: ++ unary-expression prefix-decrement-expression: -- unary-expression unary-op-expression: unary-operator cast-expression unary-operator: one of + - ! ~ error-control-expression: @ expression cast-expression: ( cast-type ) unary-expression cast-type: one of bool int float string await-expression: await expression
instanceof-expression: unary-expression instanceof-subject instanceof instanceof-type-designator instanceof-subject: expression instanceof-type-designator: qualified-name variable-name
multiplicative-expression: instanceof-expression multiplicative-expression * instanceof-expression multiplicative-expression / instanceof-expression multiplicative-expression % instanceof-expression
additive-expression: multiplicative-expression additive-expression + multiplicative-expression additive-expression - multiplicative-expression additive-expression . multiplicative-expression
shift-expression: additive-expression shift-expression << additive-expression shift-expression >> additive-expression
relational-expression: shift-expression relational-expression < shift-expression relational-expression > shift-expression relational-expression <= shift-expression relational-expression >= shift-expression
equality-expression: relational-expression equality-expression == relational-expression equality-expression != relational-expression equality-expression === relational-expression equality-expression !== relational-expression
bitwise-AND-expression: equality-expression bit-wise-AND-expression & equality-expression bitwise-exc-OR-expression: bitwise-AND-expression bitwise-exc-OR-expression ^ bitwise-AND-expression bitwise-inc-OR-expression: bitwise-exc-OR-expression bitwise-inc-OR-expression | bitwise-exc-OR-expression
logical-AND-expression: bitwise-inc-OR-expression logical-AND-expression && bitwise-inc-OR-expression logical-inc-OR-expression: logical-AND-expression logical-inc-OR-expression || logical-AND-expression
conditional-expression: logical-inc-OR-expression logical-inc-OR-expression ? expressionopt : conditional-expression
piped-expression: coalesce-expression piped-expression |> coalesce-expression
lambda-expression: piped-expression asyncopt lambda-function-signature ==> lambda-body lambda-function-signature: variable-name ( anonymous-function-parameter-declaration-listopt ) anonymous-function-returnopt lambda-body: expression compound-statement
assignment-expression: lambda-expression simple-assignment-expression compound-assignment-expression simple-assignment-expression: unary-expression = assignment-expression byref-assignment-expression: unary-expression = & assignment-expression compound-assignment-expression: unary-expression compound-assignment-operator assignment-expression compound-assignment-operator: one of **= *= /= %= += -= .= <<= >>= &= ^= |=
expression: assignment-expression yield array-element-initializer
constant-expression: array-creation-expression collection-literal tuple-literal shape-literal const-expression const-expression: expression
statement: function-static-declaration compound-statement labeled-statement expression-statement selection-statement iteration-statement jump-statement try-statement
compound-statement: { statement-listopt } statement-list: statement statement-list statement
labeled-statement: case-label default-label case-label: case expression : statement default-label: default : statement
expression-statement: expressionopt ; selection-statement: if-statement switch-statement if-statement: if ( expression ) statement elseif-clauses-opt else-clause-opt elseif-clauses: elseif-clause elseif-clauses elseif-clause elseif-clause: elseif ( expression ) statement else-clause: else statement switch-statement: switch ( expression ) compound-statement
iteration-statement: while-statement do-statement for-statement foreach-statement while-statement: while ( expression ) statement do-statement: do statement while ( expression ) ; for-statement: for ( for-initializeropt ; for-controlopt ; for-end-of-loopopt ) statement for-initializer: for-expression-group for-control: for-expression-group for-end-of-loop: for-expression-group for-expression-group: expression for-expression-group , expression foreach-statement: foreach ( foreach-collection-name as foreach-keyopt foreach-value ) statement foreach ( foreach-collection-name await as foreach-keyopt foreach-value ) statement foreach-collection-name: expression foreach-key: expression => foreach-value: expression list-intrinsic
jump-statement: continue-statement break-statement return-statement throw-statement continue-statement: continue ; break-statement: break ; return-statement: return expressionopt ; throw-statement: throw expression ;
try-statement: try compound-statement catch-clauses try compound-statement finally-clause try compound-statement catch-clauses finally-clause catch-clauses: catch-clause catch-clauses catch-clause catch-clause: catch ( type-specifier variable-name ) compound-statement finally-clause: finally compound-statement
inclusion-directive: require-multiple-directive require-once-directive require-multiple-directive: require include-filename ; include-filename: expression require-once-directive: require_once include-filename ;
enum-declaration: enum name enum-base type-constraintopt { enumerator-listopt } enum-base: : int : string enumerator-list: enumerator enumerator-list enumerator enumerator: enumerator-constant = constant-expression ; enumerator-constant: name
generic-type-parameter-list: < generic-type-parameters ,opt > generic-type-parameters: generic-type-parameter generic-type-parameters , generic-type-parameter generic-type-parameter: generic-type-parameter-varianceopt generic-type-parameter-name type-constraintopt generic-type-parameter-name: name generic-type-parameter-variance: + - generic-type-argument-list: < generic-type-arguments ,opt > generic-type-arguments: generic-type-argument generic-type-arguments , generic-type-argument generic-type-argument: type-specifier name
function-definition: attribute-specificationopt function-definition-no-attribute function-definition-no-attribute: function-definition-header compound-statement function-definition-header: asyncopt function name generic-type-parameter-listopt ( parameter-listopt ) : return-type parameter-list: ... parameter-declaration-list ,opt parameter-declaration-list , ... parameter-declaration-list: parameter-declaration parameter-declaration-list , parameter-declaration parameter-declaration: attribute-specificationopt type-specifier variable-name default-argument-specifieropt default-argument-specifier: = const-expression return-type: type-specifier noreturn
class-declaration: attribute-specificationopt class-modifieropt class name generic-type-parameter-listopt class-base-clauseopt class-interface-clauseopt { trait-use-clausesopt class-member-declarationsopt } class-modifier: abstract final abstract final class-base-clause: extends qualified-name generic-type-argument-listopt class-interface-clause: implements qualified-name generic-type-argument-listopt class-interface-clause , qualified-name generic-type-argument-listopt class-member-declarations: class-member-declaration class-member-declarations class-member-declaration class-member-declaration: const-declaration property-declaration method-declaration constructor-declaration destructor-declaration type-constant-declaration const-declaration: abstractopt const type-specifieropt constant-declarator-list ; constant-declarator-list: constant-declarator constant-declarator-list , constant-declarator constant-declarator: name constant-initializeropt constant-initializer: = const-expression property-declaration: property-modifier type-specifier property-declarator-list ; property-declarator-list: property-declarator property-declarator-list , property-declarator property-declarator: variable-name property-initializeropt property-modifier: visibility-modifier static-modifieropt static-modifier visibility-modifier visibility-modifier: public protected private static-modifier: static property-initializer: = expression method-declaration: attribute-specificationopt method-modifiers function-definition-no-attribute attribute-specificationopt method-modifiers function-definition-header ; method-modifiers: method-modifier method-modifiers method-modifier method-modifier: visibility-modifier static-modifier abstract final constructor-declaration: attribute-specificationopt constructor-modifiers function __construct ( constructor-parameter-declaration-listopt ) void-returnopt compound-statement constructor-parameter-declaration-list: constructor-parameter-declaration constructor-parameter-declaration-list , constructor-parameter-declaration constructor-parameter-declaration: visibility-modifieropt type-specifier variable-name default-argument-specifieropt constructor-modifiers: constructor-modifier constructor-modifiers constructor-modifier constructor-modifier: visibility-modifier abstract final destructor-declaration: attribute-specificationopt visibility-modifier function __destruct ( ) void-returnopt compound-statement void-return: : void type-constant-declaration: abstract-type-constant-declaration concrete-type-constant-declaration abstract-type-constant-declaration: abstract const type name type-constraintopt ; concrete-type-constant-declaration: const type name type-constraintopt = type-specifier ;
interface-declaration: attribute-specificationopt interface name generic-type-parameter-listopt interface-base-clauseopt { interface-member-declarationsopt } interface-base-clause: extends qualified-name generic-type-argument-listopt interface-base-clause , qualified-name generic-type-argument-listopt interface-member-declarations: interface-member-declaration interface-member-declarations interface-member-declaration interface-member-declaration: require-extends-clause const-declaration method-declaration type-constant-declaration
trait-declaration: attribute-specificationopt trait name generic-type-parameter-listopt class-interface-clauseopt { trait-use-clausesopt trait-member-declarationsopt } trait-use-clauses: trait-use-clause trait-use-clauses trait-use-clause trait-use-clause: use trait-name-list ; trait-name-list: qualified-name generic-type-argument-listopt trait-name-list , qualified-name generic-type-argument-listopt trait-member-declarations: trait-member-declaration trait-member-declarations trait-member-declaration trait-member-declaration: require-extends-clause require-implements-clause property-declaration method-declaration constructor-declaration destructor-declaration require-extends-clause: require extends qualified-name ; require-implements-clause: require implements qualified-name ;
namespace-definition: namespace namespace-name ; namespace namespace-nameopt { declaration-listopt } namespace-use-declaration: use namespace-use-kindopt namespace-use-clauses ; use namespace-use-kind namespace-name-as-a-prefix { namespace-use-clauses } ; use namespace-name-as-a-prefix { namespace-use-kind-clauses } ; namespace-use-clauses: namespace-use-clause namespace-use-clauses , namespace-use-clause namespace-use-clause: qualified-name namespace-aliasing-clauseopt namespace-use-kind-clauses: namespace-use-kind-clause namespace-use-kind-clauses , namespace-use-kind-clause namespace-use-kind-clause: namespace-use-kindopt qualified-name namespace-aliasing-clauseopt namespace-aliasing-clause: as name namespace-use-kind: function const namespace-name: name namespace-name \ name namespace-name-as-a-prefix: \ \opt namespace-name \ namespace \ namespace \ namespace-name \ qualified-name: namespace-name-as-a-prefixopt name
attribute-specification: << attribute-list >> attribute-list: attribute attribute-list , attribute attribute: attribute-name attribute-value-listopt attribute-name: name attribute-value-list: ( attribute-valuesopt ) attribute-values attribute-value attribute-values , attribute-value attribute-value: expression