Repository: nikic/PHP-Parser Branch: master Commit: 50f0d9c9d0e3 Files: 664 Total size: 2.1 MB Directory structure: gitextract_zfx_1jy8/ ├── .editorconfig ├── .gitattributes ├── .github/ │ └── workflows/ │ └── main.yml ├── .gitignore ├── .php-cs-fixer.dist.php ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── UPGRADE-1.0.md ├── UPGRADE-2.0.md ├── UPGRADE-3.0.md ├── UPGRADE-4.0.md ├── UPGRADE-5.0.md ├── bin/ │ └── php-parse ├── composer.json ├── doc/ │ ├── 0_Introduction.markdown │ ├── 2_Usage_of_basic_components.markdown │ ├── README.md │ └── component/ │ ├── AST_builders.markdown │ ├── Constant_expression_evaluation.markdown │ ├── Error_handling.markdown │ ├── FAQ.markdown │ ├── JSON_representation.markdown │ ├── Lexer.markdown │ ├── Name_resolution.markdown │ ├── Performance.markdown │ ├── Pretty_printing.markdown │ └── Walking_the_AST.markdown ├── grammar/ │ ├── README.md │ ├── parser.template │ ├── php.y │ ├── phpyLang.php │ └── rebuildParsers.php ├── lib/ │ └── PhpParser/ │ ├── Builder/ │ │ ├── ClassConst.php │ │ ├── Class_.php │ │ ├── Declaration.php │ │ ├── EnumCase.php │ │ ├── Enum_.php │ │ ├── FunctionLike.php │ │ ├── Function_.php │ │ ├── Interface_.php │ │ ├── Method.php │ │ ├── Namespace_.php │ │ ├── Param.php │ │ ├── Property.php │ │ ├── TraitUse.php │ │ ├── TraitUseAdaptation.php │ │ ├── Trait_.php │ │ └── Use_.php │ ├── Builder.php │ ├── BuilderFactory.php │ ├── BuilderHelpers.php │ ├── Comment/ │ │ └── Doc.php │ ├── Comment.php │ ├── ConstExprEvaluationException.php │ ├── ConstExprEvaluator.php │ ├── Error.php │ ├── ErrorHandler/ │ │ ├── Collecting.php │ │ └── Throwing.php │ ├── ErrorHandler.php │ ├── Internal/ │ │ ├── DiffElem.php │ │ ├── Differ.php │ │ ├── PrintableNewAnonClassNode.php │ │ ├── TokenPolyfill.php │ │ └── TokenStream.php │ ├── JsonDecoder.php │ ├── Lexer/ │ │ ├── Emulative.php │ │ └── TokenEmulator/ │ │ ├── AsymmetricVisibilityTokenEmulator.php │ │ ├── AttributeEmulator.php │ │ ├── EnumTokenEmulator.php │ │ ├── ExplicitOctalEmulator.php │ │ ├── FnTokenEmulator.php │ │ ├── KeywordEmulator.php │ │ ├── MatchTokenEmulator.php │ │ ├── NullsafeTokenEmulator.php │ │ ├── PipeOperatorEmulator.php │ │ ├── PropertyTokenEmulator.php │ │ ├── ReadonlyFunctionTokenEmulator.php │ │ ├── ReadonlyTokenEmulator.php │ │ ├── ReverseEmulator.php │ │ ├── TokenEmulator.php │ │ └── VoidCastEmulator.php │ ├── Lexer.php │ ├── Modifiers.php │ ├── NameContext.php │ ├── Node/ │ │ ├── Arg.php │ │ ├── ArrayItem.php │ │ ├── Attribute.php │ │ ├── AttributeGroup.php │ │ ├── ClosureUse.php │ │ ├── ComplexType.php │ │ ├── Const_.php │ │ ├── DeclareItem.php │ │ ├── Expr/ │ │ │ ├── ArrayDimFetch.php │ │ │ ├── ArrayItem.php │ │ │ ├── Array_.php │ │ │ ├── ArrowFunction.php │ │ │ ├── Assign.php │ │ │ ├── AssignOp/ │ │ │ │ ├── BitwiseAnd.php │ │ │ │ ├── BitwiseOr.php │ │ │ │ ├── BitwiseXor.php │ │ │ │ ├── Coalesce.php │ │ │ │ ├── Concat.php │ │ │ │ ├── Div.php │ │ │ │ ├── Minus.php │ │ │ │ ├── Mod.php │ │ │ │ ├── Mul.php │ │ │ │ ├── Plus.php │ │ │ │ ├── Pow.php │ │ │ │ ├── ShiftLeft.php │ │ │ │ └── ShiftRight.php │ │ │ ├── AssignOp.php │ │ │ ├── AssignRef.php │ │ │ ├── BinaryOp/ │ │ │ │ ├── BitwiseAnd.php │ │ │ │ ├── BitwiseOr.php │ │ │ │ ├── BitwiseXor.php │ │ │ │ ├── BooleanAnd.php │ │ │ │ ├── BooleanOr.php │ │ │ │ ├── Coalesce.php │ │ │ │ ├── Concat.php │ │ │ │ ├── Div.php │ │ │ │ ├── Equal.php │ │ │ │ ├── Greater.php │ │ │ │ ├── GreaterOrEqual.php │ │ │ │ ├── Identical.php │ │ │ │ ├── LogicalAnd.php │ │ │ │ ├── LogicalOr.php │ │ │ │ ├── LogicalXor.php │ │ │ │ ├── Minus.php │ │ │ │ ├── Mod.php │ │ │ │ ├── Mul.php │ │ │ │ ├── NotEqual.php │ │ │ │ ├── NotIdentical.php │ │ │ │ ├── Pipe.php │ │ │ │ ├── Plus.php │ │ │ │ ├── Pow.php │ │ │ │ ├── ShiftLeft.php │ │ │ │ ├── ShiftRight.php │ │ │ │ ├── Smaller.php │ │ │ │ ├── SmallerOrEqual.php │ │ │ │ └── Spaceship.php │ │ │ ├── BinaryOp.php │ │ │ ├── BitwiseNot.php │ │ │ ├── BooleanNot.php │ │ │ ├── CallLike.php │ │ │ ├── Cast/ │ │ │ │ ├── Array_.php │ │ │ │ ├── Bool_.php │ │ │ │ ├── Double.php │ │ │ │ ├── Int_.php │ │ │ │ ├── Object_.php │ │ │ │ ├── String_.php │ │ │ │ ├── Unset_.php │ │ │ │ └── Void_.php │ │ │ ├── Cast.php │ │ │ ├── ClassConstFetch.php │ │ │ ├── Clone_.php │ │ │ ├── Closure.php │ │ │ ├── ClosureUse.php │ │ │ ├── ConstFetch.php │ │ │ ├── Empty_.php │ │ │ ├── Error.php │ │ │ ├── ErrorSuppress.php │ │ │ ├── Eval_.php │ │ │ ├── Exit_.php │ │ │ ├── FuncCall.php │ │ │ ├── Include_.php │ │ │ ├── Instanceof_.php │ │ │ ├── Isset_.php │ │ │ ├── List_.php │ │ │ ├── Match_.php │ │ │ ├── MethodCall.php │ │ │ ├── New_.php │ │ │ ├── NullsafeMethodCall.php │ │ │ ├── NullsafePropertyFetch.php │ │ │ ├── PostDec.php │ │ │ ├── PostInc.php │ │ │ ├── PreDec.php │ │ │ ├── PreInc.php │ │ │ ├── Print_.php │ │ │ ├── PropertyFetch.php │ │ │ ├── ShellExec.php │ │ │ ├── StaticCall.php │ │ │ ├── StaticPropertyFetch.php │ │ │ ├── Ternary.php │ │ │ ├── Throw_.php │ │ │ ├── UnaryMinus.php │ │ │ ├── UnaryPlus.php │ │ │ ├── Variable.php │ │ │ ├── YieldFrom.php │ │ │ └── Yield_.php │ │ ├── Expr.php │ │ ├── FunctionLike.php │ │ ├── Identifier.php │ │ ├── InterpolatedStringPart.php │ │ ├── IntersectionType.php │ │ ├── MatchArm.php │ │ ├── Name/ │ │ │ ├── FullyQualified.php │ │ │ └── Relative.php │ │ ├── Name.php │ │ ├── NullableType.php │ │ ├── Param.php │ │ ├── PropertyHook.php │ │ ├── PropertyItem.php │ │ ├── Scalar/ │ │ │ ├── DNumber.php │ │ │ ├── Encapsed.php │ │ │ ├── EncapsedStringPart.php │ │ │ ├── Float_.php │ │ │ ├── Int_.php │ │ │ ├── InterpolatedString.php │ │ │ ├── LNumber.php │ │ │ ├── MagicConst/ │ │ │ │ ├── Class_.php │ │ │ │ ├── Dir.php │ │ │ │ ├── File.php │ │ │ │ ├── Function_.php │ │ │ │ ├── Line.php │ │ │ │ ├── Method.php │ │ │ │ ├── Namespace_.php │ │ │ │ ├── Property.php │ │ │ │ └── Trait_.php │ │ │ ├── MagicConst.php │ │ │ └── String_.php │ │ ├── Scalar.php │ │ ├── StaticVar.php │ │ ├── Stmt/ │ │ │ ├── Block.php │ │ │ ├── Break_.php │ │ │ ├── Case_.php │ │ │ ├── Catch_.php │ │ │ ├── ClassConst.php │ │ │ ├── ClassLike.php │ │ │ ├── ClassMethod.php │ │ │ ├── Class_.php │ │ │ ├── Const_.php │ │ │ ├── Continue_.php │ │ │ ├── DeclareDeclare.php │ │ │ ├── Declare_.php │ │ │ ├── Do_.php │ │ │ ├── Echo_.php │ │ │ ├── ElseIf_.php │ │ │ ├── Else_.php │ │ │ ├── EnumCase.php │ │ │ ├── Enum_.php │ │ │ ├── Expression.php │ │ │ ├── Finally_.php │ │ │ ├── For_.php │ │ │ ├── Foreach_.php │ │ │ ├── Function_.php │ │ │ ├── Global_.php │ │ │ ├── Goto_.php │ │ │ ├── GroupUse.php │ │ │ ├── HaltCompiler.php │ │ │ ├── If_.php │ │ │ ├── InlineHTML.php │ │ │ ├── Interface_.php │ │ │ ├── Label.php │ │ │ ├── Namespace_.php │ │ │ ├── Nop.php │ │ │ ├── Property.php │ │ │ ├── PropertyProperty.php │ │ │ ├── Return_.php │ │ │ ├── StaticVar.php │ │ │ ├── Static_.php │ │ │ ├── Switch_.php │ │ │ ├── TraitUse.php │ │ │ ├── TraitUseAdaptation/ │ │ │ │ ├── Alias.php │ │ │ │ └── Precedence.php │ │ │ ├── TraitUseAdaptation.php │ │ │ ├── Trait_.php │ │ │ ├── TryCatch.php │ │ │ ├── Unset_.php │ │ │ ├── UseUse.php │ │ │ ├── Use_.php │ │ │ └── While_.php │ │ ├── Stmt.php │ │ ├── UnionType.php │ │ ├── UseItem.php │ │ ├── VarLikeIdentifier.php │ │ └── VariadicPlaceholder.php │ ├── Node.php │ ├── NodeAbstract.php │ ├── NodeDumper.php │ ├── NodeFinder.php │ ├── NodeTraverser.php │ ├── NodeTraverserInterface.php │ ├── NodeVisitor/ │ │ ├── CloningVisitor.php │ │ ├── CommentAnnotatingVisitor.php │ │ ├── FindingVisitor.php │ │ ├── FirstFindingVisitor.php │ │ ├── NameResolver.php │ │ ├── NodeConnectingVisitor.php │ │ └── ParentConnectingVisitor.php │ ├── NodeVisitor.php │ ├── NodeVisitorAbstract.php │ ├── Parser/ │ │ ├── Php7.php │ │ └── Php8.php │ ├── Parser.php │ ├── ParserAbstract.php │ ├── ParserFactory.php │ ├── PhpVersion.php │ ├── PrettyPrinter/ │ │ └── Standard.php │ ├── PrettyPrinter.php │ ├── PrettyPrinterAbstract.php │ ├── Token.php │ └── compatibility_tokens.php ├── phpstan-baseline.neon ├── phpstan.neon.dist ├── phpunit.xml.dist ├── test/ │ ├── PhpParser/ │ │ ├── Builder/ │ │ │ ├── ClassConstTest.php │ │ │ ├── ClassTest.php │ │ │ ├── EnumCaseTest.php │ │ │ ├── EnumTest.php │ │ │ ├── FunctionTest.php │ │ │ ├── InterfaceTest.php │ │ │ ├── MethodTest.php │ │ │ ├── NamespaceTest.php │ │ │ ├── ParamTest.php │ │ │ ├── PropertyTest.php │ │ │ ├── TraitTest.php │ │ │ ├── TraitUseAdaptationTest.php │ │ │ ├── TraitUseTest.php │ │ │ └── UseTest.php │ │ ├── BuilderFactoryTest.php │ │ ├── BuilderHelpersTest.php │ │ ├── CodeParsingTest.php │ │ ├── CodeTestAbstract.php │ │ ├── CodeTestParser.php │ │ ├── CommentTest.php │ │ ├── CompatibilityTest.php │ │ ├── ConstExprEvaluatorTest.php │ │ ├── ErrorHandler/ │ │ │ ├── CollectingTest.php │ │ │ └── ThrowingTest.php │ │ ├── ErrorTest.php │ │ ├── Internal/ │ │ │ └── DifferTest.php │ │ ├── JsonDecoderTest.php │ │ ├── Lexer/ │ │ │ └── EmulativeTest.php │ │ ├── LexerTest.php │ │ ├── ModifiersTest.php │ │ ├── NameContextTest.php │ │ ├── Node/ │ │ │ ├── Expr/ │ │ │ │ └── CallableLikeTest.php │ │ │ ├── IdentifierTest.php │ │ │ ├── NameTest.php │ │ │ ├── ParamTest.php │ │ │ ├── PropertyHookTest.php │ │ │ ├── Scalar/ │ │ │ │ ├── DNumberTest.php │ │ │ │ ├── MagicConstTest.php │ │ │ │ ├── NumberTest.php │ │ │ │ └── StringTest.php │ │ │ └── Stmt/ │ │ │ ├── ClassConstTest.php │ │ │ ├── ClassMethodTest.php │ │ │ ├── ClassTest.php │ │ │ ├── InterfaceTest.php │ │ │ └── PropertyTest.php │ │ ├── NodeAbstractTest.php │ │ ├── NodeDumperTest.php │ │ ├── NodeFinderTest.php │ │ ├── NodeTraverserTest.php │ │ ├── NodeVisitor/ │ │ │ ├── FindingVisitorTest.php │ │ │ ├── FirstFindingVisitorTest.php │ │ │ ├── NameResolverTest.php │ │ │ ├── NodeConnectingVisitorTest.php │ │ │ └── ParentConnectingVisitorTest.php │ │ ├── NodeVisitorForTesting.php │ │ ├── Parser/ │ │ │ ├── Php7Test.php │ │ │ └── Php8Test.php │ │ ├── ParserFactoryTest.php │ │ ├── ParserTestAbstract.php │ │ ├── PhpVersionTest.php │ │ ├── PrettyPrinterTest.php │ │ └── TokenTest.php │ ├── bootstrap.php │ ├── code/ │ │ ├── formatPreservation/ │ │ │ ├── addingPropertyType.test │ │ │ ├── anonClasses.test │ │ │ ├── arrayInsertionWithComments.test │ │ │ ├── array_spread.test │ │ │ ├── arrow_function.test │ │ │ ├── attributes.test │ │ │ ├── basic.test │ │ │ ├── blockConversion.test │ │ │ ├── classMethodNop.test │ │ │ ├── closure.test │ │ │ ├── comments.test │ │ │ ├── constants.test │ │ │ ├── delAfterIdentifier.test │ │ │ ├── emptyListInsertion.test │ │ │ ├── enum.test │ │ │ ├── fixup.test │ │ │ ├── group_use.test │ │ │ ├── indent.test │ │ │ ├── inlineHtml.test │ │ │ ├── insertionOfNullable.test │ │ │ ├── listInsertion.test │ │ │ ├── listInsertionIndentation.test │ │ │ ├── listRemoval.test │ │ │ ├── match.test │ │ │ ├── modifierChange.test │ │ │ ├── namedArgs.test │ │ │ ├── nopCommentAtEnd.test │ │ │ ├── property_hooks.test │ │ │ ├── removalViaNull.test │ │ │ ├── removingPropertyType.test │ │ │ ├── rewriteVariableInterpolationString.test │ │ │ └── traitAlias.test │ │ ├── parser/ │ │ │ ├── blockComments.test │ │ │ ├── commentAtEndOfClass.test │ │ │ ├── comments.test │ │ │ ├── emptyFile.test │ │ │ ├── errorHandling/ │ │ │ │ ├── eofError.test │ │ │ │ ├── lexerErrors.test │ │ │ │ └── recovery.test │ │ │ ├── expr/ │ │ │ │ ├── alternative_array_syntax.test │ │ │ │ ├── arrayDef.test │ │ │ │ ├── arrayDestructuring.test │ │ │ │ ├── arrayEmptyElemens.test │ │ │ │ ├── arraySpread.test │ │ │ │ ├── arrow_function.test │ │ │ │ ├── assign.test │ │ │ │ ├── assignNewByRef.test │ │ │ │ ├── cast.test │ │ │ │ ├── clone.test │ │ │ │ ├── closure.test │ │ │ │ ├── closure_use_trailing_comma.test │ │ │ │ ├── comparison.test │ │ │ │ ├── concatPrecedence.test │ │ │ │ ├── constant_expr.test │ │ │ │ ├── dynamicClassConst.test │ │ │ │ ├── errorSuppress.test │ │ │ │ ├── exit.test │ │ │ │ ├── exprInIsset.test │ │ │ │ ├── exprInList.test │ │ │ │ ├── fetchAndCall/ │ │ │ │ │ ├── args.test │ │ │ │ │ ├── constFetch.test │ │ │ │ │ ├── constantDeref.test │ │ │ │ │ ├── funcCall.test │ │ │ │ │ ├── namedArgs.test │ │ │ │ │ ├── newDeref.test │ │ │ │ │ ├── objectAccess.test │ │ │ │ │ ├── simpleArrayAccess.test │ │ │ │ │ ├── staticCall.test │ │ │ │ │ └── staticPropertyFetch.test │ │ │ │ ├── firstClassCallables.test │ │ │ │ ├── includeAndEval.test │ │ │ │ ├── issetAndEmpty.test │ │ │ │ ├── keywordsInNamespacedName.test │ │ │ │ ├── listReferences.test │ │ │ │ ├── listWithKeys.test │ │ │ │ ├── logic.test │ │ │ │ ├── match.test │ │ │ │ ├── math.test │ │ │ │ ├── new.test │ │ │ │ ├── newDeref.test │ │ │ │ ├── newWithoutClass.test │ │ │ │ ├── nullsafe.test │ │ │ │ ├── pipe.test │ │ │ │ ├── print.test │ │ │ │ ├── shellExec.test │ │ │ │ ├── ternaryAndCoalesce.test │ │ │ │ ├── throw.test │ │ │ │ ├── trailingCommas.test │ │ │ │ ├── uvs/ │ │ │ │ │ ├── constDeref.test │ │ │ │ │ ├── globalNonSimpleVarError.test │ │ │ │ │ ├── indirectCall.test │ │ │ │ │ ├── isset.test │ │ │ │ │ ├── misc.test │ │ │ │ │ ├── new.test │ │ │ │ │ ├── newInstanceofExpr.test │ │ │ │ │ └── staticProperty.test │ │ │ │ ├── varVarPos.test │ │ │ │ └── variable.test │ │ │ ├── formattingAttributes.test │ │ │ ├── nopPositions.test │ │ │ ├── scalar/ │ │ │ │ ├── constantString.test │ │ │ │ ├── docString.test │ │ │ │ ├── docStringNewlines.test │ │ │ │ ├── encapsedNegVarOffset.test │ │ │ │ ├── encapsedString.test │ │ │ │ ├── explicitOctal.test │ │ │ │ ├── flexibleDocString.test │ │ │ │ ├── flexibleDocStringErrors.test │ │ │ │ ├── float.test │ │ │ │ ├── int.test │ │ │ │ ├── invalidOctal.test │ │ │ │ ├── magicConst.test │ │ │ │ ├── numberSeparators.test │ │ │ │ └── unicodeEscape.test │ │ │ ├── semiReserved.test │ │ │ └── stmt/ │ │ │ ├── attributes.test │ │ │ ├── blocklessStatement.test │ │ │ ├── class/ │ │ │ │ ├── abstract.test │ │ │ │ ├── anonymous.test │ │ │ │ ├── asymmetric_visibility.test │ │ │ │ ├── class_position.test │ │ │ │ ├── conditional.test │ │ │ │ ├── constModifierErrors.test │ │ │ │ ├── constModifiers.test │ │ │ │ ├── enum.test │ │ │ │ ├── enum_with_string.test │ │ │ │ ├── final.test │ │ │ │ ├── implicitPublic.test │ │ │ │ ├── interface.test │ │ │ │ ├── modifier_error.test │ │ │ │ ├── name.test │ │ │ │ ├── php4Style.test │ │ │ │ ├── propertyTypes.test │ │ │ │ ├── property_hooks.test │ │ │ │ ├── property_modifiers.test │ │ │ │ ├── property_promotion.test │ │ │ │ ├── readonly.test │ │ │ │ ├── readonlyAnonyous.test │ │ │ │ ├── readonlyAsClassName.test │ │ │ │ ├── readonlyMethod.test │ │ │ │ ├── shortEchoAsIdentifier.test │ │ │ │ ├── simple.test │ │ │ │ ├── staticMethod.test │ │ │ │ ├── staticType.test │ │ │ │ ├── trait.test │ │ │ │ └── typedConstants.test │ │ │ ├── const.test │ │ │ ├── controlFlow.test │ │ │ ├── declare.test │ │ │ ├── echo.test │ │ │ ├── function/ │ │ │ │ ├── builtinTypeDeclarations.test │ │ │ │ ├── byRef.test │ │ │ │ ├── clone_function.test │ │ │ │ ├── conditional.test │ │ │ │ ├── defaultValues.test │ │ │ │ ├── disjointNormalFormTypes.test │ │ │ │ ├── exit_die_function.test │ │ │ │ ├── fn.test │ │ │ │ ├── intersectionTypes.test │ │ │ │ ├── invalidVoidParam.test │ │ │ │ ├── neverType.test │ │ │ │ ├── nullFalseTrueTypes.test │ │ │ │ ├── nullableTypes.test │ │ │ │ ├── parameters_trailing_comma.test │ │ │ │ ├── readonlyFunction.test │ │ │ │ ├── returnTypes.test │ │ │ │ ├── specialVars.test │ │ │ │ ├── typeDeclarations.test │ │ │ │ ├── typeVersions.test │ │ │ │ ├── unionTypes.test │ │ │ │ ├── validVoidParam.test │ │ │ │ ├── variadic.test │ │ │ │ └── variadicDefaultValue.test │ │ │ ├── generator/ │ │ │ │ ├── basic.test │ │ │ │ ├── yieldPrecedence.test │ │ │ │ └── yieldUnaryPrecedence.test │ │ │ ├── haltCompiler.test │ │ │ ├── haltCompilerInvalidSyntax.test │ │ │ ├── haltCompilerOffset.test │ │ │ ├── haltCompilerOutermostScope.test │ │ │ ├── hashbang.test │ │ │ ├── if.test │ │ │ ├── inlineHTML.test │ │ │ ├── loop/ │ │ │ │ ├── do.test │ │ │ │ ├── for.test │ │ │ │ ├── foreach.test │ │ │ │ └── while.test │ │ │ ├── multiCatch.test │ │ │ ├── namespace/ │ │ │ │ ├── alias.test │ │ │ │ ├── braced.test │ │ │ │ ├── commentAfterNamespace.test │ │ │ │ ├── groupUse.test │ │ │ │ ├── groupUseErrors.test │ │ │ │ ├── groupUsePositions.test │ │ │ │ ├── groupUseTrailingComma.test │ │ │ │ ├── invalidName.test │ │ │ │ ├── mix.test │ │ │ │ ├── name.test │ │ │ │ ├── nested.test │ │ │ │ ├── notBraced.test │ │ │ │ ├── nsAfterHashbang.test │ │ │ │ ├── outsideStmt.test │ │ │ │ └── outsideStmtInvalid.test │ │ │ ├── newInInitializer.test │ │ │ ├── switch.test │ │ │ ├── tryCatch.test │ │ │ ├── tryCatch_without_variable.test │ │ │ ├── tryWithoutCatch.test │ │ │ ├── unset.test │ │ │ └── voidCast.test │ │ └── prettyPrinter/ │ │ ├── comments.test │ │ ├── commentsInCommaList.test │ │ ├── expr/ │ │ │ ├── anonymousClass.test │ │ │ ├── arrayDestructuring.test │ │ │ ├── arraySpread.test │ │ │ ├── arrow_function.test │ │ │ ├── call.test │ │ │ ├── cast.test │ │ │ ├── closure.test │ │ │ ├── constant_deref.test │ │ │ ├── docStrings.test │ │ │ ├── dynamicClassConstFetch.test │ │ │ ├── firstClassCallables.test │ │ │ ├── include.test │ │ │ ├── intrinsics.test │ │ │ ├── list.test │ │ │ ├── literals.test │ │ │ ├── match.test │ │ │ ├── namedArgs.test │ │ │ ├── newDerefParentheses.test │ │ │ ├── newVariable.test │ │ │ ├── nullsafe.test │ │ │ ├── numbers.test │ │ │ ├── operators.test │ │ │ ├── parentheses.test │ │ │ ├── pipe.test │ │ │ ├── shortArraySyntax.test │ │ │ ├── stringEscaping.test │ │ │ ├── throw.test │ │ │ ├── uvs.test │ │ │ ├── variables.test │ │ │ └── yield.test │ │ ├── indent.test │ │ ├── inlineHTMLandPHPtest.file-test │ │ ├── nestedInlineHTML.test │ │ ├── onlyInlineHTML.file-test │ │ ├── onlyPHP.file-test │ │ └── stmt/ │ │ ├── alias.test │ │ ├── asymmetric_visibility.test │ │ ├── attributes.test │ │ ├── block.test │ │ ├── break_continue.test │ │ ├── class.test │ │ ├── class_const.test │ │ ├── const.test │ │ ├── declare.test │ │ ├── disjointNormalFormTypes.test │ │ ├── do_while.test │ │ ├── enum.test │ │ ├── for.test │ │ ├── foreach.test │ │ ├── function_signatures.test │ │ ├── global_static_variables.test │ │ ├── goto.test │ │ ├── groupUse.test │ │ ├── haltCompiler.file-test │ │ ├── if.test │ │ ├── intersection_types.test │ │ ├── multiCatch.test │ │ ├── namespaces.test │ │ ├── nullable_types.test │ │ ├── param_comments.test │ │ ├── properties.test │ │ ├── property_hooks.test │ │ ├── property_promotion.test │ │ ├── readonly_class.test │ │ ├── staticType.test │ │ ├── switch.test │ │ ├── throw.test │ │ ├── traitUse.test │ │ ├── tryCatch.test │ │ ├── tryCatch_without_variable.test │ │ ├── union_types.test │ │ ├── voidCast.test │ │ └── while.test │ ├── fixtures/ │ │ └── Suit.php │ └── updateTests.php ├── test_old/ │ ├── run-php-src.sh │ └── run.php └── tools/ ├── composer.json └── fuzzing/ ├── generateCorpus.php ├── php.dict └── target.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ root = true [*.y] charset = utf-8 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true indent_style = space indent_size = 4 ================================================ FILE: .gitattributes ================================================ /.github export-ignore /doc export-ignore /grammar export-ignore /test export-ignore /test_old export-ignore /tools export-ignore .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore .php-cs-fixer.dist.php export-ignore Makefile export-ignore CHANGELOG.md export-ignore CONTRIBUTING.md export-ignore phpstan-baseline.neon export-ignore phpstan.neon.dist export-ignore phpunit.xml.dist export-ignore UPGRADE-*.md export-ignore ================================================ FILE: .github/workflows/main.yml ================================================ # https://help.github.com/en/categories/automating-your-workflow-with-github-actions name: Main on: push: pull_request: jobs: tests_coverage: runs-on: "ubuntu-latest" name: "PHP 7.4 Unit Tests (with coverage)" steps: - name: "Checkout" uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: coverage: "xdebug" php-version: "7.4" tools: composer:v2 - name: "Install dependencies" run: | composer require php-coveralls/php-coveralls:^2.2 --dev --no-update COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist - name: "Tests" run: "php vendor/bin/phpunit --coverage-clover build/logs/clover.xml" - name: Coveralls env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: "php vendor/bin/php-coveralls" if: ${{ success() }} tests: runs-on: "ubuntu-latest" name: "PHP ${{ matrix.php-version }} Unit Tests" strategy: matrix: php-version: - "8.0" - "8.1" - "8.2" - "8.3" - "8.4" - "8.5" fail-fast: false steps: - name: "Checkout" uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: coverage: "none" php-version: "${{ matrix.php-version }}" ini-file: "development" tools: composer:v2 - name: "Install dependencies" run: "COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist ${{ matrix.flags }}" - name: "PHPUnit" run: "php vendor/bin/phpunit" test_old_73_80: runs-on: "ubuntu-latest" name: "PHP 7.4 Code on PHP 8.4 Integration Tests" steps: - name: "Checkout" uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: coverage: "none" php-version: "8.4" ini-file: "development" tools: composer:v2 - name: "Install PHP 8 dependencies" run: "COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist" - name: "Tests" run: "test_old/run-php-src.sh 7.4.33" test_old_80_70: runs-on: "ubuntu-latest" name: "PHP 8.4 Code on PHP 7.4 Integration Tests" steps: - name: "Checkout" uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: coverage: "none" php-version: "7.4" ini-file: "development" tools: composer:v2 - name: "Install PHP 8 dependencies" run: "COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist" - name: "Tests" run: "test_old/run-php-src.sh 8.4.0beta5" phpstan: runs-on: "ubuntu-latest" name: "PHPStan" steps: - name: "Checkout" uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: coverage: "none" php-version: "8.3" tools: composer:v2 - name: "Install dependencies" run: | cd tools && composer install - name: "PHPStan" run: "php tools/vendor/bin/phpstan" php-cs-fixer: runs-on: "ubuntu-latest" name: "PHP-CS-Fixer" steps: - name: "Checkout" uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: coverage: "none" php-version: "8.3" tools: composer:v2 - name: "Install dependencies" run: | cd tools && composer install - name: "php-cs-fixer" run: "php tools/vendor/bin/php-cs-fixer fix --dry-run" ================================================ FILE: .gitignore ================================================ .idea/ vendor/ composer.lock grammar/kmyacc.exe grammar/y.output .phpunit.result.cache .php-cs-fixer.cache ================================================ FILE: .php-cs-fixer.dist.php ================================================ exclude('PhpParser/Parser') ->in(__DIR__ . '/lib') ->in(__DIR__ . '/test') ->in(__DIR__ . '/grammar') ; $config = new PhpCsFixer\Config(); return $config->setRiskyAllowed(true) ->setRules([ '@PSR12' => true, // We use PSR12 with consistent brace placement. 'curly_braces_position' => [ 'functions_opening_brace' => 'same_line', 'classes_opening_brace' => 'same_line', ], // declare(strict_types=1) on the same line as false, 'declare_strict_types' => true, // Keep argument formatting for now. 'method_argument_space' => ['on_multiline' => 'ignore'], 'phpdoc_align' => ['align' => 'left'], 'phpdoc_trim' => true, 'no_empty_phpdoc' => true, 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], 'no_extra_blank_lines' => true, ]) ->setFinder($finder) ; ================================================ FILE: CHANGELOG.md ================================================ Version 5.7.0 (2025-12-06) -------------------------- ### Fixed * Fixed changing modifier on anonymous class with formatting preserving pretty printer. * Emit an error for unparenthesized arrow functions in pipe operator, and print necessary parentheses in the pretty printer. * Fix PHP 8.5 deprecation warning in php-parse binary. ### Changed * When targeting PHP 8.4 or newer, omit parentheses around immediately dereferenced new expressions. ### Added * Added `shouldPrintRawValue` attribute to `Scalar\Int_`, which makes the pretty printer use the `rawValue` of the node. This can be used to print integers with separators. Version 5.6.2 (2025-10-21) -------------------------- ### Fixed * Fixed formatting-preserving pretty-printing when changing the visibility modifier on a node that has attributes. * Fixed `chr()` deprecation warning on PHP 8.5. ### Added * Added `Param::isFinal()` method. Version 5.6.1 (2025-08-13) -------------------------- ### Fixed * Fixed `Param::isPublic()` for parameters with asymmetric visibility keyword. * Fixed PHP 8.5 deprecation warnings for `SplObjectStorage` methods. ### Added * Added cast `kind` attributes to `Cast\Int_`, `Cast\Bool_` and `Cast\String_`. These allow distinguishing the deprecated versions of these casts. Version 5.6.0 (2025-07-27) -------------------------- ### Added * [8.5] Added support for `clone` with arbitrary function arguments. This will be parsed as an `Expr\FuncCall` node, instead of the usual `Expr\Clone_` node. * [8.5] Permit declaration of `function clone` for use in stubs. * [8.5] Added support for the pipe operator, represented by `Expr\BinaryOp\Pipe`. * [8.5] Added support for the `(void)` cast, represented by `Expr\Cast\Void_`. * [8.5] Added support for the `final` modifier on promoted properties. * Added `CallLike::getArg()` to fetch an argument by position and name. Version 5.5.0 (2025-05-31) -------------------------- ### Added * [8.5] Added support for attributes on constants. `Stmt\Const_` now has an `attrGroups` subnode. * Added `weakReferences` option to `NodeConnectingVisitor` and `ParentConnectingVisitor`. This will create the parent/next/prev references as WeakReferences, to avoid making the AST cyclic and thus increasing GC pressure. ### Changed * Attributes on parameters are now printed on separate lines if the pretty printer target version is PHP 7.4 or older (which is the default). This allows them to be interpreted as comments, instead of causing a parse error. Specify a target version of PHP 8.0 or newer to restore the previous behavior. Version 5.4.0 (2024-12-30) -------------------------- ### Added * Added `Property::isAbstract()` and `Property::isFinal()` methods. * Added `PropertyHook::isFinal()` method. * Emit an error if property hook is used on declaration with multiple properties. ### Fixed * Make legacy class aliases compatible with classmap-authoritative autoloader. * `Param::isPromoted()` and `Param::isPublic()` now returns true for parameters that have property hooks but no explicit visibility modifier. * `PropertyHook::getStmts()` now correctly desugars short `set` hooks. `set => $value` will be expanded to `set { $this->propertyName = $value; }`. This requires the `propertyName` attribute on the hook to be set, which is now also set by the parser. If the attribute is not set, `getStmts()` will throw an error for short set hooks, as it is not possible to produce a correct desugaring. Version 5.3.1 (2024-10-08) -------------------------- ### Added * Added support for declaring functions with name `exit` or `die`, to allow their use in stubs. Version 5.3.0 (2024-09-29) -------------------------- ### Added * Added `indent` option to pretty printer, which can be used to specify the indentation to use (defaulting to four spaces). This also allows using tab indentation. ### Fixed * Resolve names in `PropertyHook`s in the `NameResolver`. * Include the trailing semicolon inside `Stmt\GroupUse` nodes, making them consistent with `Stmt\Use_` nodes. * Fixed indentation sometimes becoming negative in formatting-preserving pretty printer, resulting in `ValueError`s. Version 5.2.0 (2024-09-15) -------------------------- ### Added * [8.4] Added support for `__PROPERTY__` magic constant, represented using a `Node\Scalar\MagicConst\Property` node. * [8.4] Added support for property hooks, which are represented using a new `hooks` subnode on `Node\Stmt\Property` and `Node\Param`, which contains an array of `Node\PropertyHook`. * [8.4] Added support for asymmetric visibility modifiers. Property `flags` can now hold the additional bits `Modifiers::PUBLIC_SET`, `Modifiers::PROTECTED_SET` and `Modifiers::PRIVATE_SET`. * [8.4] Added support for generalized exit function. For backwards compatibility, exit without argument or a single plain argument continues to use a `Node\Expr\Exit_` node. Otherwise (e.g. if a named argument is used) it will be represented as a plain `Node\Expr\FuncCall`. * Added support for passing enum values to various builder methods, like `BuilderFactory::val()`. ### Removed * Removed support for alternative array syntax `$array{0}` from the PHP 8 parser. It is still supported by the PHP 7 parser. This is necessary in order to support property hooks. Version 5.1.0 (2024-07-01) -------------------------- ### Added * [8.4] Added support for dereferencing `new` expressions without parentheses. ### Fixed * Fixed redundant parentheses being added when pretty printing ternary expressions. ### Changed * Made some phpdoc types more precise. Version 5.0.2 (2024-03-05) -------------------------- ### Fixed * Fix handling of indentation on next line after opening PHP tag in formatting-preserving pretty printer. ### Changed * Avoid cyclic references in `Parser` objects. This means that no longer used parser objects are immediately destroyed now, instead of requiring cycle GC. * Update `PhpVersion::getNewestSupported()` to report PHP 8.3 instead of PHP 8.2. Version 5.0.1 (2024-02-21) -------------------------- ### Changed * Added check to detect use of PHP-Parser with libraries that define `T_*` compatibility tokens with incorrect type (such as string instead of int). This would lead to `TypeError`s down the line. Now an `Error` will be thrown early to indicate the problem. Version 5.0.0 (2024-01-07) -------------------------- See UPGRADE-5.0 for detailed migration instructions. ### Fixed * Fixed parent class of `PropertyItem` and `UseItem`. Version 5.0.0-rc1 (2023-12-20) ------------------------------ See UPGRADE-5.0 for detailed migration instructions. ### Fixed * Fixed parsing of empty files. ### Added * Added support for printing additional attributes (like `kind`) in `NodeDumper`. * Added `rawValue` attribute to `InterpolatedStringPart` and heredoc/nowdoc `String_`s, which provides the original, unparsed value. It was previously only available for non-interpolated single/double quoted strings. * Added `Stmt\Block` to represent `{}` code blocks. Previously, such code blocks were flattened into the parent statements array. `Stmt\Block` will not be created for structures that are typically used with code blocks, for example `if ($x) { $y; }` will be represented as previously, while `if ($x) { { $x; } }` will have an extra `Stmt\Block` wrapper. ### Changed * Use visitor to assign comments. This fixes the long-standing issue where comments were assigned to all nodes sharing a starting position. Now only the outer-most node will hold the comments. * Don't parse unicode escape sequences when targeting PHP < 7.0. * Improve NodeDumper performance for large dumps. ### Removed * Removed `Stmt\Throw_` node, use `Expr\Throw_` inside `Stmt\Expression` instead. * Removed `ParserFactory::create()`. Version 5.0.0-beta1 (2023-09-17) -------------------------------- See UPGRADE-5.0 for detailed migration instructions. ### Added * Visitors can now be passed directly to the `NodeTraverser` constructor. A separate call to `addVisitor()` is no longer required. ### Changed * The minimum host PHP version is now PHP 7.4. It is still possible to parse code from older versions. Property types have been added where possible. * The `Lexer` no longer accepts options. `Lexer\Emulative` only accepts a `PhpVersion`. The `startLexing()`, `getTokens()` and `handleHaltCompiler()` methods have been removed. Instead, there is a single method `tokenize()` returning the tokens. * The `Parser::getLexer()` method has been replaced by `Parser::getTokens()`. * Attribute handling has been moved from the lexer to the parser, and is no longer configurable. The comments, startLine, endLine, startTokenPos, endTokenPos, startFilePos, and endFilePos attributes will always be added. * The pretty printer now defaults to PHP 7.4 as the target version. * The pretty printer now indents heredoc/nowdoc strings if the target version is >= 7.3 (flexible heredoc/nowdoc). ### Removed * The deprecated `Comment::getLine()`, `Comment::getTokenPos()` and `Comment::getFilePos()` methods have been removed. Use `Comment::getStartLine()`, `Comment::getStartTokenPos()` and `Comment::getStartFilePos()` instead. ### Deprecated * The `Node::getLine()` method has been deprecated. Use `Node::getStartLine()` instead. Version 5.0.0-alpha3 (2023-06-24) --------------------------------- See UPGRADE-5.0 for detailed migration instructions. ### Added * [PHP 8.3] Added support for typed constants. * [PHP 8.3] Added support for readonly anonymous classes. * Added support for `NodeVisitor::REPLACE_WITH_NULL`. * Added support for CRLF newlines in the pretty printer, using the new `newline` option. ### Changed * Use PHP 7.1 as the default target version for the pretty printer. * Print `else if { }` instead of `else { if { } }`. * The `leaveNode()` method on visitors is now invoked in reverse order of `enterNode()`. * Moved `NodeTraverser::REMOVE_NODE` etc. to `NodeVisitor::REMOVE_NODE`. The old constants are still available for compatibility. * The `Name` subnode `parts` has been replaced by `name`, which stores the name as a string rather than an array of parts separated by namespace separators. The `getParts()` method returns the old representation. * No longer accept strings for types in Node constructors. Instead, either an `Identifier`, `Name` or `ComplexType` must be passed. * `Comment::getReformattedText()` now normalizes CRLF newlines to LF newlines. ### Fixed * Don't trim leading whitespace in formatting preserving printer. * Treat DEL as a label character in the formatting preserving printer depending on the targeted PHP version. * Fix error reporting in emulative lexer without explicitly specified error handler. * Gracefully handle non-contiguous array indices in the `Differ`. Version 5.0.0-alpha2 (2023-03-05) --------------------------------- See UPGRADE-5.0 for detailed migration instructions. ### Added * [PHP 8.3] Added support for dynamic class constant fetch. * Added many additional type annotations. PhpStan is now used. * Added a fuzzing target for PHP-Fuzzer, which was how a lot of pretty printer bugs were found. * Added `isPromoted()`, `isPublic()`, `isProtected()`, `isPrivate()` and `isReadonly()` methods on `Param`. * Added support for class constants in trait builder. * Added `PrettyPrinter` interface. * Added support for formatting preservation when toggling static modifiers. * The `php-parse` binary now accepts `-` as the file name, in which case it will read from stdin. ### Fixed * The pretty printer now uses a more accurate treatment of unary operator precedence, and will only wrap them in parentheses if required. This allowed fixing a number of other precedence related bugs. * The pretty printer now respects the precedence of `clone`, `throw` and arrow functions. * The pretty printer no longer unconditionally wraps `yield` in parentheses, unless the target version is set to older than PHP 7.0. * Fixed formatting preservation for alternative elseif/else syntax. * Fixed checks for when it is safe to print strings as heredoc/nowdoc to accommodate flexible doc string semantics. * The pretty printer now prints parentheses around new/instanceof operands in all required situations. * Similar, differences in allowed expressions on the LHS of `->` and `::` are now taken into account. * Fixed various cases where `\r` at the end of a doc string could be incorrectly merged into a CRLF sequence with a following `\n`. * `__halt_compiler` is no longer recognized as a semi-reserved keyword, in line with PHP behavior. * ``. ### Fixed * Multiple modifiers for promoted properties are now accepted. In particular this allows something like `public readonly` for promoted properties. * Formatting-preserving pretty printing for comments in array literals has been fixed. Version 4.12.0 (2021-07-21) --------------------------- ### Added * [PHP 8.1] Added support for readonly properties (through a new `MODIFIER_READONLY`). * [PHP 8.1] Added support for final class constants. ### Fixed * Fixed compatibility with PHP 8.1. `&` tokens are now canonicalized to the `T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG` and `T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG` tokens used in PHP 8.1. This happens unconditionally, regardless of whether the emulative lexer is used. Version 4.11.0 (2021-07-03) --------------------------- ### Added * `BuilderFactory::args()` now accepts named arguments. * `BuilderFactory::attribute()` has been added. * An `addAttribute()` method accepting an `Attribute` or `AttributeGroup` has been adde to all builders that accept attributes, such as `Builder\Class_`. ### Fixed * `NameResolver` now handles enums. * `PrettyPrinter` now prints backing enum type. * Builder methods for types now property handle `never` type. Version 4.10.5 (2021-05-03) --------------------------- ### Added * [PHP 8.1] Added support for enums. These are represented using the `Stmt\Enum_` and `Stmt\EnumCase` nodes. * [PHP 8.1] Added support for never type. This type will now be returned as an `Identifier` rather than `Name`. * Added `ClassConst` builder. ### Changed * Non-UTF-8 code units in strings will now be hex-encoded. ### Fixed * Fixed precedence of arrow functions. Version 4.10.4 (2020-12-20) --------------------------- ### Fixed * Fixed position information for variable-variables (#741). * Fixed position information for traits/interfaces preceded by if statement (#738). Version 4.10.3 (2020-12-03) --------------------------- ### Fixed * Fixed formatting-preserving pretty printing for `"{$x}"`. * Ternary expressions are now treated as non-associative in the pretty printer, in order to generate code that is compatible with the parentheses requirement introduced in PHP 8. * Removed no longer necessary `error_clear_last()` call in lexer, which may interfere with fatal error handlers if invoked during shutdown. Version 4.10.2 (2020-09-26) ------------------ ### Fixed * Fixed check for token emulation conflicts with other libraries. Version 4.10.1 (2020-09-23) --------------------------- ### Added * Added support for recovering from a missing semicolon after a property or class constant declaration. ### Fixed * Fix spurious whitespace in formatting-preserving pretty printer when both removing and adding elements at the start of a list. * Fix incorrect case-sensitivity in keyword token emulation. Version 4.10.0 (2020-09-19) --------------------------- ### Added * [PHP 8.0] Added support for attributes. These are represented using a new `AttributeGroup` node containing `Attribute` nodes. A new `attrGroups` subnode is available on all node types that support attributes, i.e. `Stmt\Class_`, `Stmt\Trait_`, `Stmt\Interface_`, `Stmt\Function_`, `Stmt\ClassMethod`, `Stmt\ClassConst`, `Stmt\Property`, `Expr\Closure`, `Expr\ArrowFunction` and `Param`. * [PHP 8.0] Added support for nullsafe properties inside interpolated strings, in line with an upstream change. ### Fixed * Improved compatibility with other libraries that use forward compatibility defines for PHP tokens. Version 4.9.1 (2020-08-30) -------------------------- ### Added * Added support for removing the first element of a list to the formatting-preserving pretty printer. ### Fixed * Allow member modifiers as part of namespaced names. These were missed when support for other keywords was added. Version 4.9.0 (2020-08-18) -------------------------- ### Added * [PHP 8.0] Added support for named arguments, represented using a new `name` subnode on `Arg`. * [PHP 8.0] Added support for static return type, represented like a normal class return type. * [PHP 8.0] Added support for throw expression, represented using a new `Expr\Throw_` node. For backwards compatibility reasons, throw expressions in statement context continue to be represented using `Stmt\Throw_`. * [PHP 8.0] Added support for keywords as parts of namespaced names. ### Fixed * Emit parentheses for class constant fetch with complex left-hand-side. * Emit parentheses for new/instanceof on complex class expression. Version 4.8.0 (2020-08-09) -------------------------- ### Added * [PHP 8.0] Added support for nullsafe operator, represented using the new `Expr\NullsafePropertyFetch` and `Expr\NullsafeMethodCall` nodes. * Added `phpVersion` option to the emulative lexer, which allows controlling the target version to emulate (defaults to the latest available, currently PHP 8.0). This is useful to parse code that uses reserved keywords from newer PHP versions as identifiers. Version 4.7.0 (2020-07-25) -------------------------- ### Added * Add `ParentConnectingVisitor` and `NodeConnectingVisitor` classes. * [PHP 8.0] Added support for match expressions. These are represented using a new `Expr\Match_` containing `MatchArm`s. * [PHP 8.0] Added support for trailing comma in closure use lists. ### Fixed * Fixed missing error for unterminated comment with trailing newline (#688). * Compatibility with PHP 8.0 has been restored: Namespaced names are now always represented by `T_NAME_*` tokens, using emulationg on older PHP versions. Full support for reserved keywords in namespaced names is not yet present. Version 4.6.0 (2020-07-02) -------------------------- ### Added * [PHP 8.0] Added support for trailing commas in parameter lists. * [PHP 8.0] Added support for constructor promotion. The parameter visibility is stored in `Node\Param::$flags`. ### Fixed * Comment tokens now always follow the PHP 8 interpretation, and do not include trailing whitespace. * As a result of the previous change, some whitespace issues when inserting a statement into a method containing only a comment, and using the formatting-preserving pretty printer, have been resolved. Version 4.5.0 (2020-06-03) -------------------------- ### Added * [PHP 8.0] Added support for the mixed type. This means `mixed` types are now parsed as an `Identifier` rather than a `Name`. * [PHP 8.0] Added support for catching without capturing the exception. This means that `Catch_::$var` may now be null. Version 4.4.0 (2020-04-10) -------------------------- ### Added * Added support for passing union types in builders. * Added end line, token position and file position information for comments. * Added `getProperty()` method to `ClassLike` nodes. ### Fixed * Fixed generation of invalid code when using the formatting preserving pretty printer, and inserting code next to certain nop statements. The formatting is still ugly though. * `getDocComment()` no longer requires that the very last comment before a node be a doc comment. There may not be non-doc comments between the doc comment and the declaration. * Allowed arbitrary expressions in `isset()` and `list()`, rather than just variables. In particular, this allows `isset(($x))`, which is legal PHP code. * [PHP 8.0] Add support for [variable syntax tweaks RFC](https://wiki.php.net/rfc/variable_syntax_tweaks). Version 4.3.0 (2019-11-08) -------------------------- ### Added * [PHP 8.0] Added support for union types using a new `UnionType` node. Version 4.2.5 (2019-10-25) -------------------------- ### Changed * Tests and documentation are no longer included in source archives. They can still be accessed by cloning the repository. * php-yacc is now used to generate the parser. This has no impact on users of the library. Version 4.2.4 (2019-09-01) -------------------------- ### Added * Added getProperties(), getConstants() and getTraitUses() to ClassLike. (#629, #630) ### Fixed * Fixed flexible heredoc emulation to check for digits after the end label. This synchronizes behavior with the upcoming PHP 7.3.10 release. Version 4.2.3 (2019-08-12) -------------------------- ### Added * [PHP 7.4] Add support for numeric literal separators. (#615) ### Fixed * Fixed resolution of return types for arrow functions. (#613) * Fixed compatibility with PHP 7.4. Version 4.2.2 (2019-05-25) -------------------------- ### Added * [PHP 7.4] Add support for arrow functions using a new `Expr\ArrowFunction` node. (#602) * [PHP 7.4] Add support for array spreads, using a new `unpack` subnode on `ArrayItem`. (#609) * Added support for inserting into empty list nodes in the formatting preserving pretty printer. ### Changed * `php-parse` will now print messages to stderr, so that stdout only contains the actual result of the operation (such as a JSON dump). (#605) ### Fixed * Fixed attribute assignment for zero-length nop statements, and a related assertion failure in the formatting-preserving pretty printer. (#589) Version 4.2.1 (2019-02-16) -------------------------- ### Added * [PHP 7.4] Add support for `??=` operator through a new `AssignOp\Coalesce` node. (#575) Version 4.2.0 (2019-01-12) -------------------------- ### Added * [PHP 7.4] Add support for typed properties through a new `type` subnode of `Stmt\Property`. Additionally `Builder\Property` now has a `setType()` method. (#567) * Add `kind` attribute to `Cast\Double_`, which allows to distinguish between `(float)`, `(double)` and `(real)`. The form of the cast will be preserved by the pretty printer. (#565) ### Fixed * Remove assertion when pretty printing anonymous class with a name (#554). Version 4.1.1 (2018-12-26) -------------------------- ### Fixed * Fix "undefined offset" notice when parsing specific malformed code (#551). ### Added * Support error recovery for missing return type (`function foo() : {}`) (#544). Version 4.1.0 (2018-10-10) -------------------------- ### Added * Added support for PHP 7.3 flexible heredoc/nowdoc strings, completing support for PHP 7.3. There are two caveats for this feature: * In some rare, pathological cases flexible heredoc/nowdoc strings change the interpretation of existing doc strings. PHP-Parser will now use the new interpretation. * Flexible heredoc/nowdoc strings require special support from the lexer. Because this is not available on PHP versions before 7.3, support has to be emulated. This emulation is not perfect and some cases which we do not expect to occur in practice (such as flexible doc strings being nested within each other through abuse of variable-variable interpolation syntax) may not be recognized correctly. * Added `DONT_TRAVERSE_CURRENT_AND_CHILDREN` to `NodeTraverser` to skip both traversal of child nodes, and prevent subsequent visitors from visiting the current node. Version 4.0.4 (2018-09-18) -------------------------- ### Added * The following methods have been added to `BuilderFactory`: * `useTrait()` (fluent builder) * `traitUseAdaptation()` (fluent builder) * `useFunction()` (fluent builder) * `useConst()` (fluent builder) * `var()` * `propertyFetch()` ### Deprecated * `Builder\Param::setTypeHint()` has been deprecated in favor of the newly introduced `Builder\Param::setType()`. Version 4.0.3 (2018-07-15) -------------------------- ### Fixed * Fixed possible undefined offset notice in formatting-preserving printer. (#513) ### Added * Improved error recovery inside arrays. * Preserve trailing comment inside classes. **Note:** This change is possibly BC breaking if your code validates that classes can only contain certain statement types. After this change, classes can also contain Nop statements, while this was not previously possible. (#509) Version 4.0.2 (2018-06-03) -------------------------- ### Added * Improved error recovery inside classes. * Support error recovery for `foreach` without `as`. * Support error recovery for parameters without variable (`function (Type ) {}`). * Support error recovery for functions without body (`function ($foo)`). Version 4.0.1 (2018-03-25) -------------------------- ### Added * [PHP 7.3] Added support for trailing commas in function calls. * [PHP 7.3] Added support for by-reference array destructuring. * Added checks to node traverser to prevent replacing a statement with an expression or vice versa. This should prevent common mistakes in the implementation of node visitors. * Added the following methods to `BuilderFactory`, to simplify creation of expressions: * `funcCall()` * `methodCall()` * `staticCall()` * `new()` * `constFetch()` * `classConstFetch()` Version 4.0.0 (2018-02-28) -------------------------- * No significant code changes since the beta 1 release. Version 4.0.0-beta1 (2018-01-27) -------------------------------- ### Fixed * In formatting-preserving pretty printer: Fixed indentation when inserting into lists. (#466) ### Added * In formatting-preserving pretty printer: Improved formatting of elements inserted into multi-line arrays. ### Removed * The `Autoloader` class has been removed. It is now required to use the Composer autoloader. Version 4.0.0-alpha3 (2017-12-26) --------------------------------- ### Fixed * In the formatting-preserving pretty printer: * Fixed comment indentation. * Fixed handling of inline HTML in the fallback case. * Fixed insertion into list nodes that require creation of a code block. ### Added * Added support for inserting at the start of list nodes in formatting-preserving pretty printer. Version 4.0.0-alpha2 (2017-11-10) --------------------------------- ### Added * In the formatting-preserving pretty printer: * Added support for changing modifiers. * Added support for anonymous classes. * Added support for removing from list nodes. * Improved support for changing comments. * Added start token offsets to comments. Version 4.0.0-alpha1 (2017-10-18) --------------------------------- ### Added * Added experimental support for format-preserving pretty-printing. In this mode formatting will be preserved for parts of the code which have not been modified. * Added `replaceNodes` option to `NameResolver`, defaulting to true. If this option is disabled, resolved names will be added as `resolvedName` attributes, instead of replacing the original names. * Added `NodeFinder` class, which can be used to find nodes based on a callback or class name. This is a utility to avoid custom node visitor implementations for simple search operations. * Added `ClassMethod::isMagic()` method. * Added `BuilderFactory` methods: `val()` method for creating an AST for a simple value, `concat()` for creating concatenation trees, `args()` for preparing function arguments. * Added `NameContext` class, which encapsulates the `NameResolver` logic independently of the actual AST traversal. This facilitates use in other context, such as class names in doc comments. Additionally it provides an API for getting the shortest representation of a name. * Added `Node::setAttributes()` method. * Added `JsonDecoder`. This allows conversion JSON back into an AST. * Added `Name` methods `toLowerString()` and `isSpecialClassName()`. * Added `Identifier` and `VarLikeIdentifier` nodes, which are used in place of simple strings in many places. * Added `getComments()`, `getStartLine()`, `getEndLine()`, `getStartTokenPos()`, `getEndTokenPos()`, `getStartFilePos()` and `getEndFilePos()` methods to `Node`. These provide a more obvious access point for the already existing attributes of the same name. * Added `ConstExprEvaluator` to evaluate constant expressions to PHP values. * Added `Expr\BinaryOp::getOperatorSigil()`, returning `+` for `Expr\BinaryOp\Plus`, etc. ### Changed * Many subnodes that previously held simple strings now use `Identifier` (or `VarLikeIdentifier`) nodes. Please see the UPGRADE-4.0 file for an exhaustive list of affected nodes and some notes on possible impact. * Expression statements (`expr;`) are now represented using a `Stmt\Expression` node. Previously these statements were directly represented as their constituent expression. * The `name` subnode of `Param` has been renamed to `var` and now contains a `Variable` rather than a plain string. * The `name` subnode of `StaticVar` has been renamed to `var` and now contains a `Variable` rather than a plain string. * The `var` subnode of `ClosureUse` now contains a `Variable` rather than a plain string. * The `var` subnode of `Catch` now contains a `Variable` rather than a plain string. * The `alias` subnode of `UseUse` is now `null` if no explicit alias is given. As such, `use Foo\Bar` and `use Foo\Bar as Bar` are now represented differently. The `getAlias()` method can be used to get the effective alias, even if it is not explicitly given. ### Removed * Support for running on PHP 5 and HHVM has been removed. You can however still parse code of old PHP versions (such as PHP 5.2), while running on PHP 7. * Removed `type` subnode on `Class`, `ClassMethod` and `Property` nodes. Use `flags` instead. * The `ClassConst::isStatic()` method has been removed. Constants cannot have a static modifier. * The `NodeTraverser` no longer accepts `false` as a return value from a `leaveNode()` method. `NodeTraverser::REMOVE_NODE` should be returned instead. * The `Node::setLine()` method has been removed. If you really need to, you can use `setAttribute()` instead. * The misspelled `Class_::VISIBILITY_MODIFER_MASK` constant has been dropped in favor of `Class_::VISIBILITY_MODIFIER_MASK`. * The XML serializer has been removed. As such, the classes `Serializer\XML`, and `Unserializer\XML`, as well as the interfaces `Serializer` and `Unserializer` no longer exist. * The `BuilderAbstract` class has been removed. It's functionality is moved into `BuilderHelpers`. However, this is an internal class and should not be used directly. Version 3.1.5 (2018-02-28) -------------------------- ### Fixed * Fixed duplicate comment assignment in switch statements. (#469) * Improve compatibility with PHP-Scoper. (#477) Version 3.1.4 (2018-01-25) -------------------------- ### Fixed * Fixed pretty printing of `-(-$x)` and `+(+$x)`. (#459) Version 3.1.3 (2017-12-26) -------------------------- ### Fixed * Improve compatibility with php-scoper, by supporting prefixed namespaces in `NodeAbstract::getType()`. Version 3.1.2 (2017-11-04) -------------------------- ### Fixed * Comments on empty blocks are now preserved on a `Stmt\Nop` node. (#382) ### Added * Added `kind` attribute for `Stmt\Namespace_` node, which is one of `KIND_SEMICOLON` or `KIND_BRACED`. (#417) * Added `setDocComment()` method to namespace builder. (#437) Version 3.1.1 (2017-09-02) -------------------------- ### Fixed * Fixed syntax error on comment after brace-style namespace declaration. (#412) * Added support for TraitUse statements in trait builder. (#413) Version 3.1.0 (2017-07-28) -------------------------- ### Added * [PHP 7.2] Added support for trailing comma in group use statements. * [PHP 7.2] Added support for `object` type. This means `object` types will now be represented as a builtin type (a simple `"object"` string), rather than a class `Name`. ### Fixed * Floating-point numbers are now printed correctly if the LC_NUMERIC locale uses a comma as decimal separator. ### Changed * `Name::$parts` is no longer deprecated. Version 3.0.6 (2017-06-28) -------------------------- ### Fixed * Fixed the spelling of `Class_::VISIBILITY_MODIFIER_MASK`. The previous spelling of `Class_::VISIBILITY_MODIFER_MASK` is preserved for backwards compatibility. * The pretty printing will now preserve comments inside array literals and function calls by printing the array items / function arguments on separate lines. Array literals and functions that do not contain comments are not affected. ### Added * Added `Builder\Param::makeVariadic()`. ### Deprecated * The `Node::setLine()` method has been deprecated. Version 3.0.5 (2017-03-05) -------------------------- ### Fixed * Name resolution of `NullableType`s is now performed earlier, so that a fully resolved signature is available when a function is entered. (#360) * `Error` nodes are now considered empty, while previously they extended until the token where the error occurred. This made some nodes larger than expected. (#359) * Fixed notices being thrown during error recovery in some situations. (#362) Version 3.0.4 (2017-02-10) -------------------------- ### Fixed * Fixed some extensibility issues in pretty printer (`pUseType()` is now public and `pPrec()` calls into `p()`, instead of directly dispatching to the type-specific printing method). * Fixed notice in `bin/php-parse` script. ### Added * Error recovery from missing semicolons is now supported in more cases. * Error recovery from trailing commas in positions where PHP does not support them is now supported. Version 3.0.3 (2017-02-03) -------------------------- ### Fixed * In `"$foo[0]"` the `0` is now parsed as an `LNumber` rather than `String`. (#325) * Ensure integers and floats are always pretty printed preserving semantics, even if the particular value can only be manually constructed. * Throw a `LogicException` when trying to pretty-print an `Error` node. Previously this resulted in an undefined method exception or fatal error. ### Added * [PHP 7.1] Added support for negative interpolated offsets: `"$foo[-1]"` * Added `preserveOriginalNames` option to `NameResolver`. If this option is enabled, an `originalName` attribute, containing the unresolved name, will be added to each resolved name. * Added `php-parse --with-positions` option, which dumps nodes with position information. ### Deprecated * The XML serializer has been deprecated. In particular, the classes `Serializer\XML`, `Unserializer\XML`, as well as the interfaces `Serializer` and `Unserializer` are deprecated. Version 3.0.2 (2016-12-06) -------------------------- ### Fixed * Fixed name resolution of nullable types. (#324) * Fixed pretty-printing of nullable types. Version 3.0.1 (2016-12-01) -------------------------- ### Fixed * Fixed handling of nested `list()`s: If the nested list was unkeyed, it was directly included in the list items. If it was keyed, it was wrapped in `ArrayItem`. Now nested `List_` nodes are always wrapped in `ArrayItem`s. (#321) Version 3.0.0 (2016-11-30) -------------------------- ### Added * Added support for dumping node positions in the NodeDumper through the `dumpPositions` option. * Added error recovery support for `$`, `new`, `Foo::`. Version 3.0.0-beta2 (2016-10-29) -------------------------------- This release primarily improves our support for error recovery. ### Added * Added `Node::setDocComment()` method. * Added `Error::getMessageWithColumnInfo()` method. * Added support for recovery from lexer errors. * Added support for recovering from "special" errors (i.e. non-syntax parse errors). * Added precise location information for lexer errors. * Added `ErrorHandler` interface, and `ErrorHandler\Throwing` and `ErrorHandler\Collecting` as specific implementations. These provide a general mechanism for handling error recovery. * Added optional `ErrorHandler` argument to `Parser::parse()`, `Lexer::startLexing()` and `NameResolver::__construct()`. * The `NameResolver` now adds a `namespacedName` attribute on name nodes that cannot be statically resolved (unqualified unaliased function or constant names in namespaces). ### Fixed * Fixed attribute assignment for `GroupUse` prefix and variables in interpolated strings. ### Changed * The constants on `NameTraverserInterface` have been moved into the `NameTraverser` class. * Due to the error handling changes, the `Parser` interface and `Lexer` API have changed. * The emulative lexer now directly postprocesses tokens, instead of using `~__EMU__~` sequences. This changes the protected API of the lexer. * The `Name::slice()` method now returns `null` for empty slices, previously `new Name([])` was used. `Name::concat()` now also supports concatenation with `null`. ### Removed * Removed `Name::append()` and `Name::prepend()`. These mutable methods have been superseded by the immutable `Name::concat()`. * Removed `Error::getRawLine()` and `Error::setRawLine()`. These methods have been superseded by `Error::getStartLine()` and `Error::setStartLine()`. * Removed support for node cloning in the `NodeTraverser`. * Removed `$separator` argument from `Name::toString()`. * Removed `throw_on_error` parser option and `Parser::getErrors()` method. Use the `ErrorHandler` mechanism instead. Version 3.0.0-beta1 (2016-09-16) -------------------------------- ### Added * [7.1] Function/method and parameter builders now support PHP 7.1 type hints (void, iterable and nullable types). * Nodes and Comments now implement `JsonSerializable`. The node kind is stored in a `nodeType` property. * The `InlineHTML` node now has an `hasLeadingNewline` attribute, that specifies whether the preceding closing tag contained a newline. The pretty printer honors this attribute. * Partial parsing of `$obj->` (with missing property name) is now supported in error recovery mode. * The error recovery mode is now exposed in the `php-parse` script through the `--with-recovery` or `-r` flags. The following changes are also part of PHP-Parser 2.1.1: * The PHP 7 parser will now generate a parse error for `$var =& new Obj` assignments. * Comments on free-standing code blocks will now be retained as comments on the first statement in the code block. Version 3.0.0-alpha1 (2016-07-25) --------------------------------- ### Added * [7.1] Added support for `void` and `iterable` types. These will now be represented as strings (instead of `Name` instances) similar to other builtin types. * [7.1] Added support for class constant visibility. The `ClassConst` node now has a `flags` subnode holding the visibility modifier, as well as `isPublic()`, `isProtected()` and `isPrivate()` methods. The constructor changed to accept the additional subnode. * [7.1] Added support for nullable types. These are represented using a new `NullableType` node with a single `type` subnode. * [7.1] Added support for short array destructuring syntax. This means that `Array` nodes may now appear as the left-hand-side of assignments and foreach value targets. Additionally the array items may now contain `null` values if elements are skipped. * [7.1] Added support for keys in list() destructuring. The `List` subnode `vars` has been renamed to `items` and now contains `ArrayItem`s instead of plain variables. * [7.1] Added support for multi-catch. The `Catch` subnode `type` has been renamed to `types` and is now an array of `Name`s. * `Name::slice()` now supports lengths and negative offsets. This brings it in line with `array_slice()` functionality. ### Changed Due to PHP 7.1 support additions described above, the node structure changed as follows: * `void` and `iterable` types are now stored as strings if the PHP 7 parser is used. * The `ClassConst` constructor changed to accept an additional `flags` subnode. * The `Array` subnode `items` may now contain `null` elements (destructuring). * The `List` subnode `vars` has been renamed to `items` and now contains `ArrayItem`s instead of plain variables. * The `Catch` subnode `type` has been renamed to `types` and is now an array of `Name`s. Additionally the following changes were made: * The `type` subnode on `Class`, `ClassMethod` and `Property` has been renamed to `flags`. The `type` subnode has retained for backwards compatibility and is populated to the same value as `flags`. However, writes to `type` will not update `flags`. * The `TryCatch` subnode `finallyStmts` has been replaced with a `finally` subnode that holds an explicit `Finally` node. This allows for more accurate attribute assignment. * The `Trait` constructor now has the same form as the `Class` and `Interface` constructors: It takes an array of subnodes. Unlike classes/interfaces, traits can only have a `stmts` subnode. * The `NodeDumper` now prints class/method/property/constant modifiers, as well as the include and use type in a textual representation, instead of only showing the number. * All methods on `PrettyPrinter\Standard` are now protected. Previously most of them were public. ### Removed * Removed support for running on PHP 5.4. It is however still possible to parse PHP 5.2-5.4 code while running on a newer version. * The deprecated `Comment::setLine()` and `Comment::setText()` methods have been removed. * The deprecated `Name::set()`, `Name::setFirst()` and `Name::setLast()` methods have been removed. Version 2.1.1 (2016-09-16) -------------------------- ### Changed * The pretty printer will now escape all control characters in the range `\x00-\x1F` inside double quoted strings. If no special escape sequence is available, an octal escape will be used. * The quality of the error recovery has been improved. In particular unterminated expressions should be handled more gracefully. * The PHP 7 parser will now generate a parse error for `$var =& new Obj` assignments. * Comments on free-standing code blocks will no be retained as comments on the first statement in the code block. Version 2.1.0 (2016-04-19) -------------------------- ### Fixed * Properly support `B""` strings (with uppercase `B`) in a number of places. * Fixed reformatting of indented parts in a certain non-standard comment style. ### Added * Added `dumpComments` option to node dumper, to enable dumping of comments associated with nodes. * Added `Stmt\Nop` node, that is used to collect comments located at the end of a block or at the end of a file (without a following node with which they could otherwise be associated). * Added `kind` attribute to `Expr\Exit` to distinguish between `exit` and `die`. * Added `kind` attribute to `Scalar\LNumber` to distinguish between decimal, binary, octal and hexadecimal numbers. * Added `kind` attribute to `Expr\Array` to distinguish between `array()` and `[]`. * Added `kind` attribute to `Scalar\String` and `Scalar\Encapsed` to distinguish between single-quoted, double-quoted, heredoc and nowdoc string. * Added `docLabel` attribute to `Scalar\String` and `Scalar\Encapsed`, if it is a heredoc or nowdoc string. * Added start file offset information to `Comment` nodes. * Added `setReturnType()` method to function and method builders. * Added `-h` and `--help` options to `php-parse` script. ### Changed * Invalid octal literals now throw a parse error in PHP 7 mode. * The pretty printer takes all the new attributes mentioned in the previous section into account. * The protected `AbstractPrettyPrinter::pComments()` method no longer returns a trailing newline. * The bundled autoloader supports library files being stored in a different directory than `PhpParser` for easier downstream distribution. ### Deprecated * The `Comment::setLine()` and `Comment::setText()` methods have been deprecated. Construct new objects instead. ### Removed * The internal (but public) method `Scalar\LNumber::parse()` has been removed. A non-internal `LNumber::fromString()` method has been added instead. Version 2.0.1 (2016-02-28) -------------------------- ### Fixed * `declare() {}` and `declare();` are not semantically equivalent and will now result in different ASTs. The format case will have an empty `stmts` array, while the latter will set `stmts` to `null`. * Magic constants are now supported as semi-reserved keywords. * A shebang line like `#!/usr/bin/env php` is now allowed at the start of a namespaced file. Previously this generated an exception. * The `prettyPrintFile()` method will not strip a trailing `?>` from the raw data that follows a `__halt_compiler()` statement. * The `prettyPrintFile()` method will not strip an opening `slice()` which takes a subslice of a name. ### Changed * `PhpParser\Parser` is now an interface, implemented by `Parser\Php5`, `Parser\Php7` and `Parser\Multiple`. The `Multiple` parser will try multiple parsers, until one succeeds. * Token constants are now defined on `PhpParser\Parser\Tokens` rather than `PhpParser\Parser`. * The `Name->set()`, `Name->append()`, `Name->prepend()` and `Name->setFirst()` methods are deprecated in favor of `Name::concat()` and `Name->slice()`. * The `NodeTraverser` no longer clones nodes by default. The old behavior can be restored by passing `true` to the constructor. * The constructor for `Scalar` nodes no longer has a default value. E.g. `new LNumber()` should now be written as `new LNumber(0)`. --- **This changelog only includes changes from the 2.0 series. For older changes see the [1.x series changelog](https://github.com/nikic/PHP-Parser/blob/1.x/CHANGELOG.md) and the [0.9 series changelog](https://github.com/nikic/PHP-Parser/blob/0.9/CHANGELOG.md).** ================================================ FILE: CONTRIBUTING.md ================================================ ## Coding Style This project uses PSR-12 with consistent brace placement. This means that the opening brace is always on the same line, even for class and method declarations. ## Tools This project uses PHP-CS-Fixer and PHPStan. You can invoke them using `make`: ```shell make php-cs-fixer make phpstan ``` ## Adding support for new PHP syntax 1. If necessary, add emulation support for new tokens. * Add a new subclass of `Lexer\TokenEmulator`. Take inspiration from existing classes. * Add the new class to the array in `Lexer\Emulative`. * Add tests for the emulation in `Lexer\EmulativeTest`. You'll want to modify `provideTestReplaceKeywords()` for new reserved keywords and `provideTestLexNewFeatures()` for other emulations. 2. Add any new node classes that are needed. 3. Add support for the new syntax in `grammar/php.y`. Regenerate the parser by running `php grammar/rebuildParsers.php`. Use `--debug` if there are conflicts. 4. Add pretty-printing support by implementing a `pFooBar()` method in `PrettyPrinter\Standard`. 5. Add tests both in `test/code/parser` and `test/code/prettyPrinter`. 6. Add support for formatting-preserving pretty-printing. This is done by modifying the data tables at the end of `PrettyPrinterAbstract`. Add a test in `test/code/formatPreservation`. 7. Does the new syntax feature namespaced names? If so, add support for name resolution in `NodeVisitor\NameResolver`. Test it in `NodeVisitor\NameResolverTest`. 8. Does the new syntax require any changes to builders? Is so, make them :) ================================================ FILE: LICENSE ================================================ BSD 3-Clause License Copyright (c) 2011, Nikita Popov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================ FILE: Makefile ================================================ .PHONY: phpstan php-cs-fixer tools/vendor: composer install -d tools phpstan: tools/vendor php tools/vendor/bin/phpstan php-cs-fixer: tools/vendor php tools/vendor/bin/php-cs-fixer fix tests: php vendor/bin/phpunit ================================================ FILE: README.md ================================================ PHP Parser ========== [![Coverage Status](https://coveralls.io/repos/github/nikic/PHP-Parser/badge.svg?branch=master)](https://coveralls.io/github/nikic/PHP-Parser?branch=master) This is a PHP parser written in PHP. Its purpose is to simplify static code analysis and manipulation. [**Documentation for version 5.x**][doc_master] (current; for running on PHP >= 7.4; for parsing PHP 7.0 to PHP 8.4, with limited support for parsing PHP 5.x). [Documentation for version 4.x][doc_4_x] (supported; for running on PHP >= 7.0; for parsing PHP 5.2 to PHP 8.3). Features -------- The main features provided by this library are: * Parsing PHP 7, and PHP 8 code into an abstract syntax tree (AST). * Invalid code can be parsed into a partial AST. * The AST contains accurate location information. * Dumping the AST in human-readable form. * Converting an AST back to PHP code. * Formatting can be preserved for partially changed ASTs. * Infrastructure to traverse and modify ASTs. * Resolution of namespaced names. * Evaluation of constant expressions. * Builders to simplify AST construction for code generation. * Converting an AST into JSON and back. Quick Start ----------- Install the library using [composer](https://getcomposer.org): php composer.phar require nikic/php-parser Parse some PHP code into an AST and dump the result in human-readable form: ```php createForNewestSupportedVersion(); try { $ast = $parser->parse($code); } catch (Error $error) { echo "Parse error: {$error->getMessage()}\n"; return; } $dumper = new NodeDumper; echo $dumper->dump($ast) . "\n"; ``` This dumps an AST looking something like this: ``` array( 0: Stmt_Function( attrGroups: array( ) byRef: false name: Identifier( name: test ) params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: foo ) default: null ) ) returnType: null stmts: array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: var_dump ) args: array( 0: Arg( name: null value: Expr_Variable( name: foo ) byRef: false unpack: false ) ) ) ) ) ) ) ``` Let's traverse the AST and perform some kind of modification. For example, drop all function bodies: ```php use PhpParser\Node; use PhpParser\Node\Stmt\Function_; use PhpParser\NodeTraverser; use PhpParser\NodeVisitorAbstract; $traverser = new NodeTraverser(); $traverser->addVisitor(new class extends NodeVisitorAbstract { public function enterNode(Node $node) { if ($node instanceof Function_) { // Clean out the function body $node->stmts = []; } } }); $ast = $traverser->traverse($ast); echo $dumper->dump($ast) . "\n"; ``` This gives us an AST where the `Function_::$stmts` are empty: ``` array( 0: Stmt_Function( attrGroups: array( ) byRef: false name: Identifier( name: test ) params: array( 0: Param( attrGroups: array( ) type: null byRef: false variadic: false var: Expr_Variable( name: foo ) default: null ) ) returnType: null stmts: array( ) ) ) ``` Finally, we can convert the new AST back to PHP code: ```php use PhpParser\PrettyPrinter; $prettyPrinter = new PrettyPrinter\Standard; echo $prettyPrinter->prettyPrintFile($ast); ``` This gives us our original code, minus the `var_dump()` call inside the function: ```php Expr_AssignOp_BitwiseAnd Expr_AssignBitwiseOr => Expr_AssignOp_BitwiseOr Expr_AssignBitwiseXor => Expr_AssignOp_BitwiseXor Expr_AssignConcat => Expr_AssignOp_Concat Expr_AssignDiv => Expr_AssignOp_Div Expr_AssignMinus => Expr_AssignOp_Minus Expr_AssignMod => Expr_AssignOp_Mod Expr_AssignMul => Expr_AssignOp_Mul Expr_AssignPlus => Expr_AssignOp_Plus Expr_AssignShiftLeft => Expr_AssignOp_ShiftLeft Expr_AssignShiftRight => Expr_AssignOp_ShiftRight Expr_BitwiseAnd => Expr_BinaryOp_BitwiseAnd Expr_BitwiseOr => Expr_BinaryOp_BitwiseOr Expr_BitwiseXor => Expr_BinaryOp_BitwiseXor Expr_BooleanAnd => Expr_BinaryOp_BooleanAnd Expr_BooleanOr => Expr_BinaryOp_BooleanOr Expr_Concat => Expr_BinaryOp_Concat Expr_Div => Expr_BinaryOp_Div Expr_Equal => Expr_BinaryOp_Equal Expr_Greater => Expr_BinaryOp_Greater Expr_GreaterOrEqual => Expr_BinaryOp_GreaterOrEqual Expr_Identical => Expr_BinaryOp_Identical Expr_LogicalAnd => Expr_BinaryOp_LogicalAnd Expr_LogicalOr => Expr_BinaryOp_LogicalOr Expr_LogicalXor => Expr_BinaryOp_LogicalXor Expr_Minus => Expr_BinaryOp_Minus Expr_Mod => Expr_BinaryOp_Mod Expr_Mul => Expr_BinaryOp_Mul Expr_NotEqual => Expr_BinaryOp_NotEqual Expr_NotIdentical => Expr_BinaryOp_NotIdentical Expr_Plus => Expr_BinaryOp_Plus Expr_ShiftLeft => Expr_BinaryOp_ShiftLeft Expr_ShiftRight => Expr_BinaryOp_ShiftRight Expr_Smaller => Expr_BinaryOp_Smaller Expr_SmallerOrEqual => Expr_BinaryOp_SmallerOrEqual Scalar_ClassConst => Scalar_MagicConst_Class Scalar_DirConst => Scalar_MagicConst_Dir Scalar_FileConst => Scalar_MagicConst_File Scalar_FuncConst => Scalar_MagicConst_Function Scalar_LineConst => Scalar_MagicConst_Line Scalar_MethodConst => Scalar_MagicConst_Method Scalar_NSConst => Scalar_MagicConst_Namespace Scalar_TraitConst => Scalar_MagicConst_Trait ``` These changes may affect custom pretty printers and code comparing the return value of `Node::getType()` to specific strings. ### Miscellaneous * The classes `Template` and `TemplateLoader` have been removed. You should use some other [code generation][code_gen] project built on top of PHP-Parser instead. * The `PrettyPrinterAbstract::pStmts()` method now emits a leading newline if the statement list is not empty. Custom pretty printers should remove the explicit newline before `pStmts()` calls. Old: ```php public function pStmt_Trait(PHPParser_Node_Stmt_Trait $node) { return 'trait ' . $node->name . "\n" . '{' . "\n" . $this->pStmts($node->stmts) . "\n" . '}'; } ``` New: ```php public function pStmt_Trait(Stmt\Trait_ $node) { return 'trait ' . $node->name . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; } ``` [code_gen]: https://github.com/nikic/PHP-Parser/wiki/Projects-using-the-PHP-Parser#code-generation ================================================ FILE: UPGRADE-2.0.md ================================================ Upgrading from PHP-Parser 1.x to 2.0 ==================================== ### PHP version requirements PHP-Parser now requires PHP 5.4 or newer to run. It is however still possible to *parse* PHP 5.2 and PHP 5.3 source code, while running on a newer version. ### Creating a parser instance Parser instances should now be created through the `ParserFactory`. Old direct instantiation code will not work, because the parser class was renamed. Old: ```php use PhpParser\Parser, PhpParser\Lexer; $parser = new Parser(new Lexer\Emulative); ``` New: ```php use PhpParser\ParserFactory; $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); ``` The first argument to `ParserFactory` determines how different PHP versions are handled. The possible values are: * `ParserFactory::PREFER_PHP7`: Try to parse code as PHP 7. If this fails, try to parse it as PHP 5. * `ParserFactory::PREFER_PHP5`: Try to parse code as PHP 5. If this fails, try to parse it as PHP 7. * `ParserFactory::ONLY_PHP7`: Parse code as PHP 7. * `ParserFactory::ONLY_PHP5`: Parse code as PHP 5. For most practical purposes the difference between `PREFER_PHP7` and `PREFER_PHP5` is mainly whether a scalar type hint like `string` will be stored as `'string'` (PHP 7) or as `new Name('string')` (PHP 5). To use a custom lexer, pass it as the second argument to the `create()` method: ```php use PhpParser\ParserFactory; $lexer = new MyLexer; $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer); ``` ### Rename of the `PhpParser\Parser` class `PhpParser\Parser` is now an interface, which is implemented by `Parser\Php5`, `Parser\Php7` and `Parser\Multiple`. Parser tokens are now defined in `Parser\Tokens`. If you use the `ParserFactory` described above to create your parser instance, these changes should have no further impact on you. ### Removal of legacy aliases All legacy aliases for classes have been removed. This includes the old non-namespaced `PHPParser_` classes, as well as the classes that had to be renamed for PHP 7 support. ### Deprecations The `set()`, `setFirst()`, `append()` and `prepend()` methods of the `Node\Name` class have been deprecated. Instead `Name::concat()` and `Name->slice()` should be used. ### Miscellaneous * The `NodeTraverser` no longer clones nodes by default. If you want to restore the old behavior, pass `true` to the constructor. * The legacy node format has been removed. If you use custom nodes, they are now expected to implement a `getSubNodeNames()` method. * The default value for `Scalar` node constructors was removed. This means that something like `new LNumber()` should be replaced by `new LNumber(0)`. * String parts of encapsed strings are now represented using `Scalar\EncapsStringPart` nodes, while previously raw strings were used. This affects the `parts` child of `Scalar\Encaps` and `Expr\ShellExec`. ================================================ FILE: UPGRADE-3.0.md ================================================ Upgrading from PHP-Parser 2.x to 3.0 ==================================== The backwards-incompatible changes in this release may be summarized as follows: * The specific details of the node representation have changed in some cases, primarily to accommodate new PHP 7.1 features. * There have been significant changes to the error recovery implementation. This may affect you, if you used the error recovery mode or have a custom lexer implementation. * A number of deprecated methods were removed. ### PHP version requirements PHP-Parser now requires PHP 5.5 or newer to run. It is however still possible to *parse* PHP 5.2, 5.3 and 5.4 source code, while running on a newer version. ### Changes to the node structure The following changes are likely to require code changes if the respective nodes are used: * The `List` subnode `vars` has been renamed to `items` and now contains `ArrayItem`s instead of plain variables. * The `Catch` subnode `type` has been renamed to `types` and is now an array of `Name`s. * The `TryCatch` subnode `finallyStmts` has been replaced with a `finally` subnode that holds an explicit `Finally` node. * The `type` subnode on `Class`, `ClassMethod` and `Property` has been renamed to `flags`. The `type` subnode has retained for backwards compatibility and is populated to the same value as `flags`. However, writes to `type` will not update `flags` and use of `type` is discouraged. The following changes are unlikely to require code changes: * The `ClassConst` constructor changed to accept an additional `flags` subnode. * The `Trait` constructor now has the same form as the `Class` and `Interface` constructors: It takes an array of subnodes. Unlike classes/interfaces, traits can only have a `stmts` subnode. * The `Array` subnode `items` may now contain `null` elements (due to destructuring). * `void` and `iterable` types are now stored as strings if the PHP 7 parser is used. Previously these would have been represented as `Name` instances. ### Changes to error recovery mode Previously, error recovery mode was enabled by setting the `throwOnError` option to `false` when creating the parser, while collected errors were retrieved using the `getErrors()` method: ```php $lexer = ...; $parser = (new ParserFactory)->create(ParserFactor::ONLY_PHP7, $lexer, [ 'throwOnError' => true, ]); $stmts = $parser->parse($code); $errors = $parser->getErrors(); if ($errors) { handleErrors($errors); } processAst($stmts); ``` Both the `throwOnError` option and the `getErrors()` method have been removed in PHP-Parser 3.0. Instead an instance of `ErrorHandler\Collecting` should be passed to the `parse()` method: ```php $lexer = ...; $parser = (new ParserFactory)->create(ParserFactor::ONLY_PHP7, $lexer); $errorHandler = new ErrorHandler\Collecting; $stmts = $parser->parse($code, $errorHandler); if ($errorHandler->hasErrors()) { handleErrors($errorHandler->getErrors()); } processAst($stmts); ``` #### Multiple parser fallback in error recovery mode As a result of this change, if a `Multiple` parser is used (e.g. through the `ParserFactory` using `PREFER_PHP7` or `PREFER_PHP5`), it will now return the result of the first *non-throwing* parse. As parsing never throws in error recovery mode, the result from the first parser will always be returned. The PHP 7 parser is a superset of the PHP 5 parser, with the exceptions that `=& new` and `global $$foo->bar` are not supported (other differences are in representation only). The PHP 7 parser will be able to recover from the error in both cases. For this reason, this change will likely pass unnoticed if you do not specifically test for this syntax. It is possible to restore the precise previous behavior with the following code: ```php $lexer = ...; $parser7 = new Parser\Php7($lexer); $parser5 = new Parser\Php5($lexer); $errors7 = new ErrorHandler\Collecting(); $stmts7 = $parser7->parse($code, $errors7); if ($errors7->hasErrors()) { $errors5 = new ErrorHandler\Collecting(); $stmts5 = $parser5->parse($code, $errors5); if (!$errors5->hasErrors()) { // If PHP 7 parse has errors but PHP 5 parse has no errors, use PHP 5 result return [$stmts5, $errors5]; } } // If PHP 7 succeeds or both fail use PHP 7 result return [$stmts7, $errors7]; ``` #### Error handling in the lexer In order to support recovery from lexer errors, the signature of the `startLexing()` method changed to optionally accept an `ErrorHandler`: ```php // OLD public function startLexing($code); // NEW public function startLexing($code, ErrorHandler $errorHandler = null); ``` If you use a custom lexer with overridden `startLexing()` method, it needs to be changed to accept the extra parameter. The value should be passed on to the parent method. #### Error checks in node constructors The constructors of certain nodes used to contain additional checks for semantic errors, such as creating a try block without either catch or finally. These checks have been moved from the node constructors into the parser. This allows recovery from such errors, as well as representing the resulting (invalid) AST. This means that certain error conditions are no longer checked for manually constructed nodes. ### Removed methods, arguments, options The following methods, arguments or options have been removed: * `Comment::setLine()`, `Comment::setText()`: Create new `Comment` instances instead. * `Name::set()`, `Name::setFirst()`, `Name::setLast()`, `Name::append()`, `Name::prepend()`: Use `Name::concat()` in combination with `Name::slice()` instead. * `Error::getRawLine()`, `Error::setRawLine()`. Use `Error::getStartLine()` and `Error::setStartLine()` instead. * `Parser::getErrors()`. Use `ErrorHandler\Collecting` instead. * `$separator` argument of `Name::toString()`. Use `strtr()` instead, if you really need it. * `$cloneNodes` argument of `NodeTraverser::__construct()`. Explicitly clone nodes in the visitor instead. * `throwOnError` parser option. Use `ErrorHandler\Collecting` instead. ### Miscellaneous * The `NameResolver` will now resolve unqualified function and constant names in the global namespace into fully qualified names. For example `foo()` in the global namespace resolves to `\foo()`. For names where no static resolution is possible, a `namespacedName` attribute is added now, containing the namespaced variant of the name. * All methods on `PrettyPrinter\Standard` are now protected. Previously most of them were public. The pretty printer should only be invoked using the `prettyPrint()`, `prettyPrintFile()` and `prettyPrintExpr()` methods. * The node dumper now prints numeric values that act as enums/flags in a string representation. If node dumper results are used in tests, updates may be needed to account for this. * The constants on `NameTraverserInterface` have been moved into the `NameTraverser` class. * The emulative lexer now directly postprocesses tokens, instead of using `~__EMU__~` sequences. This changes the protected API of the emulative lexer. * The `Name::slice()` method now returns `null` for empty slices, previously `new Name([])` was used. `Name::concat()` now also supports concatenation with `null`. ================================================ FILE: UPGRADE-4.0.md ================================================ Upgrading from PHP-Parser 3.x to 4.0 ==================================== ### PHP version requirements PHP-Parser now requires PHP 7.0 or newer to run. It is however still possible to *parse* PHP 5.2-5.6 source code, while running on a newer version. HHVM is no longer actively supported. ### Changes to the node structure * Many subnodes that previously held simple strings now store `Identifier` nodes instead (or `VarLikeIdentifier` nodes if they have form `$ident`). The constructors of the affected nodes will automatically convert strings to `Identifier`s and `Identifier`s implement `__toString()`. As such some code continues to work without changes, but anything using `is_string()`, type-strict comparisons or strict-mode may require adjustment. The following is an exhaustive list of all affected subnodes: * `Const_::$name` * `NullableType::$type` (for simple types) * `Param::$type` (for simple types) * `Expr\ClassConstFetch::$name` * `Expr\Closure::$returnType` (for simple types) * `Expr\MethodCall::$name` * `Expr\PropertyFetch::$name` * `Expr\StaticCall::$name` * `Expr\StaticPropertyFetch::$name` (uses `VarLikeIdentifier`) * `Stmt\Class_::$name` * `Stmt\ClassMethod::$name` * `Stmt\ClassMethod::$returnType` (for simple types) * `Stmt\Function_::$name` * `Stmt\Function_::$returnType` (for simple types) * `Stmt\Goto_::$name` * `Stmt\Interface_::$name` * `Stmt\Label::$name` * `Stmt\PropertyProperty::$name` (uses `VarLikeIdentifier`) * `Stmt\TraitUseAdaptation\Alias::$method` * `Stmt\TraitUseAdaptation\Alias::$newName` * `Stmt\TraitUseAdaptation\Precedence::$method` * `Stmt\Trait_::$name` * `Stmt\UseUse::$alias` * Expression statements (`expr;`) are now represented using a `Stmt\Expression` node. Previously these statements were directly represented as their constituent expression. * The `name` subnode of `Param` has been renamed to `var` and now contains a `Variable` rather than a plain string. * The `name` subnode of `StaticVar` has been renamed to `var` and now contains a `Variable` rather than a plain string. * The `var` subnode of `ClosureUse` now contains a `Variable` rather than a plain string. * The `var` subnode of `Catch_` now contains a `Variable` rather than a plain string. * The `alias` subnode of `UseUse` is now `null` if no explicit alias is given. As such, `use Foo\Bar` and `use Foo\Bar as Bar` are now represented differently. The `getAlias()` method can be used to get the effective alias, even if it is not explicitly given. ### Miscellaneous * The indentation handling in the pretty printer has been changed (this is only relevant if you extend the pretty printer). Previously indentation was automatic, and parts were excluded using `pNoindent()`. Now no-indent is the default and newlines that require indentation should use `$this->nl`. ### Removed functionality * Removed `type` subnode on `Class_`, `ClassMethod` and `Property` nodes. Use `flags` instead. * The `ClassConst::isStatic()` method has been removed. Constants cannot have a static modifier. * The `NodeTraverser` no longer accepts `false` as a return value from a `leaveNode()` method. `NodeTraverser::REMOVE_NODE` should be returned instead. * The `Node::setLine()` method has been removed. If you really need to, you can use `setAttribute()` instead. * The misspelled `Class_::VISIBILITY_MODIFER_MASK` constant has been dropped in favor of `Class_::VISIBILITY_MODIFIER_MASK`. * The XML serializer has been removed. As such, the classes `Serializer\XML`, and `Unserializer\XML`, as well as the interfaces `Serializer` and `Unserializer` no longer exist. * The `BuilderAbstract` class has been removed. It's functionality is moved into `BuilderHelpers`. However, this is an internal class and should not be used directly. * The `Autoloader` class has been removed in favor of relying on the Composer autoloader. ================================================ FILE: UPGRADE-5.0.md ================================================ Upgrading from PHP-Parser 4.x to 5.0 ==================================== ### PHP version requirements PHP-Parser now requires PHP 7.4 or newer to run. It is however still possible to *parse* code for older versions, while running on a newer version. ### PHP 5 parsing support The dedicated parser for PHP 5 has been removed. The PHP 7 parser now accepts a `PhpVersion` argument, which can be used to improve compatibility with older PHP versions. In particular, if an older `PhpVersion` is specified, then: * For versions before PHP 7.0, `$foo =& new Bar()` assignments are allowed without error. * For versions before PHP 7.0, invalid octal literals `089` are allowed without error. * For versions before PHP 7.0, unicode escape sequences `\u{123}` in strings are not parsed. * Type hints are interpreted as a class `Name` or as a built-in `Identifier` depending on PHP version, for example `int` is treated as a class name on PHP 5.6 and as a built-in on PHP 7.0. However, some aspects of PHP 5 parsing are no longer supported: * Some variables like `$$foo[0]` are valid in both PHP 5 and PHP 7, but have different interpretation. In that case, the PHP 7 AST will always be constructed (`($$foo)[0]` rather than `${$foo[0]}`). * Declarations of the form `global $$var[0]` are not supported in PHP 7 and will cause a parse error. In error recovery mode, it is possible to continue parsing after such declarations. * The PHP 7 parser will accept many constructs that are not valid in PHP 5. However, this was also true of the dedicated PHP 5 parser. The following symbols are affected by this removal: * The `PhpParser\Parser\Php5` class has been removed. * The `PhpParser\Parser\Multiple` class has been removed. While not strictly related to PHP 5 support, this functionality is no longer useful without it. * The `PhpParser\ParserFactory::ONLY_PHP5` and `PREFER_PHP5` options have been removed. ### Changes to the parser factory The `ParserFactory::create()` method has been removed in favor of three new methods that provide more fine-grained control over the PHP version being targeted: * `createForNewestSupportedVersion()`: Use this if you don't know the PHP version of the code you're parsing. It's better to assume a too new version than a too old one. * `createForHostVersion()`: Use this if you're parsing code for the PHP version you're running on. * `createForVersion()`: Use this if you know the PHP version of the code you want to parse. The `createForNewestSupportedVersion()` and `createForHostVersion()` are available since PHP-Parser 4.18.0, to allow libraries to support PHP-Parser 4 and 5 at the same time more easily. In all cases, the PHP version is a fairly weak hint that is only used on a best-effort basis. The parser will usually accept code for newer versions if it does not have any backwards-compatibility implications. For example, if you specify version `"8.0"`, then `class ReadOnly {}` is treated as a valid class declaration, while using `public readonly int $prop` will lead to a parse error. However, `final public const X = Y;` will be accepted in both cases. ```php use PhpParser\ParserFactory; use PhpParser\PhpVersion; $factory = new ParserFactory(); # Before $parser = $factory->create(ParserFactory::PREFER_PHP7); # After (this is roughly equivalent to PREFER_PHP7 behavior) $parser = $factory->createForNewestSupportedVersion(); # Or $parser = $factory->createForHostVersion(); # Before $parser = $factory->create(ParserFactory::ONLY_PHP5); # After (supported on a best-effort basis) $parser = $factory->createForVersion(PhpVersion::fromString("5.6")); ``` ### Changes to the throw representation Previously, `throw` statements like `throw $e;` were represented using the `Stmt\Throw_` class, while uses inside other expressions (such as `$x ?? throw $e`) used the `Expr\Throw_` class. Now, `throw $e;` is represented as a `Stmt\Expression` that contains an `Expr\Throw_`. The `Stmt\Throw_` class has been removed. ```php # Code throw $e; # Before Stmt_Throw( expr: Expr_Variable( name: e ) ) # After Stmt_Expression( expr: Expr_Throw( expr: Expr_Variable( name: e ) ) ) ``` ### Changes to the array destructuring representation Previously, the `list($x) = $y` destructuring syntax was represented using a `Node\Expr\List_` node, while `[$x] = $y` used a `Node\Expr\Array_` node, the same used for the creation (rather than destructuring) of arrays. Now, destructuring is always represented using `Node\Expr\List_`. The `kind` attribute with value `Node\Expr\List_::KIND_LIST` or `Node\Expr\List_::KIND_ARRAY` specifies which syntax was actually used. ```php # Code [$x] = $y; # Before Expr_Assign( var: Expr_Array( items: array( 0: Expr_ArrayItem( key: null value: Expr_Variable( name: x ) byRef: false unpack: false ) ) ) expr: Expr_Variable( name: y ) ) # After Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: x ) byRef: false unpack: false ) ) ) expr: Expr_Variable( name: y ) ) ``` ### Changes to the name representation Previously, `Name` nodes had a `parts` subnode, which stores an array of name parts, split by namespace separators. Now, `Name` nodes instead have a `name` subnode, which stores a plain string. For example, the name `Foo\Bar` was previously represented by `Name(parts: ['Foo', 'Bar'])` and is now represented by `Name(name: 'Foo\Bar')` instead. It is possible to convert the name to the previous representation using `$name->getParts()`. The `Name` constructor continues to accept both the string and the array representation. The `Name::getParts()` method is available since PHP-Parser 4.16.0, to allow libraries to support PHP-Parser 4 and 5 at the same time more easily. ### Changes to the block representation Previously, code blocks `{ ... }` were always flattened into their parent statement list. For example `while ($x) { $a; { $b; } $c; }` would produce the same node structure as `if ($x) { $a; $b; $c; }`, namely a `Stmt\While_` node whose `stmts` subnode is an array of three statements. Now, the nested `{ $b; }` block is represented using an explicit `Stmt\Block` node. However, the outer `{ $a; { $b; } $c; }` block is still represented using a simple array in the `stmts` subnode. ```php # Code while ($x) { $a; { $b; } $c; } # Before Stmt_While( cond: Expr_Variable( name: x ) stmts: array( 0: Stmt_Expression( expr: Expr_Variable( name: a ) ) 1: Stmt_Expression( expr: Expr_Variable( name: b ) ) 2: Stmt_Expression( expr: Expr_Variable( name: c ) ) ) ) # After Stmt_While( cond: Expr_Variable( name: x ) stmts: array( 0: Stmt_Expression( expr: Expr_Variable( name: a ) ) 1: Stmt_Block( stmts: array( 0: Stmt_Expression( expr: Expr_Variable( name: b ) ) ) ) 2: Stmt_Expression( expr: Expr_Variable( name: c ) ) ) ) ``` ### Changes to comment assignment Previously, comments were assigned to all nodes starting at the same position. Now they will be assigned to the outermost node only. ```php # Code // Comment $a + $b; # Before Stmt_Expression( expr: Expr_BinaryOp_Plus( left: Expr_Variable( name: a comments: array( 0: // Comment ) ) right: Expr_Variable( name: b ) comments: array( 0: // Comment ) ) comments: array( 0: // Comment ) ) # After Stmt_Expression( expr: Expr_BinaryOp_Plus( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) comments: array( 0: // Comment ) ) ``` ### Renamed nodes A number of AST nodes have been renamed or moved in the AST hierarchy: * `Node\Scalar\LNumber` is now `Node\Scalar\Int_`. * `Node\Scalar\DNumber` is now `Node\Scalar\Float_`. * `Node\Scalar\Encapsed` is now `Node\Scalar\InterpolatedString`. * `Node\Scalar\EncapsedStringPart` is now `Node\InterpolatedStringPart` and no longer extends `Node\Scalar` or `Node\Expr`. * `Node\Expr\ArrayItem` is now `Node\ArrayItem` and no longer extends `Node\Expr`. * `Node\Expr\ClosureUse` is now `Node\ClosureUse` and no longer extends `Node\Expr`. * `Node\Stmt\DeclareDeclare` is now `Node\DeclareItem` and no longer extends `Node\Stmt`. * `Node\Stmt\PropertyProperty` is now `Node\PropertyItem` and no longer extends `Node\Stmt`. * `Node\Stmt\StaticVar` is now `Node\StaticVar` and no longer extends `Node\Stmt`. * `Node\Stmt\UseUse` is now `Node\UseItem` and no longer extends `Node\Stmt`. The old class names have been retained as aliases for backwards compatibility. However, the `Node::getType()` method will now always return the new name (e.g. `ClosureUse` instead of `Expr_ClosureUse`). ### Modifiers Modifier flags (as used by the `$flags` subnode of `Class_`, `ClassMethod`, `Property`, etc.) are now available as class constants on a separate `PhpParser\Modifiers` class, instead of being part of `PhpParser\Node\Stmt\Class_`, to make it clearer that these are used by many different nodes. The old constants are deprecated, but are still available. ```php PhpParser\Node\Stmt\Class_::MODIFIER_PUBLIC -> PhpParser\Modifiers::PUBLIC PhpParser\Node\Stmt\Class_::MODIFIER_PROTECTED -> PhpParser\Modifiers::PROTECTED PhpParser\Node\Stmt\Class_::MODIFIER_PRIVATE -> PhpParser\Modifiers::PRIVATE PhpParser\Node\Stmt\Class_::MODIFIER_STATIC -> PhpParser\Modifiers::STATIC PhpParser\Node\Stmt\Class_::MODIFIER_ABSTRACT -> PhpParser\Modifiers::ABSTRACT PhpParser\Node\Stmt\Class_::MODIFIER_FINAL -> PhpParser\Modifiers::FINAL PhpParser\Node\Stmt\Class_::MODIFIER_READONLY -> PhpParser\Modifiers::READONLY PhpParser\Node\Stmt\Class_::VISIBILITY_MODIFIER_MASK -> PhpParser\Modifiers::VISIBILITY_MASK ``` ### Changes to node constructors Node constructor arguments accepting types no longer accept plain strings. Either an `Identifier` or `Name` (or `ComplexType`) should be passed instead. This affects the following constructor arguments: * The `'returnType'` key of `$subNodes` argument of `Node\Expr\ArrowFunction`. * The `'returnType'` key of `$subNodes` argument of `Node\Expr\Closure`. * The `'returnType'` key of `$subNodes` argument of `Node\Stmt\ClassMethod`. * The `'returnType'` key of `$subNodes` argument of `Node\Stmt\Function_`. * The `$type` argument of `Node\NullableType`. * The `$type` argument of `Node\Param`. * The `$type` argument of `Node\Stmt\Property`. * The `$type` argument of `Node\ClassConst`. To follow the previous behavior, an `Identifier` should be passed, which indicates a built-in type. ### Changes to the pretty printer A number of changes to the standard pretty printer have been made, to make it match contemporary coding style conventions (and in particular PSR-12). Options to restore the previous behavior are not provided, but it is possible to override the formatting methods (such as `pStmt_ClassMethod`) with your preferred formatting. Return types are now formatted without a space before the `:`: ```php # Before function test() : Type { } # After function test(): Type { } ``` `abstract` and `final` are now printed before visibility modifiers: ```php # Before public abstract function test(); # After abstract public function test(); ``` A space is now printed between `use` and the following `(` for closures: ```php # Before function () use($var) { }; # After function () use ($var) { }; ``` Backslashes in single-quoted strings are now only printed if they are necessary: ```php # Before 'Foo\\Bar'; '\\\\'; # After 'Foo\Bar'; '\\\\'; ``` `else if` structures will now omit redundant parentheses: ```php # Before else { if ($x) { // ... } } # After else if ($x) { // ... } ``` The pretty printer now accepts a `phpVersion` option, which accepts a `PhpVersion` object and defaults to PHP 7.4. The pretty printer will make formatting choices to make the code valid for that version. It currently controls the following behavior: * For PHP >= 7.0 (default), short array syntax `[]` will be used by default. This does not affect nodes that specify an explicit array syntax using the `kind` attribute. * For PHP >= 7.0 (default), parentheses around `yield` expressions will only be printed when necessary. Previously, parentheses were always printed, even if `yield` was used as a statement. * For PHP >= 7.1 (default), the short array syntax `[]` will be used for destructuring by default (instead of `list()`). This does not affect nodes that specify an explicit syntax using the `kind` attribute. * For PHP >= 7.3 (default), a newline is no longer forced after heredoc/nowdoc strings, as the requirement for this has been removed with the introduction of flexible heredoc/nowdoc strings. * For PHP >= 7.3 (default), heredoc/nowdoc strings are now indented just like regular code. This was allowed with the introduction of flexible heredoc/nowdoc strings. ### Changes to precedence handling in the pretty printer The pretty printer now more accurately models operator precedence. Especially for unary operators, less unnecessary parentheses will be printed. Conversely, many bugs where semantically meaningful parentheses were omitted have been fixed. To support these changes, precedence is now handled differently in the pretty printer. The internal `p()` method, which is used to recursively print nodes, now has the following signature: ```php protected function p( Node $node, int $precedence = self::MAX_PRECEDENCE, int $lhsPrecedence = self::MAX_PRECEDENCE, bool $parentFormatPreserved = false ): string; ``` The `$precedence` is the precedence of the direct parent operator (if any), while `$lhsPrecedence` is that precedence of the nearest binary operator on whose left-hand-side the node occurs. For unary operators, only the `$lhsPrecedence` is relevant. Recursive calls in pretty-printer methods should generally continue calling `p()` without additional parameters. However, pretty-printer methods for operators that participate in precedence resolution need to be adjusted. For example, typical implementations for operators look as follows now: ```php protected function pExpr_BinaryOp_Plus( BinaryOp\Plus $node, int $precedence, int $lhsPrecedence ): string { return $this->pInfixOp( BinaryOp\Plus::class, $node->left, ' + ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_UnaryPlus( Expr\UnaryPlus $node, int $precedence, int $lhsPrecedence ): string { return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr, $precedence, $lhsPrecedence); } ``` The new `$precedence` and `$lhsPrecedence` arguments need to be passed down to the `pInfixOp()`, `pPrefixOp()` and `pPostfixOp()` methods. ### Changes to the node traverser If there are multiple visitors, the node traverser will now call `leaveNode()` and `afterTraverse()` methods in the reverse order of the corresponding `enterNode()` and `beforeTraverse()` calls: ```php # Before $visitor1->enterNode($node); $visitor2->enterNode($node); $visitor1->leaveNode($node); $visitor2->leaveNode($node); # After $visitor1->enterNode($node); $visitor2->enterNode($node); $visitor2->leaveNode($node); $visitor1->leaveNode($node); ``` Additionally, the special `NodeVisitor` return values have been moved from `NodeTraverser` to `NodeVisitor`. The old names are deprecated, but still available. ```php PhpParser\NodeTraverser::REMOVE_NODE -> PhpParser\NodeVisitor::REMOVE_NODE PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN -> PhpParser\NodeVisitor::DONT_TRAVERSE_CHILDREN PhpParser\NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN -> PhpParser\NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN PhpParser\NodeTraverser::STOP_TRAVERSAL -> PhpParser\NodeVisitor::STOP_TRAVERSAL ``` Visitors can now also be passed directly to the `NodeTraverser` constructor: ```php # Before (and still supported) $traverser = new NodeTraverser(); $traverser->addVisitor(new NameResolver()); # After $traverser = new NodeTraverser(new NameResolver()); ``` ### Changes to token representation Tokens are now internally represented using the `PhpParser\Token` class, which exposes the same base interface as the `PhpToken` class introduced in PHP 8.0. On PHP 8.0 or newer, `PhpParser\Token` extends from `PhpToken`, otherwise it extends from a polyfill implementation. The most important parts of the interface may be summarized as follows: ```php class Token { public int $id; public string $text; public int $line; public int $pos; public function is(int|string|array $kind): bool; } ``` The token array is now an array of `Token`s, rather than an array of arrays and strings. Additionally, the token array is now terminated by a sentinel token with ID 0. ### Changes to the lexer The lexer API is reduced to a single `Lexer::tokenize()` method, which returns an array of tokens. The `startLexing()` and `getNextToken()` methods have been removed. Responsibility for determining start and end attributes for nodes has been moved from the lexer to the parser. The lexer no longer accepts an options array. The `usedAttributes` option has been removed without replacement, and the parser will now unconditionally add the `comments`, `startLine`, `endLine`, `startFilePos`, `endFilePos`, `startTokenPos` and `endTokenPos` attributes. There should no longer be a need to directly interact with the `Lexer` for end users, as the `ParserFactory` will create an appropriate instance, and no additional configuration of the lexer is necessary. To use formatting-preserving pretty printing, the setup boilerplate changes as follows: ```php # Before $lexer = new Lexer\Emulative([ 'usedAttributes' => [ 'comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos', ], ]); $parser = new Parser\Php7($lexer); $oldStmts = $parser->parse($code); $oldTokens = $lexer->getTokens(); $traverser = new NodeTraverser(); $traverser->addVisitor(new NodeVisitor\CloningVisitor()); $newStmts = $traverser->traverse($oldStmts); # After $parser = (new ParserFactory())->createForNewestSupportedVersion(); $oldStmts = $parser->parse($code); $oldTokens = $parser->getTokens(); $traverser = new NodeTraverser(new NodeVisitor\CloningVisitor()); $newStmts = $traverser->traverse($oldStmts); ``` ### Miscellaneous changes * The deprecated `Builder\Param::setTypeHint()` method has been removed in favor of `Builder\Param::setType()`. * The deprecated `Error` constructor taking a start line has been removed. Pass `['startLine' => $startLine]` attributes instead. * The deprecated `Comment::getLine()`, `Comment::getTokenPos()` and `Comment::getFilePos()` methods have been removed. Use `Comment::getStartLine()`, `Comment::getStartTokenPos()` and `Comment::getStartFilePos()` instead. * `Comment::getReformattedText()` now normalizes CRLF newlines to LF newlines. * The `Node::getLine()` method has been deprecated. Use `Node::getStartLine()` instead. ================================================ FILE: bin/php-parse ================================================ #!/usr/bin/env php createForVersion($attributes['version']); $dumper = new PhpParser\NodeDumper([ 'dumpComments' => true, 'dumpPositions' => $attributes['with-positions'], ]); $prettyPrinter = new PhpParser\PrettyPrinter\Standard; $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver); foreach ($files as $file) { if ($file === '-') { $code = file_get_contents('php://stdin'); fwrite(STDERR, "====> Stdin:\n"); } else if (strpos($file, ' Code $code\n"); } else { if (!file_exists($file)) { fwrite(STDERR, "File $file does not exist.\n"); exit(1); } $code = file_get_contents($file); fwrite(STDERR, "====> File $file:\n"); } if ($attributes['with-recovery']) { $errorHandler = new PhpParser\ErrorHandler\Collecting; $stmts = $parser->parse($code, $errorHandler); foreach ($errorHandler->getErrors() as $error) { $message = formatErrorMessage($error, $code, $attributes['with-column-info']); fwrite(STDERR, $message . "\n"); } if (null === $stmts) { continue; } } else { try { $stmts = $parser->parse($code); } catch (PhpParser\Error $error) { $message = formatErrorMessage($error, $code, $attributes['with-column-info']); fwrite(STDERR, $message . "\n"); exit(1); } } foreach ($operations as $operation) { if ('dump' === $operation) { fwrite(STDERR, "==> Node dump:\n"); echo $dumper->dump($stmts, $code), "\n"; } elseif ('pretty-print' === $operation) { fwrite(STDERR, "==> Pretty print:\n"); echo $prettyPrinter->prettyPrintFile($stmts), "\n"; } elseif ('json-dump' === $operation) { fwrite(STDERR, "==> JSON dump:\n"); echo json_encode($stmts, JSON_PRETTY_PRINT), "\n"; } elseif ('var-dump' === $operation) { fwrite(STDERR, "==> var_dump():\n"); var_dump($stmts); } elseif ('resolve-names' === $operation) { fwrite(STDERR, "==> Resolved names.\n"); $stmts = $traverser->traverse($stmts); } } } function formatErrorMessage(PhpParser\Error $e, $code, $withColumnInfo) { if ($withColumnInfo && $e->hasColumnInfo()) { return $e->getMessageWithColumnInfo($code); } else { return $e->getMessage(); } } function showHelp($error = '') { if ($error) { fwrite(STDERR, $error . "\n\n"); } fwrite($error ? STDERR : STDOUT, <<<'OUTPUT' Usage: php-parse [operations] file1.php [file2.php ...] or: php-parse [operations] " false, 'with-positions' => false, 'with-recovery' => false, 'version' => PhpParser\PhpVersion::getNewestSupported(), ]; array_shift($args); $parseOptions = true; foreach ($args as $arg) { if (!$parseOptions) { $files[] = $arg; continue; } switch ($arg) { case '--dump': case '-d': $operations[] = 'dump'; break; case '--pretty-print': case '-p': $operations[] = 'pretty-print'; break; case '--json-dump': case '-j': $operations[] = 'json-dump'; break; case '--var-dump': $operations[] = 'var-dump'; break; case '--resolve-names': case '-N': $operations[] = 'resolve-names'; break; case '--with-column-info': case '-c': $attributes['with-column-info'] = true; break; case '--with-positions': case '-P': $attributes['with-positions'] = true; break; case '--with-recovery': case '-r': $attributes['with-recovery'] = true; break; case '--help': case '-h': showHelp(); break; case '--': $parseOptions = false; break; default: if (preg_match('/^--version=(.*)$/', $arg, $matches)) { $attributes['version'] = PhpParser\PhpVersion::fromString($matches[1]); } elseif ($arg[0] === '-' && \strlen($arg[0]) > 1) { showHelp("Invalid operation $arg."); } else { $files[] = $arg; } } } return [$operations, $files, $attributes]; } ================================================ FILE: composer.json ================================================ { "name": "nikic/php-parser", "type": "library", "description": "A PHP parser written in PHP", "keywords": [ "php", "parser" ], "license": "BSD-3-Clause", "authors": [ { "name": "Nikita Popov" } ], "require": { "php": ">=7.4", "ext-tokenizer": "*", "ext-json": "*", "ext-ctype": "*" }, "require-dev": { "phpunit/phpunit": "^9.0", "ircmaxell/php-yacc": "^0.0.7" }, "extra": { "branch-alias": { "dev-master": "5.x-dev" } }, "autoload": { "psr-4": { "PhpParser\\": "lib/PhpParser" } }, "autoload-dev": { "psr-4": { "PhpParser\\": "test/PhpParser/" } }, "bin": [ "bin/php-parse" ] } ================================================ FILE: doc/0_Introduction.markdown ================================================ Introduction ============ This project is a PHP parser **written in PHP itself**. What is this for? ----------------- A parser is useful for [static analysis][0], manipulation of code and basically any other application dealing with code programmatically. A parser constructs an [Abstract Syntax Tree][1] (AST) of the code and thus allows dealing with it in an abstract and robust way. There are other ways of processing source code. One that PHP supports natively is using the token stream generated by [`token_get_all`][2]. The token stream is much more low level than the AST and thus has different applications: It allows to also analyze the exact formatting of a file. On the other hand, the token stream is much harder to deal with for more complex analysis. For example, an AST abstracts away the fact that, in PHP, variables can be written as `$foo`, but also as `$$bar`, `${'foobar'}` or even `${!${''}=barfoo()}`. You don't have to worry about recognizing all the different syntaxes from a stream of tokens. Another question is: Why would I want to have a PHP parser *written in PHP*? Well, PHP might not be a language especially suited for fast parsing, but processing the AST is much easier in PHP than it would be in other, faster languages like C. Furthermore the people most likely wanting to do programmatic PHP code analysis are incidentally PHP developers, not C developers. What can it parse? ------------------ The parser supports parsing PHP 7 and PHP 8 code, with the following exceptions: * Namespaced names containing whitespace (e.g. `Foo \ Bar` instead of `Foo\Bar`) are not supported. These are illegal in PHP 8, but are legal in earlier versions. However, PHP-Parser does not support them for any version. PHP-Parser 4.x had full support for parsing PHP 5. PHP-Parser 5.x has only limited support, with the following caveats: * Some variable expressions like `$$foo[0]` are valid in both PHP 5 and PHP 7, but have different interpretation. In such cases, the PHP 7 AST will always be constructed (using `($$foo)[0]` rather than `${$foo[0]}`). * Declarations of the form `global $$var[0]` are not supported in PHP 7 and will cause a parse error. In error recovery mode, it is possible to continue parsing after such declarations. As the parser is based on the tokens returned by `token_get_all` (which is only able to lex the PHP version it runs on), additionally a wrapper for emulating tokens from newer versions is provided. This allows to parse PHP 8.4 source code running on PHP 7.4, for example. This emulation is not perfect, but works well in practice. Finally, it should be noted that the parser aims to accept all valid code, not reject all invalid code. It will generally accept code that is only valid in newer versions (even when targeting an older one), and accept code that is syntactically correct, but would result in a compiler error. What output does it produce? ---------------------------- The parser produces an [Abstract Syntax Tree][1] (AST) also known as a node tree. How this looks can best be seen in an example. The program `createForHostVersion(); // Parser for the newest PHP version supported by the PHP-Parser library. $parser = (new ParserFactory())->createForNewestSupportedVersion(); // Parser for a specific PHP version. $parser = (new ParserFactory())->createForVersion(PhpVersion::fromString('8.1')); ``` Which version you should target depends on your use case. In many cases you will want to use the host version, as people typically analyze code for the version they are running on. However, when analyzing arbitrary code you are usually best off using the newest supported version, which tends to accept the widest range of code (unless there are breaking changes in PHP). The `createXYZ()` methods optionally accept an array of lexer options. Some use cases that require customized lexer options are discussed in the [lexer documentation](component/Lexer.markdown). Subsequently, you can pass PHP code (including the opening `createForHostVersion(); try { $stmts = $parser->parse($code); // $stmts is an array of statement nodes } catch (Error $e) { echo 'Parse Error: ', $e->getMessage(), "\n"; } ``` A parser instance can be reused to parse multiple files. Node dumping ------------ To dump the abstract syntax tree in human-readable form, a `NodeDumper` can be used: ```php dump($stmts), "\n"; ``` For the sample code from the previous section, this will produce the following output: ``` array( 0: Stmt_Function( attrGroups: array( ) byRef: false name: Identifier( name: printLine ) params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: msg ) default: null ) ) returnType: null stmts: array( 0: Stmt_Echo( exprs: array( 0: Expr_Variable( name: msg ) 1: Scalar_String( value: ) ) ) ) ) 1: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: printLine ) args: array( 0: Arg( name: null value: Scalar_String( value: Hello World!!! ) byRef: false unpack: false ) ) ) ) ) ``` You can also use the `php-parse` script to obtain such a node dump by calling it either with a file name or code string: ```sh vendor/bin/php-parse file.php vendor/bin/php-parse " PhpParser\Node\Stmt\Function_` * `Stmt_Expression -> PhpParser\Node\Stmt\Expression` The additional `_` at the end of the first class name is necessary, because `Function` is a reserved keyword. Many node class names in this library have a trailing `_` to avoid clashing with a keyword. As PHP is a large language there are approximately 140 different nodes. In order to make working with them easier they are grouped into three categories: * `PhpParser\Node\Stmt`s are statement nodes, i.e. language constructs that do not return a value and can not occur in an expression. For example a class definition is a statement. It doesn't return a value, and you can't write something like `func(class A {});`. * `PhpParser\Node\Expr`s are expression nodes, i.e. language constructs that return a value and thus can occur in other expressions. Examples of expressions are `$var` (`PhpParser\Node\Expr\Variable`) and `func()` (`PhpParser\Node\Expr\FuncCall`). * `PhpParser\Node\Scalar`s are nodes representing scalar values, like `'string'` (`PhpParser\Node\Scalar\String_`), `0` (`PhpParser\Node\Scalar\LNumber`) or magic constants like `__FILE__` (`PhpParser\Node\Scalar\MagicConst\File`). All `PhpParser\Node\Scalar`s extend `PhpParser\Node\Expr`, as scalars are expressions, too. * There are some nodes not in either of these groups, for example names (`PhpParser\Node\Name`) and call arguments (`PhpParser\Node\Arg`). The `Node\Stmt\Expression` node is somewhat confusing in that it contains both the terms "statement" and "expression". This node distinguishes `expr`, which is a `Node\Expr`, from `expr;`, which is an "expression statement" represented by `Node\Stmt\Expression` and containing `expr` as a sub-node. Every node has a (possibly zero) number of subnodes. You can access subnodes by writing `$node->subNodeName`. The `Stmt\Echo_` node has only one subnode `exprs`. So in order to access it in the above example you would write `$stmts[0]->exprs`. If you wanted to access the name of the function call, you would write `$stmts[0]->exprs[1]->name`. All nodes also define a `getType()` method that returns the node type. The type is the class name without the `PhpParser\Node\` prefix and `\` replaced with `_`. It also does not contain a trailing `_` for reserved-keyword class names. It is possible to associate custom metadata with a node using the `setAttribute()` method. This data can then be retrieved using `hasAttribute()`, `getAttribute()` and `getAttributes()`. By default, the parser adds the `startLine`, `endLine`, `startTokenPos`, `endTokenPos`, `startFilePos`, `endFilePos` and `comments` attributes. `comments` is an array of `PhpParser\Comment[\Doc]` instances. The pre-defined attributes can also be accessed using `getStartLine()` instead of `getAttribute('startLine')`, and so on. The last doc comment from the `comments` attribute can be obtained using `getDocComment()`. Pretty printer -------------- The pretty printer component compiles the AST back to PHP code according to a specified scheme. Currently, there is only one scheme available, namely `PhpParser\PrettyPrinter\Standard`. ```php use PhpParser\Error; use PhpParser\ParserFactory; use PhpParser\PrettyPrinter; $code = "createForHostVersion(); $prettyPrinter = new PrettyPrinter\Standard(); try { // parse $stmts = $parser->parse($code); // change $stmts[0] // the echo statement ->exprs // sub expressions [0] // the first of them (the string node) ->value // it's value, i.e. 'Hi ' = 'Hello '; // change to 'Hello ' // pretty print $code = $prettyPrinter->prettyPrint($stmts); echo $code; } catch (Error $e) { echo 'Parse Error: ', $e->getMessage(), "\n"; } ``` The above code will output: echo 'Hello ', hi\getTarget(); As you can see, the source code was first parsed using `PhpParser\Parser->parse()`, then changed and then again converted to code using `PhpParser\PrettyPrinter\Standard->prettyPrint()`. The `prettyPrint()` method pretty prints a statements array. It is also possible to pretty print only a single expression using `prettyPrintExpr()`. The `prettyPrintFile()` method can be used to print an entire file. This will include the opening ` Read more: [Pretty printing documentation](component/Pretty_printing.markdown) Node traversal -------------- The above pretty printing example used the fact that the source code was known and thus it was easy to write code that accesses a certain part of a node tree and changes it. Normally this is not the case. Usually you want to change / analyze code in a generic way, where you don't know how the node tree is going to look like. For this purpose the parser provides a component for traversing and visiting the node tree. The basic structure of a program using this `PhpParser\NodeTraverser` looks like this: ```php use PhpParser\NodeTraverser; use PhpParser\ParserFactory; use PhpParser\PrettyPrinter; $parser = (new ParserFactory())->createForHostVersion(); $traverser = new NodeTraverser; $prettyPrinter = new PrettyPrinter\Standard; // add your visitor $traverser->addVisitor(new MyNodeVisitor); try { $code = file_get_contents($fileName); // parse $stmts = $parser->parse($code); // traverse $stmts = $traverser->traverse($stmts); // pretty print $code = $prettyPrinter->prettyPrintFile($stmts); echo $code; } catch (PhpParser\Error $e) { echo 'Parse Error: ', $e->getMessage(); } ``` The corresponding node visitor might look like this: ```php use PhpParser\Node; use PhpParser\NodeVisitorAbstract; class MyNodeVisitor extends NodeVisitorAbstract { public function leaveNode(Node $node) { if ($node instanceof Node\Scalar\String_) { $node->value = 'foo'; } } } ``` The above node visitor would change all string literals in the program to `'foo'`. All visitors must implement the `PhpParser\NodeVisitor` interface, which defines the following four methods: ```php public function beforeTraverse(array $nodes); public function enterNode(\PhpParser\Node $node); public function leaveNode(\PhpParser\Node $node); public function afterTraverse(array $nodes); ``` The `beforeTraverse()` method is called once before the traversal begins and is passed the nodes the traverser was called with. This method can be used for resetting values before traversal or preparing the tree for traversal. The `afterTraverse()` method is similar to the `beforeTraverse()` method, with the only difference that it is called once after the traversal. The `enterNode()` and `leaveNode()` methods are called on every node, the former when it is entered, i.e. before its subnodes are traversed, the latter when it is left. All four methods can either return the changed node or not return at all (i.e. `null`) in which case the current node is not changed. The `enterNode()` method can additionally return the value `NodeVisitor::DONT_TRAVERSE_CHILDREN`, which instructs the traverser to skip all children of the current node. To furthermore prevent subsequent visitors from visiting the current node, `NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN` can be used instead. Both methods can additionally return the following values: * `NodeVisitor::STOP_TRAVERSAL`, in which case no further nodes will be visited. * `NodeVisitor::REMOVE_NODE`, in which case the current node will be removed from the parent array. * `NodeVisitor::REPLACE_WITH_NULL`, in which case the current node will be replaced with `null`. * An array of nodes, which will be merged into the parent array at the offset of the current node. I.e. if in `array(A, B, C)` the node `B` should be replaced with `array(X, Y, Z)` the result will be `array(A, X, Y, Z, C)`. Instead of manually implementing the `NodeVisitor` interface you can also extend the `NodeVisitorAbstract` class, which will define empty default implementations for all the above methods. > Read more: [Walking the AST](component/Walking_the_AST.markdown) The NameResolver node visitor ----------------------------- One visitor that is already bundled with the package is `PhpParser\NodeVisitor\NameResolver`. This visitor helps you work with namespaced code by trying to resolve most names to fully qualified ones. For example, consider the following code: use A as B; new B\C(); In order to know that `B\C` really is `A\C` you would need to track aliases and namespaces yourself. The `NameResolver` takes care of that and resolves names as far as possible. After running it, most names will be fully qualified. The only names that will stay unqualified are unqualified function and constant names. These are resolved at runtime and thus the visitor can't know which function they are referring to. In most cases this is a non-issue as the global functions are meant. Additionally, the `NameResolver` adds a `namespacedName` subnode to class, function and constant declarations that contains the namespaced name instead of only the shortname that is available via `name`. > Read more: [Name resolution documentation](component/Name_resolution.markdown) Example: Converting namespaced code to pseudo namespaces -------------------------------------------------------- A small example to understand the concept: We want to convert namespaced code to pseudo namespaces, so it works on 5.2, i.e. names like `A\\B` should be converted to `A_B`. Note that such conversions are fairly complicated if you take PHP's dynamic features into account, so our conversion will assume that no dynamic features are used. We start off with the following base code: ```php use PhpParser\ParserFactory; use PhpParser\PrettyPrinter; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; $inDir = '/some/path'; $outDir = '/some/other/path'; $parser = (new ParserFactory())->createForNewestSupportedVersion(); $traverser = new NodeTraverser; $prettyPrinter = new PrettyPrinter\Standard; $traverser->addVisitor(new NameResolver); // we will need resolved names $traverser->addVisitor(new NamespaceConverter); // our own node visitor // iterate over all .php files in the directory $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($inDir)); $files = new \RegexIterator($files, '/\.php$/'); foreach ($files as $file) { try { // read the file that should be converted $code = file_get_contents($file->getPathName()); // parse $stmts = $parser->parse($code); // traverse $stmts = $traverser->traverse($stmts); // pretty print $code = $prettyPrinter->prettyPrintFile($stmts); // write the converted file to the target directory file_put_contents( substr_replace($file->getPathname(), $outDir, 0, strlen($inDir)), $code ); } catch (PhpParser\Error $e) { echo 'Parse Error: ', $e->getMessage(); } } ``` Now lets start with the main code, the `NamespaceConverter`. One thing it needs to do is convert `A\\B` style names to `A_B` style ones. ```php use PhpParser\Node; class NamespaceConverter extends \PhpParser\NodeVisitorAbstract { public function leaveNode(Node $node) { if ($node instanceof Node\Name) { return new Node\Name(str_replace('\\', '_', $node->toString())); } } } ``` The above code profits from the fact that the `NameResolver` already resolved all names as far as possible, so we don't need to do that. We only need to create a string with the name parts separated by underscores instead of backslashes. This is what `str_replace('\\', '_', $node->toString())` does. (If you want to create a name with backslashes either write `$node->toString()` or `(string) $node`.) Then we create a new name from the string and return it. Returning a new node replaces the old node. Another thing we need to do is change the class/function/const declarations. Currently they contain only the shortname (i.e. the last part of the name), but they need to contain the complete name including the namespace prefix: ```php use PhpParser\Node; use PhpParser\Node\Stmt; class NodeVisitor_NamespaceConverter extends \PhpParser\NodeVisitorAbstract { public function leaveNode(Node $node) { if ($node instanceof Node\Name) { return new Node\Name(str_replace('\\', '_', $node->toString())); } elseif ($node instanceof Stmt\Class_ || $node instanceof Stmt\Interface_ || $node instanceof Stmt\Function_) { $node->name = str_replace('\\', '_', $node->namespacedName->toString()); } elseif ($node instanceof Stmt\Const_) { foreach ($node->consts as $const) { $const->name = str_replace('\\', '_', $const->namespacedName->toString()); } } } } ``` There is not much more to it than converting the namespaced name to string with `_` as separator. The last thing we need to do is remove the `namespace` and `use` statements: ```php use PhpParser\Node; use PhpParser\Node\Stmt; use PhpParser\NodeVisitor; class NodeVisitor_NamespaceConverter extends \PhpParser\NodeVisitorAbstract { public function leaveNode(Node $node) { if ($node instanceof Node\Name) { return new Node\Name(str_replace('\\', '_', $node->toString())); } elseif ($node instanceof Stmt\Class_ || $node instanceof Stmt\Interface_ || $node instanceof Stmt\Function_) { $node->name = str_replace('\\', '_', $node->namespacedName->toString(); } elseif ($node instanceof Stmt\Const_) { foreach ($node->consts as $const) { $const->name = str_replace('\\', '_', $const->namespacedName->toString()); } } elseif ($node instanceof Stmt\Namespace_) { // returning an array merges is into the parent array return $node->stmts; } elseif ($node instanceof Stmt\Use_) { // remove use nodes altogether return NodeVisitor::REMOVE_NODE; } } } ``` That's all. ================================================ FILE: doc/README.md ================================================ Table of Contents ================= Guide ----- 1. [Introduction](0_Introduction.markdown) 2. [Usage of basic components](2_Usage_of_basic_components.markdown) Component documentation ----------------------- * [Walking the AST](component/Walking_the_AST.markdown) * Node visitors * Modifying the AST from a visitor * Short-circuiting traversals * Interleaved visitors * Simple node finding API * Parent and sibling references * [Name resolution](component/Name_resolution.markdown) * Name resolver options * Name resolution context * [Pretty printing](component/Pretty_printing.markdown) * Converting AST back to PHP code * Customizing formatting * Formatting-preserving code transformations * [AST builders](component/AST_builders.markdown) * Fluent builders for AST nodes * [Lexer](component/Lexer.markdown) * Emulation * Tokens, positions and attributes * [Error handling](component/Error_handling.markdown) * Column information for errors * Error recovery (parsing of syntactically incorrect code) * [Constant expression evaluation](component/Constant_expression_evaluation.markdown) * Evaluating constant/property/etc initializers * Handling errors and unsupported expressions * [JSON representation](component/JSON_representation.markdown) * JSON encoding and decoding of ASTs * [Performance](component/Performance.markdown) * Disabling Xdebug * Reusing objects * Garbage collection impact * [Frequently asked questions](component/FAQ.markdown) * Parent and sibling references ================================================ FILE: doc/component/AST_builders.markdown ================================================ AST builders ============ When PHP-Parser is used to generate (or modify) code by first creating an Abstract Syntax Tree and then using the [pretty printer](Pretty_printing.markdown) to convert it to PHP code, it can often be tedious to manually construct AST nodes. The project provides a number of utilities to simplify the construction of common AST nodes. Fluent builders --------------- The library comes with a number of builders, which allow creating node trees using a fluent interface. Builders are created using the `BuilderFactory` and the final constructed node is accessed through `getNode()`. Fluent builders are available for the following syntactic elements: * namespaces and use statements * classes, interfaces, traits and enums * methods, functions and parameters * properties, class constants and enum cases * trait uses and trait use adaptations Here is an example: ```php use PhpParser\BuilderFactory; use PhpParser\PrettyPrinter; use PhpParser\Node; $factory = new BuilderFactory; $node = $factory->namespace('Name\Space') ->addStmt($factory->use('Some\Other\Thingy')->as('SomeClass')) ->addStmt($factory->useFunction('strlen')) ->addStmt($factory->useConst('PHP_VERSION')) ->addStmt($factory->class('SomeOtherClass') ->extend('SomeClass') ->implement('A\Few', '\Interfaces') ->makeAbstract() // ->makeFinal() ->addStmt($factory->useTrait('FirstTrait')) ->addStmt($factory->useTrait('SecondTrait', 'ThirdTrait') ->and('AnotherTrait') ->with($factory->traitUseAdaptation('foo')->as('bar')) ->with($factory->traitUseAdaptation('AnotherTrait', 'baz')->as('test')) ->with($factory->traitUseAdaptation('AnotherTrait', 'func')->insteadof('SecondTrait'))) ->addStmt($factory->method('someMethod') ->makePublic() ->makeAbstract() // ->makeFinal() ->setReturnType('bool') // ->makeReturnByRef() ->addParam($factory->param('someParam')->setType('SomeClass')) ->setDocComment('/** * This method does something. * * @param SomeClass And takes a parameter */') ) ->addStmt($factory->method('anotherMethod') ->makeProtected() // ->makePublic() [default], ->makePrivate() ->addParam($factory->param('someParam')->setDefault('test')) // it is possible to add manually created nodes ->addStmt(new Node\Expr\Print_(new Node\Expr\Variable('someParam'))) ) // properties will be correctly reordered above the methods ->addStmt($factory->property('someProperty')->makeProtected()) ->addStmt($factory->property('anotherProperty')->makePrivate()->setDefault(array(1, 2, 3))) ) ->getNode() ; $stmts = array($node); $prettyPrinter = new PrettyPrinter\Standard(); echo $prettyPrinter->prettyPrintFile($stmts); ``` This will produce the following output with the standard pretty printer: ```php evaluateSilently($someExpr); } catch (ConstExprEvaluationException $e) { // Either the expression contains unsupported expression types, // or an error occurred during evaluation } ``` Error handling -------------- The constant evaluator provides two methods, `evaluateDirectly()` and `evaluateSilently()`, which differ in error behavior. `evaluateDirectly()` will evaluate the expression as PHP would, including any generated warnings or Errors. `evaluateSilently()` will instead convert warnings and Errors into a `ConstExprEvaluationException`. For example: ```php evaluateDirectly($expr)); // float(INF) // Warning: Division by zero try { $evaluator->evaluateSilently($expr); } catch (ConstExprEvaluationException $e) { var_dump($e->getPrevious()->getMessage()); // Division by zero } ``` For the purposes of static analysis, you will likely want to use `evaluateSilently()` and leave erroring expressions unevaluated. Unsupported expressions and evaluator fallback ---------------------------------------------- The constant expression evaluator supports all expression types that are permitted in constant expressions, apart from the following: * `Scalar\MagicConst\*` * `Expr\ConstFetch` (only null/false/true are handled) * `Expr\ClassConstFetch` * `Expr\New_` (since PHP 8.1) * `Expr\PropertyFetch` (since PHP 8.2) Handling these expression types requires non-local information, such as which global constants are defined. By default, the evaluator will throw a `ConstExprEvaluationException` when it encounters an unsupported expression type. It is possible to override this behavior and support resolution for these expression types by specifying an evaluation fallback function: ```php getType()} cannot be evaluated"); }); try { $evaluator->evaluateSilently($someExpr); } catch (ConstExprEvaluationException $e) { // Handle exception } ``` Implementers are advised to ensure that evaluation of indirect constant references cannot lead to infinite recursion. For example, the following code could lead to infinite recursion if constant lookup is implemented naively. ```php hasColumnInfo()`, as the precise location of an error cannot always be determined. The methods for retrieving column information also have to be passed the source code of the parsed file. An example for printing an error: ```php if ($e->hasColumnInfo()) { echo $e->getRawMessage() . ' from ' . $e->getStartLine() . ':' . $e->getStartColumn($code) . ' to ' . $e->getEndLine() . ':' . $e->getEndColumn($code); // or: echo $e->getMessageWithColumnInfo($code); } else { echo $e->getMessage(); } ``` Both line numbers and column numbers are 1-based. EOF errors will be located at the position one past the end of the file. Error recovery -------------- The error behavior of the parser (and other components) is controlled by an `ErrorHandler`. Whenever an error is encountered, `ErrorHandler::handleError()` is invoked. The default error handling strategy is `ErrorHandler\Throwing`, which will immediately throw when an error is encountered. To instead collect all encountered errors into an array, while trying to continue parsing the rest of the source code, an instance of `ErrorHandler\Collecting` can be passed to the `Parser::parse()` method. A usage example: ```php $parser = (new PhpParser\ParserFactory())->createForHostVersion(); $errorHandler = new PhpParser\ErrorHandler\Collecting; $stmts = $parser->parse($code, $errorHandler); if ($errorHandler->hasErrors()) { foreach ($errorHandler->getErrors() as $error) { // $error is an ordinary PhpParser\Error } } if (null !== $stmts) { // $stmts is a best-effort partial AST } ``` The partial AST may contain `Expr\Error` nodes that indicate that an error occurred while parsing an expression. The `NameResolver` visitor also accepts an `ErrorHandler` as a constructor argument. ================================================ FILE: doc/component/FAQ.markdown ================================================ Frequently Asked Questions ========================== * [How can the parent of a node be obtained?](#how-can-the-parent-of-a-node-be-obtained) * [How can the next/previous sibling of a node be obtained?](#how-can-the-nextprevious-sibling-of-a-node-be-obtained) How can the parent of a node be obtained? ----- The AST does not store parent nodes by default. However, the `ParentConnectingVisitor` can be used to achieve this: ```php use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\ParentConnectingVisitor; use PhpParser\ParserFactory; $code = '...'; $traverser = new NodeTraverser(new ParentConnectingVisitor); $parser = (new ParserFactory())->createForHostVersion(); $ast = $parser->parse($code); $ast = $traverser->traverse($ast); ``` After running this visitor, the parent node can be obtained through `$node->getAttribute('parent')`. How can the next/previous sibling of a node be obtained? ----- Again, siblings are not stored by default, but the `NodeConnectingVisitor` can be used to store the previous / next node with a common parent as well: ```php use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NodeConnectingVisitor; use PhpParser\ParserFactory; $code = '...'; $traverser = new NodeTraverser(new NodeConnectingVisitor); $parser = (new ParserFactory())->createForHostVersion(); $ast = $parser->parse($code); $ast = $traverser->traverse($ast); ``` After running this visitor, the parent node can be obtained through `$node->getAttribute('parent')`, the previous node can be obtained through `$node->getAttribute('previous')`, and the next node can be obtained through `$node->getAttribute('next')`. `ParentConnectingVisitor` and `NodeConnectingVisitor` should not be used at the same time. The latter includes the functionality of the former. How can I limit the impact of cyclic references in the AST? ----- NodeConnectingVisitor adds a parent reference, which introduces a cycle. This means that the AST can now only be collected by the cycle garbage collector. This in turn can lead to performance and/or memory issues. To break the cyclic references between AST nodes `NodeConnectingVisitor` supports a boolean `$weakReferences` constructor parameter. When set to `true`, all attributes added by `NodeConnectingVisitor` will be wrapped into a `WeakReference` object. After enabling this parameter, the parent node can be obtained through `$node->getAttribute('weak_parent')`, the previous node can be obtained through `$node->getAttribute('weak_previous')`, and the next node can be obtained through `$node->getAttribute('weak_next')`. ================================================ FILE: doc/component/JSON_representation.markdown ================================================ JSON representation =================== Nodes (and comments) implement the `JsonSerializable` interface. As such, it is possible to JSON encode the AST directly using `json_encode()`: ```php createForHostVersion(); try { $stmts = $parser->parse($code); echo json_encode($stmts, JSON_PRETTY_PRINT), "\n"; } catch (PhpParser\Error $e) { echo 'Parse Error: ', $e->getMessage(); } ``` This will result in the following output (which includes attributes): ```json [ { "nodeType": "Stmt_Function", "attributes": { "startLine": 4, "comments": [ { "nodeType": "Comment_Doc", "text": "\/** @param string $msg *\/", "line": 3, "filePos": 7, "tokenPos": 2, "endLine": 3, "endFilePos": 31, "endTokenPos": 2 } ], "endLine": 6 }, "byRef": false, "name": { "nodeType": "Identifier", "attributes": { "startLine": 4, "endLine": 4 }, "name": "printLine" }, "params": [ { "nodeType": "Param", "attributes": { "startLine": 4, "endLine": 4 }, "type": null, "byRef": false, "variadic": false, "var": { "nodeType": "Expr_Variable", "attributes": { "startLine": 4, "endLine": 4 }, "name": "msg" }, "default": null, "flags": 0, "attrGroups": [] } ], "returnType": null, "stmts": [ { "nodeType": "Stmt_Echo", "attributes": { "startLine": 5, "endLine": 5 }, "exprs": [ { "nodeType": "Expr_Variable", "attributes": { "startLine": 5, "endLine": 5 }, "name": "msg" }, { "nodeType": "Scalar_String", "attributes": { "startLine": 5, "endLine": 5, "kind": 2, "rawValue": "\"\\n\"" }, "value": "\n" } ] } ], "attrGroups": [], "namespacedName": null } ] ``` The JSON representation may be converted back into an AST using the `JsonDecoder`: ```php decode($json); ``` Note that not all ASTs can be represented using JSON. In particular: * JSON only supports UTF-8 strings. * JSON does not support non-finite floating-point numbers. This can occur if the original source code contains non-representable floating-pointing literals such as `1e1000`. If the node tree is not representable in JSON, the initial `json_encode()` call will fail. From the command line, a JSON dump can be obtained using `vendor/bin/php-parse -j file.php`. ================================================ FILE: doc/component/Lexer.markdown ================================================ Lexer component documentation ============================= The lexer is responsible for providing tokens to the parser. Typical use of the library does not require direct interaction with the lexer, as an appropriate lexer is created by `PhpParser\ParserFactory`. The tokens produced by the lexer can then be retrieved using `PhpParser\Parser::getTokens()`. Emulation --------- While this library implements a custom parser, it relies on PHP's `ext/tokenizer` extension to perform lexing. However, this extension only supports lexing code for the PHP version you are running on, while this library also wants to support parsing newer code. For that reason, the lexer performs additional "emulation" in three layers: First, PhpParser uses the `PhpToken` based representation introduced in PHP 8.0, rather than the array-based tokens from previous versions. The `PhpParser\Token` class either extends `PhpToken` (on PHP 8.0) or a polyfill implementation. The polyfill implementation will also perform two emulations that are required by the parser and cannot be disabled: * Single-line comments use the PHP 8.0 representation that does not include a trailing newline. The newline will be part of a following `T_WHITESPACE` token. * Namespaced names use the PHP 8.0 representation using `T_NAME_FULLY_QUALIFIED`, `T_NAME_QUALIFIED` and `T_NAME_RELATIVE` tokens, rather than the previous representation using a sequence of `T_STRING` and `T_NS_SEPARATOR`. This means that certain code that is legal on older versions (namespaced names including whitespace, such as `A \ B`) will not be accepted by the parser. Second, the `PhpParser\Lexer` base class will convert `&` tokens into the PHP 8.1 representation of either `T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG` or `T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG`. This is required by the parser and cannot be disabled. Finally, `PhpParser\Lexer\Emulative` performs other, optional emulations. This lexer is parameterized by `PhpVersion` and will try to emulate `ext/tokenizer` output for that version. This is done using separate `TokenEmulator`s for each emulated feature. Emulation is usually used to support newer PHP versions, but there is also very limited support for reverse emulation to older PHP versions, which can make keywords from newer versions non-reserved. Tokens, positions and attributes -------------------------------- The `Lexer::tokenize()` method returns an array of `PhpParser\Token`s. The most important parts of the interface can be summarized as follows: ```php class Token { /** @var int Token ID, either T_* or ord($char) for single-character tokens. */ public int $id; /** @var string The textual content of the token. */ public string $text; /** @var int The 1-based starting line of the token (or -1 if unknown). */ public int $line; /** @var int The 0-based starting position of the token (or -1 if unknown). */ public int $pos; /** @param int|string|(int|string)[] $kind Token ID or text (or array of them) */ public function is($kind): bool; } ``` Unlike PHP's own `PhpToken::tokenize()` output, the token array is terminated by a sentinel token with ID 0. The lexer is normally invoked implicitly by the parser. In that case, the tokens for the last parse can be retrieved using `Parser::getTokens()`. Nodes in the AST produced by the parser always corresponds to some range of tokens. The parser adds a number of positioning attributes to allow mapping nodes back to lines, tokens or file offsets: * `startLine`: Line in which the node starts. Used by `$node->getStartLine()`. * `endLine`: Line in which the node ends. Used by `$node->getEndLine()`. * `startTokenPos`: Offset into the token array of the first token in the node. Used by `$node->getStartTokenPos()`. * `endTokenPos`: Offset into the token array of the last token in the node. Used by `$node->getEndTokenPos()`. * `startFilePos`: Offset into the code string of the first character that is part of the node. Used by `$node->getStartFilePos()`. * `endFilePos`: Offset into the code string of the last character that is part of the node. Used by `$node->getEndFilePos()`. Note that `start`/`end` here are closed rather than half-open ranges. This means that a node consisting of a single token will have `startTokenPos == endTokenPos` rather than `startTokenPos + 1 == endTokenPos`. This also means that a zero-length node will have `startTokenPos -1 == endTokenPos`. ### Using token positions > **Note:** The example in this section is outdated in that this information is directly available in the AST: While > `$property->isPublic()` does not distinguish between `public` and `var`, directly checking `$property->flags` for > the `$property->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0` allows making this distinction without resorting to > tokens. However, the general idea behind the example still applies in other cases. The token offset information is useful if you wish to examine the exact formatting used for a node. For example the AST does not distinguish whether a property was declared using `public` or using `var`, but you can retrieve this information based on the token position: ```php /** @param PhpParser\Token[] $tokens */ function isDeclaredUsingVar(array $tokens, PhpParser\Node\Stmt\Property $prop) { $i = $prop->getStartTokenPos(); return $tokens[$i]->id === T_VAR; } ``` In order to make use of this function, you will have to provide the tokens from the lexer to your node visitor using code similar to the following: ```php class MyNodeVisitor extends PhpParser\NodeVisitorAbstract { private $tokens; public function setTokens(array $tokens) { $this->tokens = $tokens; } public function leaveNode(PhpParser\Node $node) { if ($node instanceof PhpParser\Node\Stmt\Property) { var_dump(isDeclaredUsingVar($this->tokens, $node)); } } } $parser = (new PhpParser\ParserFactory())->createForHostVersion($lexerOptions); $visitor = new MyNodeVisitor(); $traverser = new PhpParser\NodeTraverser($visitor); try { $stmts = $parser->parse($code); $visitor->setTokens($parser->getTokens()); $stmts = $traverser->traverse($stmts); } catch (PhpParser\Error $e) { echo 'Parse Error: ', $e->getMessage(); } ``` ================================================ FILE: doc/component/Name_resolution.markdown ================================================ Name resolution =============== Since the introduction of namespaces in PHP 5.3, literal names in PHP code are subject to a relatively complex name resolution process, which is based on the current namespace, the current import table state, as well the type of the referenced symbol. PHP-Parser implements name resolution and related functionality, both as reusable logic (NameContext), as well as a node visitor (NameResolver) based on it. The NameResolver visitor ------------------------ The `NameResolver` visitor can (and for nearly all uses of the AST, should) be applied to resolve names to their fully-qualified form, to the degree that this is possible. ```php $nameResolver = new PhpParser\NodeVisitor\NameResolver; $nodeTraverser = new PhpParser\NodeTraverser; $nodeTraverser->addVisitor($nameResolver); // Resolve names $stmts = $nodeTraverser->traverse($stmts); ``` In the default configuration, the name resolver will perform three actions: * Declarations of functions, classes, interfaces, traits, enums and global constants will have a `namespacedName` property added, which contains the function/class/etc name including the namespace prefix. For historic reasons this is a **property** rather than an attribute. * Names will be replaced by fully qualified resolved names, which are instances of `Node\Name\FullyQualified`. * Unqualified function and constant names inside a namespace cannot be statically resolved. Inside a namespace `Foo`, a call to `strlen()` may either refer to the namespaced `\Foo\strlen()`, or the global `\strlen()`. Because PHP-Parser does not have the necessary context to decide this, such names are left unresolved. Additionally, a `namespacedName` **attribute** is added to the name node. The name resolver accepts an option array as the second argument, with the following default values: ```php $nameResolver = new PhpParser\NodeVisitor\NameResolver(null, [ 'preserveOriginalNames' => false, 'replaceNodes' => true, ]); ``` If the `preserveOriginalNames` option is enabled, then the resolved (fully qualified) name will have an `originalName` attribute, which contains the unresolved name. If the `replaceNodes` option is disabled, then names will no longer be resolved in-place. Instead, a `resolvedName` attribute will be added to each name, which contains the resolved (fully qualified) name. Once again, if an unqualified function or constant name cannot be resolved, then the `resolvedName` attribute will not be present, and instead a `namespacedName` attribute is added. The `replaceNodes` attribute is useful if you wish to perform modifications on the AST, as you probably do not wish the resulting code to have fully resolved names as a side-effect. The NameContext --------------- The actual name resolution logic is implemented in the `NameContext` class, which has the following public API: ```php class NameContext { public function __construct(ErrorHandler $errorHandler); public function startNamespace(Name $namespace = null); public function addAlias(Name $name, string $aliasName, int $type, array $errorAttrs = []); public function getNamespace(); public function getResolvedName(Name $name, int $type); public function getResolvedClassName(Name $name) : Name; public function getPossibleNames(string $name, int $type) : array; public function getShortName(string $name, int $type) : Name; } ``` The `$type` parameters accept one of the `Stmt\Use_::TYPE_*` constants, which represent the three basic symbol types in PHP (functions, constants and everything else). Next to name resolution, the `NameContext` also supports the reverse operation of finding a short representation of a name given the current name resolution environment. The name context is intended to be used for name resolution operations outside the AST itself, such as class names inside doc comments. A visitor running in parallel with the name resolver can access the name context using `$nameResolver->getNameContext()`. Alternatively a visitor can use an independent context and explicitly feed `Namespace` and `Use` nodes to it. ================================================ FILE: doc/component/Performance.markdown ================================================ Performance =========== Parsing is computationally expensive task, to which the PHP language is not very well suited. Nonetheless, there are a few things you can do to improve the performance of this library, which are described in the following. Xdebug ------ Running PHP with Xdebug adds a lot of overhead, especially for code that performs many method calls. Just by loading Xdebug (without enabling profiling or other more intrusive Xdebug features), you can expect that code using PHP-Parser will be approximately *five times slower*. As such, you should make sure that Xdebug is not loaded when using this library. Note that setting the `xdebug.default_enable=0` ini option does *not* disable Xdebug. The *only* way to disable Xdebug is to not load the extension in the first place. If you are building a command-line utility for use by developers (who often have Xdebug enabled), you may want to consider automatically restarting PHP with Xdebug unloaded. The [composer/xdebug-handler](https://github.com/composer/xdebug-handler) package can be used to do this. If you do run with Xdebug, you may need to increase the `xdebug.max_nesting_level` option to a higher level, such as 3000. While the parser itself is recursion free, most other code working on the AST uses recursion and will generate an error if the value of this option is too low. Assertions ---------- Assertions should be disabled in a production context by setting `zend.assertions=-1` (or `zend.assertions=0` if set at runtime). The library currently doesn't make heavy use of assertions, but they are used in an increasing number of places. Object reuse ------------ Many objects in this project are designed for reuse. For example, one `Parser` object can be used to parse multiple files. When possible, objects should be reused rather than being newly instantiated for every use. Some objects have expensive initialization procedures, which will be unnecessarily repeated if the object is not reused. (Currently two objects with particularly expensive setup are parsers and pretty printers, though the details might change between versions of this library.) ================================================ FILE: doc/component/Pretty_printing.markdown ================================================ Pretty printing =============== Pretty printing is the process of converting a syntax tree back to PHP code. In its basic mode of operation the pretty printer provided by this library will print the AST using a certain predefined code style and will discard (nearly) all formatting of the original code. Because programmers tend to be rather picky about their code formatting, this mode of operation is not very suitable for refactoring code, but can be used for automatically generated code, which is usually only read for debugging purposes. Basic usage ----------- ```php $stmts = $parser->parse($code); // MODIFY $stmts here $prettyPrinter = new PhpParser\PrettyPrinter\Standard; $newCode = $prettyPrinter->prettyPrintFile($stmts); ``` The pretty printer has three basic printing methods: `prettyPrint()`, `prettyPrintFile()` and `prettyPrintExpr()`. The one that is most commonly useful is `prettyPrintFile()`, which takes an array of statements and produces a full PHP file, including opening `` or not. Additionally, the pretty printer supports three options: * `phpVersion` (defaults to 7.4) allows opting into formatting that is not supported by older PHP versions. * `newline` (defaults to `"\n"`) can be set to `"\r\n"` in order to produce Windows newlines. * `indent` (defaults to four spaces `" "`) can be set to any number of spaces or a single tab. * `shortArraySyntax` determines the used array syntax if the `kind` attribute is not set. This is a legacy option, and `phpVersion` should be used to control this behavior instead. The behaviors controlled by `phpVersion` (defaults to PHP 7.4) are: * For PHP >= 7.0, short array syntax `[]` will be used by default. This does not affect nodes that specify an explicit array syntax using the `kind` attribute. * For PHP >= 7.0, parentheses around `yield` expressions will only be printed when necessary. * For PHP >= 7.1, the short array syntax `[]` will be used for destructuring by default (instead of `list()`). This does not affect nodes that specify and explicit syntax using the `kind` attribute. * For PHP >= 7.3, a newline is no longer forced after heredoc/nowdoc strings, as the requirement for this has been removed with the introduction of flexible heredoc/nowdoc strings. * For PHP >= 7.3, heredoc/nowdoc strings are indented just like regular code. This was allowed with the introduction of flexible heredoc/nowdoc strings. The default pretty printer does not provide functionality for fine-grained customization of code formatting. If you want to make minor changes to the formatting, the easiest way is to extend the pretty printer and override the methods responsible for the node types you are interested in. If you want to have more fine-grained formatting control, the recommended method is to combine the default pretty printer with an existing library for code reformatting, such as [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer). Formatting-preserving pretty printing ------------------------------------- For automated code refactoring, migration and similar, you will usually only want to modify a small portion of the code and leave the remainder alone. The basic pretty printer is not suitable for this, because it will also reformat parts of the code which have not been modified. Since PHP-Parser 4.0, a formatting-preserving pretty-printing mode is available, which attempts to preserve the formatting of code (those AST nodes that have not changed) and only reformat code which has been modified or newly inserted. Use of the formatting-preservation functionality requires some additional preparatory steps: ```php use PhpParser\{NodeTraverser, NodeVisitor, ParserFactory, PrettyPrinter}; $parser = (new ParserFactory())->createForHostVersion(); $oldStmts = $parser->parse($code); $oldTokens = $parser->getTokens(); // Run CloningVisitor before making changes to the AST. $traverser = new NodeTraverser(new NodeVisitor\CloningVisitor()); $newStmts = $traverser->traverse($oldStmts); // MODIFY $newStmts HERE $printer = new PrettyPrinter\Standard(); $newCode = $printer->printFormatPreserving($newStmts, $oldStmts, $oldTokens); ``` If you make use of the name resolution functionality, you will likely want to disable the `replaceNodes` option. This will add resolved names as attributes, instead of directly modifying the AST and causing spurious changes to the pretty printed code. For more information, see the [name resolution documentation](Name_resolution.markdown). The formatting-preservation works on a best-effort basis and may sometimes reformat more code than necessary. If you encounter problems while using this functionality, please open an issue. ================================================ FILE: doc/component/Walking_the_AST.markdown ================================================ Walking the AST =============== The most common way to work with the AST is by using a node traverser and one or more node visitors. As a basic example, the following code changes all literal integers in the AST into strings (e.g., `42` becomes `'42'`.) ```php use PhpParser\{Node, NodeTraverser, NodeVisitorAbstract}; $traverser = new NodeTraverser; $traverser->addVisitor(new class extends NodeVisitorAbstract { public function leaveNode(Node $node) { if ($node instanceof Node\Scalar\Int_) { return new Node\Scalar\String_((string) $node->value); } } }); $stmts = ...; $modifiedStmts = $traverser->traverse($stmts); ``` Visitors can be either passed to the `NodeTraverser` constructor, or added using `addVisitor()`: ```php $traverser = new NodeTraverser($visitor1, $visitor2, $visitor3); // Equivalent to: $traverser = new NodeTraverser(); $traverser->addVisitor($visitor1); $traverser->addVisitor($visitor2); $traverser->addVisitor($visitor3); ``` Node visitors ------------- Each node visitor implements an interface with following four methods: ```php interface NodeVisitor { public function beforeTraverse(array $nodes); public function enterNode(Node $node); public function leaveNode(Node $node); public function afterTraverse(array $nodes); } ``` The `beforeTraverse()` and `afterTraverse()` methods are called before and after the traversal respectively, and are passed the entire AST. They can be used to perform any necessary state setup or cleanup. The `enterNode()` method is called when a node is first encountered, before its children are processed ("preorder"). The `leaveNode()` method is called after all children have been visited ("postorder"). For example, if we have the following excerpt of an AST ``` Expr_FuncCall( name: Name( name: printLine ) args: array( 0: Arg( name: null value: Scalar_String( value: Hello World!!! ) byRef: false unpack: false ) ) ) ``` then the enter/leave methods will be called in the following order: ``` enterNode(Expr_FuncCall) enterNode(Name) leaveNode(Name) enterNode(Arg) enterNode(Scalar_String) leaveNode(Scalar_String) leaveNode(Arg) leaveNode(Expr_FuncCall) ``` A common pattern is that `enterNode` is used to collect some information and then `leaveNode` performs modifications based on that. At the time when `leaveNode` is called, all the code inside the node will have already been visited and necessary information collected. As you usually do not want to implement all four methods, it is recommended that you extend `NodeVisitorAbstract` instead of implementing the interface directly. The abstract class provides empty default implementations. Modifying the AST ----------------- There are a number of ways in which the AST can be modified from inside a node visitor. The first and simplest is to simply change AST properties inside the visitor: ```php public function leaveNode(Node $node) { if ($node instanceof Node\Scalar\LNumber) { // increment all integer literals $node->value++; } } ``` The second is to replace a node entirely by returning a new node: ```php public function leaveNode(Node $node) { if ($node instanceof Node\Expr\BinaryOp\BooleanAnd) { // Convert all $a && $b expressions into !($a && $b) return new Node\Expr\BooleanNot($node); } } ``` Doing this is supported both inside enterNode and leaveNode. However, you have to be mindful about where you perform the replacement: If a node is replaced in enterNode, then the recursive traversal will also consider the children of the new node. If you aren't careful, this can lead to infinite recursion. For example, let's take the previous code sample and use enterNode instead: ```php public function enterNode(Node $node) { if ($node instanceof Node\Expr\BinaryOp\BooleanAnd) { // Convert all $a && $b expressions into !($a && $b) return new Node\Expr\BooleanNot($node); } } ``` Now `$a && $b` will be replaced by `!($a && $b)`. Then the traverser will go into the first (and only) child of `!($a && $b)`, which is `$a && $b`. The transformation applies again and we end up with `!!($a && $b)`. This will continue until PHP hits the memory limit. Finally, there are three special replacement types. The first is removal of a node: ```php public function leaveNode(Node $node) { if ($node instanceof Node\Stmt\Return_) { // Remove all return statements return NodeVisitor::REMOVE_NODE; } } ``` Node removal only works if the parent structure is an array. This means that usually it only makes sense to remove nodes of type `Node\Stmt`, as they always occur inside statement lists (and a few more node types like `Arg` or `Expr\ArrayItem`, which are also always part of lists). On the other hand, removing a `Node\Expr` does not make sense: If you have `$a * $b`, there is no meaningful way in which the `$a` part could be removed. If you want to remove an expression, you generally want to remove it together with a surrounding expression statement: ```php public function leaveNode(Node $node) { if ($node instanceof Node\Stmt\Expression && $node->expr instanceof Node\Expr\FuncCall && $node->expr->name instanceof Node\Name && $node->expr->name->toString() === 'var_dump' ) { return NodeVisitor::REMOVE_NODE; } } ``` This example will remove all calls to `var_dump()` which occur as expression statements. This means that `var_dump($a);` will be removed, but `if (var_dump($a))` will not be removed (and there is no obvious way in which it can be removed). Another way to remove nodes is to replace them with `null`. For example, all `else` statements could be removed as follows: ```php public function leaveNode(Node $node) { if ($node instanceof Node\Stmt\Else_) { return NodeVisitor::REPLACE_WITH_NULL; } } ``` This is only safe to do if the subnode the node is stored in is nullable. `Node\Stmt\Else_` only occurs inside `Node\Stmt\If_::$else`, which is nullable, so this particular replacement is safe. Next to removing nodes, it is also possible to replace one node with multiple nodes. This only works if the parent structure is an array. ```php public function leaveNode(Node $node) { if ($node instanceof Node\Stmt\Return_ && $node->expr !== null) { // Convert "return foo();" into "$retval = foo(); return $retval;" $var = new Node\Expr\Variable('retval'); return [ new Node\Stmt\Expression(new Node\Expr\Assign($var, $node->expr)), new Node\Stmt\Return_($var), ]; } } ``` Short-circuiting traversal -------------------------- An AST can easily contain thousands of nodes, and traversing over all of them may be slow, especially if you have more than one visitor. In some cases, it is possible to avoid a full traversal. If you are looking for all class declarations in a file (and assuming you're not interested in anonymous classes), you know that once you've seen a class declaration, there is no point in also checking all it's child nodes, because PHP does not allow nesting classes. In this case, you can instruct the traverser to not recurse into the class node: ```php private $classes = []; public function enterNode(Node $node) { if ($node instanceof Node\Stmt\Class_) { $this->classes[] = $node; return NodeVisitor::DONT_TRAVERSE_CHILDREN; } } ``` Of course, this option is only available in enterNode, because it's already too late by the time leaveNode is reached. If you are only looking for one specific node, it is also possible to abort the traversal entirely after finding it. For example, if you are looking for the node of a class with a certain name (and discounting exotic cases like conditionally defining a class two times), you can stop traversal once you found it: ```php private $class = null; public function enterNode(Node $node) { if ($node instanceof Node\Stmt\Class_ && $node->namespacedName->toString() === 'Foo\Bar\Baz' ) { $this->class = $node; return NodeVisitor::STOP_TRAVERSAL; } } ``` This works both in enterNode and leaveNode. Note that this particular case can also be more easily handled using a NodeFinder, which will be introduced below. Multiple visitors ----------------- A single traverser can be used with multiple visitors: ```php $traverser = new NodeTraverser; $traverser->addVisitor($visitorA); $traverser->addVisitor($visitorB); $stmts = $traverser->traverse($stmts); ``` It is important to understand that if a traverser is run with multiple visitors, the visitors will be interleaved. Given the following AST excerpt ``` Stmt_Return( expr: Expr_Variable( name: foobar ) ) ``` the following method calls will be performed: ```php $visitorA->enterNode(Stmt_Return) $visitorB->enterNode(Stmt_Return) $visitorA->enterNode(Expr_Variable) $visitorB->enterNode(Expr_Variable) $visitorB->leaveNode(Expr_Variable) $visitorA->leaveNode(Expr_Variable) $visitorB->leaveNode(Stmt_Return) $visitorA->leaveNode(Stmt_Return) ``` That is, when visiting a node, `enterNode()` and `leaveNode()` will always be called for all visitors, with the `leaveNode()` calls happening in the reverse order of the `enterNode()` calls. Running multiple visitors in parallel improves performance, as the AST only has to be traversed once. However, it is not always possible to write visitors in a way that allows interleaved execution. In this case, you can always fall back to performing multiple traversals: ```php $traverserA = new NodeTraverser; $traverserA->addVisitor($visitorA); $traverserB = new NodeTraverser; $traverserB->addVisitor($visitorB); $stmts = $traverserA->traverser($stmts); $stmts = $traverserB->traverser($stmts); ``` When using multiple visitors, it is important to understand how they interact with the various special enterNode/leaveNode return values: * If *any* visitor returns `DONT_TRAVERSE_CHILDREN`, the children will be skipped for *all* visitors. * If *any* visitor returns `DONT_TRAVERSE_CURRENT_AND_CHILDREN`, the children will be skipped for *all* visitors, and all *subsequent* visitors will not visit the current node. * If *any* visitor returns `STOP_TRAVERSAL`, traversal is stopped for *all* visitors. * If a visitor returns a replacement node, subsequent visitors will be passed the replacement node, not the original one. * If a visitor returns `REMOVE_NODE`, subsequent visitors will not see this node. * If a visitor returns `REPLACE_WITH_NULL`, subsequent visitors will not see this node. * If a visitor returns an array of replacement nodes, subsequent visitors will see neither the node that was replaced, nor the replacement nodes. Simple node finding ------------------- While the node visitor mechanism is very flexible, creating a node visitor can be overly cumbersome for minor tasks. For this reason a `NodeFinder` is provided, which can find AST nodes that either satisfy a certain callback, or which are instances of a certain node type. A couple of examples are shown in the following: ```php use PhpParser\{Node, NodeFinder}; $nodeFinder = new NodeFinder; // Find all class nodes. $classes = $nodeFinder->findInstanceOf($stmts, Node\Stmt\Class_::class); // Find all classes that extend another class $extendingClasses = $nodeFinder->find($stmts, function(Node $node) { return $node instanceof Node\Stmt\Class_ && $node->extends !== null; }); // Find first class occurring in the AST. Returns null if no class exists. $class = $nodeFinder->findFirstInstanceOf($stmts, Node\Stmt\Class_::class); // Find first class that has name $name $class = $nodeFinder->findFirst($stmts, function(Node $node) use ($name) { return $node instanceof Node\Stmt\Class_ && $node->resolvedName->toString() === $name; }); ``` Internally, the `NodeFinder` also uses a node traverser. It only simplifies the interface for a common use case. Parent and sibling references ----------------------------- The node visitor mechanism is somewhat rigid, in that it prescribes an order in which nodes should be accessed: From parents to children. However, it can often be convenient to operate in the reverse direction: When working on a node, you might want to check if the parent node satisfies a certain property. PHP-Parser does not add parent (or sibling) references to nodes by default, but you can enable them using the `ParentConnectingVisitor` or `NodeConnectingVisitor`. See the [FAQ](FAQ.markdown) for more information. ================================================ FILE: grammar/README.md ================================================ What do all those files mean? ============================= * `php.y`: PHP 5-8 grammar written in a pseudo language * `parser.template`: A `kmyacc` parser prototype file for PHP * `rebuildParsers.php`: Preprocesses the grammar and builds the parser using `kmyacc` .phpy pseudo language ===================== The `.y` file is a normal grammar in `kmyacc` (`yacc`) style, with some transformations applied to it: * Nodes are created using the syntax `Name[..., ...]`. This is transformed into `new Name(..., ..., attributes())` * Some function-like constructs are resolved (see `rebuildParsers.php` for a list) Building the parser =================== Run `php grammar/rebuildParsers.php` to rebuild the parsers. Additional options: * The `KMYACC` environment variable can be used to specify an alternative `kmyacc` binary. By default the `phpyacc` dev dependency will be used. To use the original `kmyacc`, you need to compile [moriyoshi's fork](https://github.com/moriyoshi/kmyacc-forked). * The `--debug` option enables emission of debug symbols and creates the `y.output` file. * The `--keep-tmp-grammar` option preserves the preprocessed grammar file. ================================================ FILE: grammar/parser.template ================================================ semValue #semval($,%t) $self->semValue #semval(%n) $stackPos-(%l-%n) #semval(%n,%t) $stackPos-(%l-%n) namespace PhpParser\Parser; use PhpParser\Error; use PhpParser\Modifiers; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Name; use PhpParser\Node\Scalar; use PhpParser\Node\Stmt; #include; /* This is an automatically GENERATED file, which should not be manually edited. * Instead edit one of the following: * * the grammar file grammar/php.y * * the skeleton file grammar/parser.template * * the preprocessing script grammar/rebuildParsers.php */ class #(-p) extends \PhpParser\ParserAbstract { #tokenval public const %s = %n; #endtokenval protected int $tokenToSymbolMapSize = #(YYMAXLEX); protected int $actionTableSize = #(YYLAST); protected int $gotoTableSize = #(YYGLAST); protected int $invalidSymbol = #(YYBADCH); protected int $errorSymbol = #(YYINTERRTOK); protected int $defaultAction = #(YYDEFAULT); protected int $unexpectedTokenRule = #(YYUNEXPECTED); protected int $YY2TBLSTATE = #(YY2TBLSTATE); protected int $numNonLeafStates = #(YYNLSTATES); protected array $symbolToName = array( #listvar terminals ); protected array $tokenToSymbol = array( #listvar yytranslate ); protected array $action = array( #listvar yyaction ); protected array $actionCheck = array( #listvar yycheck ); protected array $actionBase = array( #listvar yybase ); protected array $actionDefault = array( #listvar yydefault ); protected array $goto = array( #listvar yygoto ); protected array $gotoCheck = array( #listvar yygcheck ); protected array $gotoBase = array( #listvar yygbase ); protected array $gotoDefault = array( #listvar yygdefault ); protected array $ruleToNonTerminal = array( #listvar yylhs ); protected array $ruleToLength = array( #listvar yylen ); #if -t protected array $productions = array( #production-strings; ); #endif protected function initReduceCallbacks(): void { $this->reduceCallbacks = [ #reduce %n => static function ($self, $stackPos) { %b }, #noact %n => null, #endreduce ]; } } #tailcode; ================================================ FILE: grammar/php.y ================================================ %pure_parser %expect 2 %right T_VOID_CAST %right T_THROW %left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE %left ',' %left T_LOGICAL_OR %left T_LOGICAL_XOR %left T_LOGICAL_AND %right T_PRINT %right T_YIELD %right T_DOUBLE_ARROW %right T_YIELD_FROM %left '=' T_PLUS_EQUAL T_MINUS_EQUAL T_MUL_EQUAL T_DIV_EQUAL T_CONCAT_EQUAL T_MOD_EQUAL T_AND_EQUAL T_OR_EQUAL T_XOR_EQUAL T_SL_EQUAL T_SR_EQUAL T_POW_EQUAL T_COALESCE_EQUAL %left '?' ':' %right T_COALESCE %left T_BOOLEAN_OR %left T_BOOLEAN_AND %left '|' %left '^' %left T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG %nonassoc T_IS_EQUAL T_IS_NOT_EQUAL T_IS_IDENTICAL T_IS_NOT_IDENTICAL T_SPACESHIP %nonassoc '<' T_IS_SMALLER_OR_EQUAL '>' T_IS_GREATER_OR_EQUAL #if PHP7 %left T_SL T_SR %left '+' '-' '.' #endif #if PHP8 %left T_PIPE %left '.' %left T_SL T_SR %left '+' '-' #endif %left '*' '/' '%' %right '!' %nonassoc T_INSTANCEOF %right '~' T_INC T_DEC T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@' %right T_POW %right '[' %nonassoc T_NEW T_CLONE %token T_EXIT %token T_IF %left T_ELSEIF %left T_ELSE %left T_ENDIF %token T_LNUMBER %token T_DNUMBER %token T_STRING %token T_STRING_VARNAME %token T_VARIABLE %token T_NUM_STRING %token T_INLINE_HTML %token T_ENCAPSED_AND_WHITESPACE %token T_CONSTANT_ENCAPSED_STRING %token T_ECHO %token T_DO %token T_WHILE %token T_ENDWHILE %token T_FOR %token T_ENDFOR %token T_FOREACH %token T_ENDFOREACH %token T_DECLARE %token T_ENDDECLARE %token T_AS %token T_SWITCH %token T_MATCH %token T_ENDSWITCH %token T_CASE %token T_DEFAULT %token T_BREAK %token T_CONTINUE %token T_GOTO %token T_FUNCTION %token T_FN %token T_CONST %token T_RETURN %token T_TRY %token T_CATCH %token T_FINALLY %token T_THROW %token T_USE %token T_INSTEADOF %token T_GLOBAL %token T_STATIC T_ABSTRACT T_FINAL T_PRIVATE T_PROTECTED T_PUBLIC T_READONLY %token T_PUBLIC_SET %token T_PROTECTED_SET %token T_PRIVATE_SET %token T_VAR %token T_UNSET %token T_ISSET %token T_EMPTY %token T_HALT_COMPILER %token T_CLASS %token T_TRAIT %token T_INTERFACE %token T_ENUM %token T_EXTENDS %token T_IMPLEMENTS %token T_OBJECT_OPERATOR %token T_NULLSAFE_OBJECT_OPERATOR %token T_DOUBLE_ARROW %token T_LIST %token T_ARRAY %token T_CALLABLE %token T_CLASS_C %token T_TRAIT_C %token T_METHOD_C %token T_FUNC_C %token T_PROPERTY_C %token T_LINE %token T_FILE %token T_START_HEREDOC %token T_END_HEREDOC %token T_DOLLAR_OPEN_CURLY_BRACES %token T_CURLY_OPEN %token T_PAAMAYIM_NEKUDOTAYIM %token T_NAMESPACE %token T_NS_C %token T_DIR %token T_NS_SEPARATOR %token T_ELLIPSIS %token T_NAME_FULLY_QUALIFIED %token T_NAME_QUALIFIED %token T_NAME_RELATIVE %token T_ATTRIBUTE %token T_ENUM %% start: top_statement_list { $$ = $this->handleNamespaces($1); } ; top_statement_list_ex: top_statement_list_ex top_statement { pushNormalizing($1, $2); } | /* empty */ { init(); } ; top_statement_list: top_statement_list_ex { makeZeroLengthNop($nop); if ($nop !== null) { $1[] = $nop; } $$ = $1; } ; ampersand: T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG | T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG ; reserved_non_modifiers: T_INCLUDE | T_INCLUDE_ONCE | T_EVAL | T_REQUIRE | T_REQUIRE_ONCE | T_LOGICAL_OR | T_LOGICAL_XOR | T_LOGICAL_AND | T_INSTANCEOF | T_NEW | T_CLONE | T_EXIT | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_DO | T_WHILE | T_ENDWHILE | T_FOR | T_ENDFOR | T_FOREACH | T_ENDFOREACH | T_DECLARE | T_ENDDECLARE | T_AS | T_TRY | T_CATCH | T_FINALLY | T_THROW | T_USE | T_INSTEADOF | T_GLOBAL | T_VAR | T_UNSET | T_ISSET | T_EMPTY | T_CONTINUE | T_GOTO | T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT | T_BREAK | T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS | T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_FN | T_MATCH | T_ENUM | T_ECHO { $$ = $1; if ($$ === "emitError(new Error('Cannot use "emitError(new Error('A trailing comma is not allowed here', attributes())); } ; optional_comma: /* empty */ | ',' ; attribute_decl: class_name { $$ = Node\Attribute[$1, []]; } | class_name argument_list { $$ = Node\Attribute[$1, $2]; } ; attribute_group: attribute_decl { init($1); } | attribute_group ',' attribute_decl { push($1, $3); } ; attribute: T_ATTRIBUTE attribute_group optional_comma ']' { $$ = Node\AttributeGroup[$2]; } ; attributes: attribute { init($1); } | attributes attribute { push($1, $2); } ; optional_attributes: /* empty */ { $$ = []; } | attributes ; top_statement: statement | function_declaration_statement | class_declaration_statement | T_HALT_COMPILER '(' ')' ';' { $$ = Stmt\HaltCompiler[$this->handleHaltCompiler()]; } | T_NAMESPACE namespace_declaration_name semi { $$ = Stmt\Namespace_[$2, null]; $$->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON); $this->checkNamespace($$); } | T_NAMESPACE namespace_declaration_name '{' top_statement_list '}' { $$ = Stmt\Namespace_[$2, $4]; $$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); $this->checkNamespace($$); } | T_NAMESPACE '{' top_statement_list '}' { $$ = Stmt\Namespace_[null, $3]; $$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); $this->checkNamespace($$); } | T_USE use_declarations semi { $$ = Stmt\Use_[$2, Stmt\Use_::TYPE_NORMAL]; } | T_USE use_type use_declarations semi { $$ = Stmt\Use_[$3, $2]; } | group_use_declaration | T_CONST constant_declaration_list semi { $$ = new Stmt\Const_($2, attributes(), []); } | attributes T_CONST constant_declaration_list semi { $$ = new Stmt\Const_($3, attributes(), $1); $this->checkConstantAttributes($$); } ; use_type: T_FUNCTION { $$ = Stmt\Use_::TYPE_FUNCTION; } | T_CONST { $$ = Stmt\Use_::TYPE_CONSTANT; } ; group_use_declaration: T_USE use_type legacy_namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}' semi { $$ = Stmt\GroupUse[$3, $6, $2]; } | T_USE legacy_namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}' semi { $$ = Stmt\GroupUse[$2, $5, Stmt\Use_::TYPE_UNKNOWN]; } ; unprefixed_use_declarations: non_empty_unprefixed_use_declarations optional_comma ; non_empty_unprefixed_use_declarations: non_empty_unprefixed_use_declarations ',' unprefixed_use_declaration { push($1, $3); } | unprefixed_use_declaration { init($1); } ; use_declarations: non_empty_use_declarations no_comma ; non_empty_use_declarations: non_empty_use_declarations ',' use_declaration { push($1, $3); } | use_declaration { init($1); } ; inline_use_declarations: non_empty_inline_use_declarations optional_comma ; non_empty_inline_use_declarations: non_empty_inline_use_declarations ',' inline_use_declaration { push($1, $3); } | inline_use_declaration { init($1); } ; unprefixed_use_declaration: namespace_name { $$ = Node\UseItem[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); } | namespace_name T_AS identifier_not_reserved { $$ = Node\UseItem[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); } ; use_declaration: legacy_namespace_name { $$ = Node\UseItem[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); } | legacy_namespace_name T_AS identifier_not_reserved { $$ = Node\UseItem[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); } ; inline_use_declaration: unprefixed_use_declaration { $$ = $1; $$->type = Stmt\Use_::TYPE_NORMAL; } | use_type unprefixed_use_declaration { $$ = $2; $$->type = $1; } ; constant_declaration_list: non_empty_constant_declaration_list no_comma ; non_empty_constant_declaration_list: non_empty_constant_declaration_list ',' constant_declaration { push($1, $3); } | constant_declaration { init($1); } ; constant_declaration: identifier_not_reserved '=' expr { $$ = Node\Const_[$1, $3]; } ; class_const_list: non_empty_class_const_list no_comma ; non_empty_class_const_list: non_empty_class_const_list ',' class_const { push($1, $3); } | class_const { init($1); } ; class_const: T_STRING '=' expr { $$ = Node\Const_[new Node\Identifier($1, stackAttributes(#1)), $3]; } | semi_reserved '=' expr { $$ = Node\Const_[new Node\Identifier($1, stackAttributes(#1)), $3]; } ; inner_statement_list_ex: inner_statement_list_ex inner_statement { pushNormalizing($1, $2); } | /* empty */ { init(); } ; inner_statement_list: inner_statement_list_ex { makeZeroLengthNop($nop); if ($nop !== null) { $1[] = $nop; } $$ = $1; } ; inner_statement: statement | function_declaration_statement | class_declaration_statement | T_HALT_COMPILER { throw new Error('__HALT_COMPILER() can only be used from the outermost scope', attributes()); } ; non_empty_statement: '{' inner_statement_list '}' { $$ = Stmt\Block[$2]; } | T_IF '(' expr ')' blocklike_statement elseif_list else_single { $$ = Stmt\If_[$3, ['stmts' => $5, 'elseifs' => $6, 'else' => $7]]; } | T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';' { $$ = Stmt\If_[$3, ['stmts' => $6, 'elseifs' => $7, 'else' => $8]]; } | T_WHILE '(' expr ')' while_statement { $$ = Stmt\While_[$3, $5]; } | T_DO blocklike_statement T_WHILE '(' expr ')' ';' { $$ = Stmt\Do_ [$5, $2]; } | T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement { $$ = Stmt\For_[['init' => $3, 'cond' => $5, 'loop' => $7, 'stmts' => $9]]; } | T_SWITCH '(' expr ')' switch_case_list { $$ = Stmt\Switch_[$3, $5]; } | T_BREAK optional_expr semi { $$ = Stmt\Break_[$2]; } | T_CONTINUE optional_expr semi { $$ = Stmt\Continue_[$2]; } | T_RETURN optional_expr semi { $$ = Stmt\Return_[$2]; } | T_GLOBAL global_var_list semi { $$ = Stmt\Global_[$2]; } | T_STATIC static_var_list semi { $$ = Stmt\Static_[$2]; } | T_ECHO expr_list_forbid_comma semi { $$ = Stmt\Echo_[$2]; } | T_INLINE_HTML { $$ = Stmt\InlineHTML[$1]; $$->setAttribute('hasLeadingNewline', $this->inlineHtmlHasLeadingNewline(#1)); } | expr semi { $$ = Stmt\Expression[$1]; } | T_UNSET '(' variables_list ')' semi { $$ = Stmt\Unset_[$3]; } | T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement { $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; } | T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW foreach_variable ')' foreach_statement { $$ = Stmt\Foreach_[$3, $7[0], ['keyVar' => $5, 'byRef' => $7[1], 'stmts' => $9]]; } | T_FOREACH '(' expr error ')' foreach_statement { $$ = Stmt\Foreach_[$3, new Expr\Error(stackAttributes(#4)), ['stmts' => $6]]; } | T_DECLARE '(' declare_list ')' declare_statement { $$ = Stmt\Declare_[$3, $5]; } | T_TRY '{' inner_statement_list '}' catches optional_finally { $$ = Stmt\TryCatch[$3, $5, $6]; $this->checkTryCatch($$); } | T_GOTO identifier_not_reserved semi { $$ = Stmt\Goto_[$2]; } | identifier_not_reserved ':' { $$ = Stmt\Label[$1]; } | error { $$ = null; /* means: no statement */ } ; statement: non_empty_statement | ';' { makeNop($$); } ; blocklike_statement: statement { toBlock($1); } ; catches: /* empty */ { init(); } | catches catch { push($1, $2); } ; name_union: name { init($1); } | name_union '|' name { push($1, $3); } ; catch: T_CATCH '(' name_union optional_plain_variable ')' '{' inner_statement_list '}' { $$ = Stmt\Catch_[$3, $4, $7]; } ; optional_finally: /* empty */ { $$ = null; } | T_FINALLY '{' inner_statement_list '}' { $$ = Stmt\Finally_[$3]; } ; variables_list: non_empty_variables_list optional_comma ; non_empty_variables_list: variable { init($1); } | non_empty_variables_list ',' variable { push($1, $3); } ; optional_ref: /* empty */ { $$ = false; } | ampersand { $$ = true; } ; optional_arg_ref: /* empty */ { $$ = false; } | T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG { $$ = true; } ; optional_ellipsis: /* empty */ { $$ = false; } | T_ELLIPSIS { $$ = true; } ; block_or_error: '{' inner_statement_list '}' { $$ = $2; } | error { $$ = []; } ; fn_identifier: identifier_not_reserved | T_READONLY { $$ = Node\Identifier[$1]; } | T_EXIT { $$ = Node\Identifier[$1]; } | T_CLONE { $$ = Node\Identifier[$1]; } ; function_declaration_statement: T_FUNCTION optional_ref fn_identifier '(' parameter_list ')' optional_return_type block_or_error { $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $8, 'attrGroups' => []]]; } | attributes T_FUNCTION optional_ref fn_identifier '(' parameter_list ')' optional_return_type block_or_error { $$ = Stmt\Function_[$4, ['byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9, 'attrGroups' => $1]]; } ; class_declaration_statement: class_entry_type identifier_not_reserved extends_from implements_list '{' class_statement_list '}' { $$ = Stmt\Class_[$2, ['type' => $1, 'extends' => $3, 'implements' => $4, 'stmts' => $6, 'attrGroups' => []]]; $this->checkClass($$, #2); } | attributes class_entry_type identifier_not_reserved extends_from implements_list '{' class_statement_list '}' { $$ = Stmt\Class_[$3, ['type' => $2, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]]; $this->checkClass($$, #3); } | optional_attributes T_INTERFACE identifier_not_reserved interface_extends_list '{' class_statement_list '}' { $$ = Stmt\Interface_[$3, ['extends' => $4, 'stmts' => $6, 'attrGroups' => $1]]; $this->checkInterface($$, #3); } | optional_attributes T_TRAIT identifier_not_reserved '{' class_statement_list '}' { $$ = Stmt\Trait_[$3, ['stmts' => $5, 'attrGroups' => $1]]; } | optional_attributes T_ENUM identifier_not_reserved enum_scalar_type implements_list '{' class_statement_list '}' { $$ = Stmt\Enum_[$3, ['scalarType' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]]; $this->checkEnum($$, #3); } ; enum_scalar_type: /* empty */ { $$ = null; } | ':' type { $$ = $2; } enum_case_expr: /* empty */ { $$ = null; } | '=' expr { $$ = $2; } ; class_entry_type: T_CLASS { $$ = 0; } | class_modifiers T_CLASS ; class_modifiers: class_modifier | class_modifiers class_modifier { $this->checkClassModifier($1, $2, #2); $$ = $1 | $2; } ; class_modifier: T_ABSTRACT { $$ = Modifiers::ABSTRACT; } | T_FINAL { $$ = Modifiers::FINAL; } | T_READONLY { $$ = Modifiers::READONLY; } ; extends_from: /* empty */ { $$ = null; } | T_EXTENDS class_name { $$ = $2; } ; interface_extends_list: /* empty */ { $$ = array(); } | T_EXTENDS class_name_list { $$ = $2; } ; implements_list: /* empty */ { $$ = array(); } | T_IMPLEMENTS class_name_list { $$ = $2; } ; class_name_list: non_empty_class_name_list no_comma ; non_empty_class_name_list: class_name { init($1); } | non_empty_class_name_list ',' class_name { push($1, $3); } ; for_statement: blocklike_statement | ':' inner_statement_list T_ENDFOR ';' { $$ = $2; } ; foreach_statement: blocklike_statement | ':' inner_statement_list T_ENDFOREACH ';' { $$ = $2; } ; declare_statement: non_empty_statement { toBlock($1); } | ';' { $$ = null; } | ':' inner_statement_list T_ENDDECLARE ';' { $$ = $2; } ; declare_list: non_empty_declare_list no_comma ; non_empty_declare_list: declare_list_element { init($1); } | non_empty_declare_list ',' declare_list_element { push($1, $3); } ; declare_list_element: identifier_not_reserved '=' expr { $$ = Node\DeclareItem[$1, $3]; } ; switch_case_list: '{' case_list '}' { $$ = $2; } | '{' ';' case_list '}' { $$ = $3; } | ':' case_list T_ENDSWITCH ';' { $$ = $2; } | ':' ';' case_list T_ENDSWITCH ';' { $$ = $3; } ; case_list: /* empty */ { init(); } | case_list case { push($1, $2); } ; case: T_CASE expr case_separator inner_statement_list_ex { $$ = Stmt\Case_[$2, $4]; } | T_DEFAULT case_separator inner_statement_list_ex { $$ = Stmt\Case_[null, $3]; } ; case_separator: ':' | ';' ; match: T_MATCH '(' expr ')' '{' match_arm_list '}' { $$ = Expr\Match_[$3, $6]; } ; match_arm_list: /* empty */ { $$ = []; } | non_empty_match_arm_list optional_comma ; non_empty_match_arm_list: match_arm { init($1); } | non_empty_match_arm_list ',' match_arm { push($1, $3); } ; match_arm: expr_list_allow_comma T_DOUBLE_ARROW expr { $$ = Node\MatchArm[$1, $3]; } | T_DEFAULT optional_comma T_DOUBLE_ARROW expr { $$ = Node\MatchArm[null, $4]; } ; while_statement: blocklike_statement { $$ = $1; } | ':' inner_statement_list T_ENDWHILE ';' { $$ = $2; } ; elseif_list: /* empty */ { init(); } | elseif_list elseif { push($1, $2); } ; elseif: T_ELSEIF '(' expr ')' blocklike_statement { $$ = Stmt\ElseIf_[$3, $5]; } ; new_elseif_list: /* empty */ { init(); } | new_elseif_list new_elseif { push($1, $2); } ; new_elseif: T_ELSEIF '(' expr ')' ':' inner_statement_list { $$ = Stmt\ElseIf_[$3, $6]; $this->fixupAlternativeElse($$); } ; else_single: /* empty */ { $$ = null; } | T_ELSE blocklike_statement { $$ = Stmt\Else_[$2]; } ; new_else_single: /* empty */ { $$ = null; } | T_ELSE ':' inner_statement_list { $$ = Stmt\Else_[$3]; $this->fixupAlternativeElse($$); } ; foreach_variable: variable { $$ = array($1, false); } | ampersand variable { $$ = array($2, true); } | list_expr { $$ = array($1, false); } | array_short_syntax { $$ = array($this->fixupArrayDestructuring($1), false); } ; parameter_list: non_empty_parameter_list optional_comma | /* empty */ { $$ = array(); } ; non_empty_parameter_list: parameter { init($1); } | non_empty_parameter_list ',' parameter { push($1, $3); } ; optional_property_modifiers: /* empty */ { $$ = 0; } | optional_property_modifiers property_modifier { $this->checkModifier($1, $2, #2); $$ = $1 | $2; } ; property_modifier: T_PUBLIC { $$ = Modifiers::PUBLIC; } | T_PROTECTED { $$ = Modifiers::PROTECTED; } | T_PRIVATE { $$ = Modifiers::PRIVATE; } | T_PUBLIC_SET { $$ = Modifiers::PUBLIC_SET; } | T_PROTECTED_SET { $$ = Modifiers::PROTECTED_SET; } | T_PRIVATE_SET { $$ = Modifiers::PRIVATE_SET; } | T_READONLY { $$ = Modifiers::READONLY; } | T_FINAL { $$ = Modifiers::FINAL; } ; parameter: optional_attributes optional_property_modifiers optional_type_without_static optional_arg_ref optional_ellipsis plain_variable optional_property_hook_list { $$ = new Node\Param($6, null, $3, $4, $5, attributes(), $2, $1, $7); $this->checkParam($$); $this->addPropertyNameToHooks($$); } | optional_attributes optional_property_modifiers optional_type_without_static optional_arg_ref optional_ellipsis plain_variable '=' expr optional_property_hook_list { $$ = new Node\Param($6, $8, $3, $4, $5, attributes(), $2, $1, $9); $this->checkParam($$); $this->addPropertyNameToHooks($$); } | optional_attributes optional_property_modifiers optional_type_without_static optional_arg_ref optional_ellipsis error { $$ = new Node\Param(Expr\Error[], null, $3, $4, $5, attributes(), $2, $1); } ; type_expr: type | '?' type { $$ = Node\NullableType[$2]; } | union_type { $$ = Node\UnionType[$1]; } | intersection_type ; type: type_without_static | T_STATIC { $$ = Node\Name['static']; } ; type_without_static: name { $$ = $this->handleBuiltinTypes($1); } | T_ARRAY { $$ = Node\Identifier['array']; } | T_CALLABLE { $$ = Node\Identifier['callable']; } ; union_type_element: type | '(' intersection_type ')' { $$ = $2; } ; union_type: union_type_element '|' union_type_element { init($1, $3); } | union_type '|' union_type_element { push($1, $3); } ; union_type_without_static_element: type_without_static | '(' intersection_type_without_static ')' { $$ = $2; } ; union_type_without_static: union_type_without_static_element '|' union_type_without_static_element { init($1, $3); } | union_type_without_static '|' union_type_without_static_element { push($1, $3); } ; intersection_type_list: type T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type { init($1, $3); } | intersection_type_list T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type { push($1, $3); } ; intersection_type: intersection_type_list { $$ = Node\IntersectionType[$1]; } ; intersection_type_without_static_list: type_without_static T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static { init($1, $3); } | intersection_type_without_static_list T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static { push($1, $3); } ; intersection_type_without_static: intersection_type_without_static_list { $$ = Node\IntersectionType[$1]; } ; type_expr_without_static: type_without_static | '?' type_without_static { $$ = Node\NullableType[$2]; } | union_type_without_static { $$ = Node\UnionType[$1]; } | intersection_type_without_static ; optional_type_without_static: /* empty */ { $$ = null; } | type_expr_without_static ; optional_return_type: /* empty */ { $$ = null; } | ':' type_expr { $$ = $2; } | ':' error { $$ = null; } ; argument_list: '(' ')' { $$ = array(); } | '(' non_empty_argument_list optional_comma ')' { $$ = $2; } | '(' variadic_placeholder ')' { init($2); } ; clone_argument_list: '(' ')' { $$ = array(); } | '(' non_empty_clone_argument_list optional_comma ')' { $$ = $2; } | '(' expr ',' ')' { init(Node\Arg[$2, false, false]); } | '(' variadic_placeholder ')' { init($2); } ; non_empty_clone_argument_list: expr ',' argument { init(new Node\Arg($1, false, false, stackAttributes(#1)), $3); } | argument_no_expr { init($1); } | non_empty_clone_argument_list ',' argument { push($1, $3); } ; variadic_placeholder: T_ELLIPSIS { $$ = Node\VariadicPlaceholder[]; } ; non_empty_argument_list: argument { init($1); } | non_empty_argument_list ',' argument { push($1, $3); } ; argument_no_expr: ampersand variable { $$ = Node\Arg[$2, true, false]; } | T_ELLIPSIS expr { $$ = Node\Arg[$2, false, true]; } | identifier_maybe_reserved ':' expr { $$ = new Node\Arg($3, false, false, attributes(), $1); } ; argument: expr { $$ = Node\Arg[$1, false, false]; } | argument_no_expr { $$ = $1; } ; global_var_list: non_empty_global_var_list no_comma ; non_empty_global_var_list: non_empty_global_var_list ',' global_var { push($1, $3); } | global_var { init($1); } ; global_var: simple_variable ; static_var_list: non_empty_static_var_list no_comma ; non_empty_static_var_list: non_empty_static_var_list ',' static_var { push($1, $3); } | static_var { init($1); } ; static_var: plain_variable { $$ = Node\StaticVar[$1, null]; } | plain_variable '=' expr { $$ = Node\StaticVar[$1, $3]; } ; class_statement_list_ex: class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } else { $$ = $1; } } | /* empty */ { init(); } ; class_statement_list: class_statement_list_ex { makeZeroLengthNop($nop); if ($nop !== null) { $1[] = $nop; } $$ = $1; } ; class_statement: optional_attributes variable_modifiers optional_type_without_static property_declaration_list semi { $$ = new Stmt\Property($2, $4, attributes(), $3, $1); } #if PHP8 | optional_attributes variable_modifiers optional_type_without_static property_declaration_list '{' property_hook_list '}' { $$ = new Stmt\Property($2, $4, attributes(), $3, $1, $6); $this->checkPropertyHooksForMultiProperty($$, #5); $this->checkEmptyPropertyHookList($6, #5); $this->addPropertyNameToHooks($$); } #endif | optional_attributes method_modifiers T_CONST class_const_list semi { $$ = new Stmt\ClassConst($4, $2, attributes(), $1); $this->checkClassConst($$, #2); } | optional_attributes method_modifiers T_CONST type_expr class_const_list semi { $$ = new Stmt\ClassConst($5, $2, attributes(), $1, $4); $this->checkClassConst($$, #2); } | optional_attributes method_modifiers T_FUNCTION optional_ref identifier_maybe_reserved '(' parameter_list ')' optional_return_type method_body { $$ = Stmt\ClassMethod[$5, ['type' => $2, 'byRef' => $4, 'params' => $7, 'returnType' => $9, 'stmts' => $10, 'attrGroups' => $1]]; $this->checkClassMethod($$, #2); } | T_USE class_name_list trait_adaptations { $$ = Stmt\TraitUse[$2, $3]; } | optional_attributes T_CASE identifier_maybe_reserved enum_case_expr semi { $$ = Stmt\EnumCase[$3, $4, $1]; } | error { $$ = null; /* will be skipped */ } ; trait_adaptations: ';' { $$ = array(); } | '{' trait_adaptation_list '}' { $$ = $2; } ; trait_adaptation_list: /* empty */ { init(); } | trait_adaptation_list trait_adaptation { push($1, $2); } ; trait_adaptation: trait_method_reference_fully_qualified T_INSTEADOF class_name_list ';' { $$ = Stmt\TraitUseAdaptation\Precedence[$1[0], $1[1], $3]; } | trait_method_reference T_AS member_modifier identifier_maybe_reserved ';' { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, $4]; } | trait_method_reference T_AS member_modifier ';' { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, null]; } | trait_method_reference T_AS identifier_not_reserved ';' { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; } | trait_method_reference T_AS reserved_non_modifiers_identifier ';' { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; } ; trait_method_reference_fully_qualified: name T_PAAMAYIM_NEKUDOTAYIM identifier_maybe_reserved { $$ = array($1, $3); } ; trait_method_reference: trait_method_reference_fully_qualified | identifier_maybe_reserved { $$ = array(null, $1); } ; method_body: ';' /* abstract method */ { $$ = null; } | block_or_error ; variable_modifiers: non_empty_member_modifiers | T_VAR { $$ = 0; } ; method_modifiers: /* empty */ { $$ = 0; } | non_empty_member_modifiers ; non_empty_member_modifiers: member_modifier | non_empty_member_modifiers member_modifier { $this->checkModifier($1, $2, #2); $$ = $1 | $2; } ; member_modifier: T_PUBLIC { $$ = Modifiers::PUBLIC; } | T_PROTECTED { $$ = Modifiers::PROTECTED; } | T_PRIVATE { $$ = Modifiers::PRIVATE; } | T_PUBLIC_SET { $$ = Modifiers::PUBLIC_SET; } | T_PROTECTED_SET { $$ = Modifiers::PROTECTED_SET; } | T_PRIVATE_SET { $$ = Modifiers::PRIVATE_SET; } | T_STATIC { $$ = Modifiers::STATIC; } | T_ABSTRACT { $$ = Modifiers::ABSTRACT; } | T_FINAL { $$ = Modifiers::FINAL; } | T_READONLY { $$ = Modifiers::READONLY; } ; property_declaration_list: non_empty_property_declaration_list no_comma ; non_empty_property_declaration_list: property_declaration { init($1); } | non_empty_property_declaration_list ',' property_declaration { push($1, $3); } ; property_decl_name: T_VARIABLE { $$ = Node\VarLikeIdentifier[parseVar($1)]; } ; property_declaration: property_decl_name { $$ = Node\PropertyItem[$1, null]; } | property_decl_name '=' expr { $$ = Node\PropertyItem[$1, $3]; } ; property_hook_list: /* empty */ { $$ = []; } | property_hook_list property_hook { push($1, $2); } ; optional_property_hook_list: /* empty */ { $$ = []; } #if PHP8 | '{' property_hook_list '}' { $$ = $2; $this->checkEmptyPropertyHookList($2, #1); } #endif ; property_hook: optional_attributes property_hook_modifiers optional_ref identifier_not_reserved property_hook_body { $$ = Node\PropertyHook[$4, $5, ['flags' => $2, 'byRef' => $3, 'params' => [], 'attrGroups' => $1]]; $this->checkPropertyHook($$, null); } | optional_attributes property_hook_modifiers optional_ref identifier_not_reserved '(' parameter_list ')' property_hook_body { $$ = Node\PropertyHook[$4, $8, ['flags' => $2, 'byRef' => $3, 'params' => $6, 'attrGroups' => $1]]; $this->checkPropertyHook($$, #5); } ; property_hook_body: ';' { $$ = null; } | '{' inner_statement_list '}' { $$ = $2; } | T_DOUBLE_ARROW expr ';' { $$ = $2; } ; property_hook_modifiers: /* empty */ { $$ = 0; } | property_hook_modifiers member_modifier { $this->checkPropertyHookModifiers($1, $2, #2); $$ = $1 | $2; } ; expr_list_forbid_comma: non_empty_expr_list no_comma ; expr_list_allow_comma: non_empty_expr_list optional_comma ; non_empty_expr_list: non_empty_expr_list ',' expr { push($1, $3); } | expr { init($1); } ; for_expr: /* empty */ { $$ = array(); } | expr_list_forbid_comma ; expr: variable | list_expr '=' expr { $$ = Expr\Assign[$1, $3]; } | array_short_syntax '=' expr { $$ = Expr\Assign[$this->fixupArrayDestructuring($1), $3]; } | variable '=' expr { $$ = Expr\Assign[$1, $3]; } | variable '=' ampersand variable { $$ = Expr\AssignRef[$1, $4]; } | variable '=' ampersand new_expr { $$ = Expr\AssignRef[$1, $4]; if (!$this->phpVersion->allowsAssignNewByReference()) { $this->emitError(new Error('Cannot assign new by reference', attributes())); } } | new_expr | match | T_CLONE clone_argument_list { $$ = Expr\FuncCall[new Node\Name($1, stackAttributes(#1)), $2]; } | T_CLONE expr { $$ = Expr\Clone_[$2]; } | variable T_PLUS_EQUAL expr { $$ = Expr\AssignOp\Plus [$1, $3]; } | variable T_MINUS_EQUAL expr { $$ = Expr\AssignOp\Minus [$1, $3]; } | variable T_MUL_EQUAL expr { $$ = Expr\AssignOp\Mul [$1, $3]; } | variable T_DIV_EQUAL expr { $$ = Expr\AssignOp\Div [$1, $3]; } | variable T_CONCAT_EQUAL expr { $$ = Expr\AssignOp\Concat [$1, $3]; } | variable T_MOD_EQUAL expr { $$ = Expr\AssignOp\Mod [$1, $3]; } | variable T_AND_EQUAL expr { $$ = Expr\AssignOp\BitwiseAnd[$1, $3]; } | variable T_OR_EQUAL expr { $$ = Expr\AssignOp\BitwiseOr [$1, $3]; } | variable T_XOR_EQUAL expr { $$ = Expr\AssignOp\BitwiseXor[$1, $3]; } | variable T_SL_EQUAL expr { $$ = Expr\AssignOp\ShiftLeft [$1, $3]; } | variable T_SR_EQUAL expr { $$ = Expr\AssignOp\ShiftRight[$1, $3]; } | variable T_POW_EQUAL expr { $$ = Expr\AssignOp\Pow [$1, $3]; } | variable T_COALESCE_EQUAL expr { $$ = Expr\AssignOp\Coalesce [$1, $3]; } | variable T_INC { $$ = Expr\PostInc[$1]; } | T_INC variable { $$ = Expr\PreInc [$2]; } | variable T_DEC { $$ = Expr\PostDec[$1]; } | T_DEC variable { $$ = Expr\PreDec [$2]; } | expr T_BOOLEAN_OR expr { $$ = Expr\BinaryOp\BooleanOr [$1, $3]; } | expr T_BOOLEAN_AND expr { $$ = Expr\BinaryOp\BooleanAnd[$1, $3]; } | expr T_LOGICAL_OR expr { $$ = Expr\BinaryOp\LogicalOr [$1, $3]; } | expr T_LOGICAL_AND expr { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; } | expr T_LOGICAL_XOR expr { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; } | expr '|' expr { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; } | expr T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG expr { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; } | expr T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG expr { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; } | expr '^' expr { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; } | expr '.' expr { $$ = Expr\BinaryOp\Concat [$1, $3]; } | expr '+' expr { $$ = Expr\BinaryOp\Plus [$1, $3]; } | expr '-' expr { $$ = Expr\BinaryOp\Minus [$1, $3]; } | expr '*' expr { $$ = Expr\BinaryOp\Mul [$1, $3]; } | expr '/' expr { $$ = Expr\BinaryOp\Div [$1, $3]; } | expr '%' expr { $$ = Expr\BinaryOp\Mod [$1, $3]; } | expr T_SL expr { $$ = Expr\BinaryOp\ShiftLeft [$1, $3]; } | expr T_SR expr { $$ = Expr\BinaryOp\ShiftRight[$1, $3]; } | expr T_POW expr { $$ = Expr\BinaryOp\Pow [$1, $3]; } | '+' expr %prec T_INC { $$ = Expr\UnaryPlus [$2]; } | '-' expr %prec T_INC { $$ = Expr\UnaryMinus[$2]; } | '!' expr { $$ = Expr\BooleanNot[$2]; } | '~' expr { $$ = Expr\BitwiseNot[$2]; } | expr T_IS_IDENTICAL expr { $$ = Expr\BinaryOp\Identical [$1, $3]; } | expr T_IS_NOT_IDENTICAL expr { $$ = Expr\BinaryOp\NotIdentical [$1, $3]; } | expr T_IS_EQUAL expr { $$ = Expr\BinaryOp\Equal [$1, $3]; } | expr T_IS_NOT_EQUAL expr { $$ = Expr\BinaryOp\NotEqual [$1, $3]; } | expr T_SPACESHIP expr { $$ = Expr\BinaryOp\Spaceship [$1, $3]; } | expr '<' expr { $$ = Expr\BinaryOp\Smaller [$1, $3]; } | expr T_IS_SMALLER_OR_EQUAL expr { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; } | expr '>' expr { $$ = Expr\BinaryOp\Greater [$1, $3]; } | expr T_IS_GREATER_OR_EQUAL expr { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; } #if PHP8 | expr T_PIPE expr { $$ = Expr\BinaryOp\Pipe[$1, $3]; $this->checkPipeOperatorParentheses($3); } #endif | expr T_INSTANCEOF class_name_reference { $$ = Expr\Instanceof_[$1, $3]; } | '(' expr ')' { $$ = $2; if ($$ instanceof Expr\ArrowFunction) { $this->parenthesizedArrowFunctions->offsetSet($$); } } | expr '?' expr ':' expr { $$ = Expr\Ternary[$1, $3, $5]; } | expr '?' ':' expr { $$ = Expr\Ternary[$1, null, $4]; } | expr T_COALESCE expr { $$ = Expr\BinaryOp\Coalesce[$1, $3]; } | T_ISSET '(' expr_list_allow_comma ')' { $$ = Expr\Isset_[$3]; } | T_EMPTY '(' expr ')' { $$ = Expr\Empty_[$3]; } | T_INCLUDE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE]; } | T_INCLUDE_ONCE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE_ONCE]; } | T_EVAL '(' expr ')' { $$ = Expr\Eval_[$3]; } | T_REQUIRE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE]; } | T_REQUIRE_ONCE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE_ONCE]; } | T_INT_CAST expr { $attrs = attributes(); $attrs['kind'] = $this->getIntCastKind($1); $$ = new Expr\Cast\Int_($2, $attrs); } | T_DOUBLE_CAST expr { $attrs = attributes(); $attrs['kind'] = $this->getFloatCastKind($1); $$ = new Expr\Cast\Double($2, $attrs); } | T_STRING_CAST expr { $attrs = attributes(); $attrs['kind'] = $this->getStringCastKind($1); $$ = new Expr\Cast\String_($2, $attrs); } | T_ARRAY_CAST expr { $$ = Expr\Cast\Array_ [$2]; } | T_OBJECT_CAST expr { $$ = Expr\Cast\Object_ [$2]; } | T_BOOL_CAST expr { $attrs = attributes(); $attrs['kind'] = $this->getBoolCastKind($1); $$ = new Expr\Cast\Bool_($2, $attrs); } | T_UNSET_CAST expr { $$ = Expr\Cast\Unset_ [$2]; } | T_VOID_CAST expr { $$ = Expr\Cast\Void_ [$2]; } | T_EXIT ctor_arguments { $$ = $this->createExitExpr($1, #1, $2, attributes()); } | '@' expr { $$ = Expr\ErrorSuppress[$2]; } | scalar | '`' backticks_expr '`' { $$ = Expr\ShellExec[$2]; } | T_PRINT expr { $$ = Expr\Print_[$2]; } | T_YIELD { $$ = Expr\Yield_[null, null]; } | T_YIELD expr { $$ = Expr\Yield_[$2, null]; } | T_YIELD expr T_DOUBLE_ARROW expr { $$ = Expr\Yield_[$4, $2]; } | T_YIELD_FROM expr { $$ = Expr\YieldFrom[$2]; } | T_THROW expr { $$ = Expr\Throw_[$2]; } | T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr %prec T_THROW { $$ = Expr\ArrowFunction[['static' => false, 'byRef' => $2, 'params' => $4, 'returnType' => $6, 'expr' => $8, 'attrGroups' => []]]; } | T_STATIC T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr %prec T_THROW { $$ = Expr\ArrowFunction[['static' => true, 'byRef' => $3, 'params' => $5, 'returnType' => $7, 'expr' => $9, 'attrGroups' => []]]; } | T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type block_or_error { $$ = Expr\Closure[['static' => false, 'byRef' => $2, 'params' => $4, 'uses' => $6, 'returnType' => $7, 'stmts' => $8, 'attrGroups' => []]]; } | T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type block_or_error { $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $9, 'attrGroups' => []]]; } | attributes T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr %prec T_THROW { $$ = Expr\ArrowFunction[['static' => false, 'byRef' => $3, 'params' => $5, 'returnType' => $7, 'expr' => $9, 'attrGroups' => $1]]; } | attributes T_STATIC T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr %prec T_THROW { $$ = Expr\ArrowFunction[['static' => true, 'byRef' => $4, 'params' => $6, 'returnType' => $8, 'expr' => $10, 'attrGroups' => $1]]; } | attributes T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type block_or_error { $$ = Expr\Closure[['static' => false, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $9, 'attrGroups' => $1]]; } | attributes T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type block_or_error { $$ = Expr\Closure[['static' => true, 'byRef' => $4, 'params' => $6, 'uses' => $8, 'returnType' => $9, 'stmts' => $10, 'attrGroups' => $1]]; } ; anonymous_class: optional_attributes class_entry_type ctor_arguments extends_from implements_list '{' class_statement_list '}' { $$ = array(Stmt\Class_[null, ['type' => $2, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]], $3); $this->checkClass($$[0], -1); } ; new_dereferenceable: T_NEW class_name_reference argument_list { $$ = Expr\New_[$2, $3]; } | T_NEW anonymous_class { list($class, $ctorArgs) = $2; $$ = Expr\New_[$class, $ctorArgs]; } ; new_non_dereferenceable: T_NEW class_name_reference { $$ = Expr\New_[$2, []]; } ; new_expr: new_dereferenceable | new_non_dereferenceable ; lexical_vars: /* empty */ { $$ = array(); } | T_USE '(' lexical_var_list ')' { $$ = $3; } ; lexical_var_list: non_empty_lexical_var_list optional_comma ; non_empty_lexical_var_list: lexical_var { init($1); } | non_empty_lexical_var_list ',' lexical_var { push($1, $3); } ; lexical_var: optional_ref plain_variable { $$ = Node\ClosureUse[$2, $1]; } ; name_readonly: T_READONLY { $$ = Name[$1]; } ; function_call: name argument_list { $$ = Expr\FuncCall[$1, $2]; } | name_readonly argument_list { $$ = Expr\FuncCall[$1, $2]; } | callable_expr argument_list { $$ = Expr\FuncCall[$1, $2]; } | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM member_name argument_list { $$ = Expr\StaticCall[$1, $3, $4]; } ; class_name: T_STATIC { $$ = Name[$1]; } | name ; name: T_STRING { $$ = Name[$1]; } | T_NAME_QUALIFIED { $$ = Name[$1]; } | T_NAME_FULLY_QUALIFIED { $$ = Name\FullyQualified[substr($1, 1)]; } | T_NAME_RELATIVE { $$ = Name\Relative[substr($1, 10)]; } ; class_name_reference: class_name | new_variable | '(' expr ')' { $$ = $2; } | error { $$ = Expr\Error[]; $this->errorState = 2; } ; class_name_or_var: class_name | fully_dereferenceable ; backticks_expr: /* empty */ { $$ = array(); } | encaps_string_part { $$ = array($1); parseEncapsed($$, '`', $this->phpVersion->supportsUnicodeEscapes()); } | encaps_list { parseEncapsed($1, '`', $this->phpVersion->supportsUnicodeEscapes()); $$ = $1; } ; ctor_arguments: /* empty */ { $$ = array(); } | argument_list ; constant: name { $$ = Expr\ConstFetch[$1]; } | T_LINE { $$ = Scalar\MagicConst\Line[]; } | T_FILE { $$ = Scalar\MagicConst\File[]; } | T_DIR { $$ = Scalar\MagicConst\Dir[]; } | T_CLASS_C { $$ = Scalar\MagicConst\Class_[]; } | T_TRAIT_C { $$ = Scalar\MagicConst\Trait_[]; } | T_METHOD_C { $$ = Scalar\MagicConst\Method[]; } | T_FUNC_C { $$ = Scalar\MagicConst\Function_[]; } | T_NS_C { $$ = Scalar\MagicConst\Namespace_[]; } | T_PROPERTY_C { $$ = Scalar\MagicConst\Property[]; } ; class_constant: class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_maybe_reserved { $$ = Expr\ClassConstFetch[$1, $3]; } | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' { $$ = Expr\ClassConstFetch[$1, $4]; } /* We interpret an isolated FOO:: as an unfinished class constant fetch. It could also be an unfinished static property fetch or unfinished scoped call. */ | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM error { $$ = Expr\ClassConstFetch[$1, new Expr\Error(stackAttributes(#3))]; $this->errorState = 2; } ; array_short_syntax: '[' array_pair_list ']' { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_SHORT; $$ = new Expr\Array_($2, $attrs); } ; dereferenceable_scalar: T_ARRAY '(' array_pair_list ')' { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_LONG; $$ = new Expr\Array_($3, $attrs); $this->createdArrays->offsetSet($$); } | array_short_syntax { $$ = $1; $this->createdArrays->offsetSet($$); } | T_CONSTANT_ENCAPSED_STRING { $$ = Scalar\String_::fromString($1, attributes(), $this->phpVersion->supportsUnicodeEscapes()); } | '"' encaps_list '"' { $attrs = attributes(); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED; parseEncapsed($2, '"', $this->phpVersion->supportsUnicodeEscapes()); $$ = new Scalar\InterpolatedString($2, $attrs); } ; scalar: T_LNUMBER { $$ = $this->parseLNumber($1, attributes(), $this->phpVersion->allowsInvalidOctals()); } | T_DNUMBER { $$ = Scalar\Float_::fromString($1, attributes()); } | dereferenceable_scalar | constant | class_constant | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC { $$ = $this->parseDocString($1, $2, $3, attributes(), stackAttributes(#3), true); } | T_START_HEREDOC T_END_HEREDOC { $$ = $this->parseDocString($1, '', $2, attributes(), stackAttributes(#2), true); } | T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = $this->parseDocString($1, $2, $3, attributes(), stackAttributes(#3), true); } ; optional_expr: /* empty */ { $$ = null; } | expr ; fully_dereferenceable: variable | '(' expr ')' { $$ = $2; } | dereferenceable_scalar | class_constant | new_dereferenceable ; array_object_dereferenceable: fully_dereferenceable | constant ; callable_expr: callable_variable | '(' expr ')' { $$ = $2; } | dereferenceable_scalar | new_dereferenceable ; callable_variable: simple_variable | array_object_dereferenceable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } #if PHP7 | array_object_dereferenceable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } #endif | function_call | array_object_dereferenceable T_OBJECT_OPERATOR property_name argument_list { $$ = Expr\MethodCall[$1, $3, $4]; } | array_object_dereferenceable T_NULLSAFE_OBJECT_OPERATOR property_name argument_list { $$ = Expr\NullsafeMethodCall[$1, $3, $4]; } ; optional_plain_variable: /* empty */ { $$ = null; } | plain_variable ; variable: callable_variable | static_member | array_object_dereferenceable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; } | array_object_dereferenceable T_NULLSAFE_OBJECT_OPERATOR property_name { $$ = Expr\NullsafePropertyFetch[$1, $3]; } ; simple_variable: plain_variable | '$' '{' expr '}' { $$ = Expr\Variable[$3]; } | '$' simple_variable { $$ = Expr\Variable[$2]; } | '$' error { $$ = Expr\Variable[Expr\Error[]]; $this->errorState = 2; } ; static_member_prop_name: simple_variable { $var = $1->name; $$ = \is_string($var) ? Node\VarLikeIdentifier[$var] : $var; } ; static_member: class_name_or_var T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name { $$ = Expr\StaticPropertyFetch[$1, $3]; } ; new_variable: simple_variable | new_variable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } #if PHP7 | new_variable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } #endif | new_variable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; } | new_variable T_NULLSAFE_OBJECT_OPERATOR property_name { $$ = Expr\NullsafePropertyFetch[$1, $3]; } | class_name T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name { $$ = Expr\StaticPropertyFetch[$1, $3]; } | new_variable T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name { $$ = Expr\StaticPropertyFetch[$1, $3]; } ; member_name: identifier_maybe_reserved | '{' expr '}' { $$ = $2; } | simple_variable ; property_name: identifier_not_reserved | '{' expr '}' { $$ = $2; } | simple_variable | error { $$ = Expr\Error[]; $this->errorState = 2; } ; list_expr: T_LIST '(' inner_array_pair_list ')' { $$ = Expr\List_[$3]; $$->setAttribute('kind', Expr\List_::KIND_LIST); $this->postprocessList($$); } ; array_pair_list: inner_array_pair_list { $$ = $1; $end = count($$)-1; if ($$[$end]->value instanceof Expr\Error) array_pop($$); } ; comma_or_error: ',' | error { /* do nothing -- prevent default action of $$=$1. See #551. */ } ; inner_array_pair_list: inner_array_pair_list comma_or_error array_pair { push($1, $3); } | array_pair { init($1); } ; array_pair: expr { $$ = Node\ArrayItem[$1, null, false]; } | ampersand variable { $$ = Node\ArrayItem[$2, null, true]; } | list_expr { $$ = Node\ArrayItem[$1, null, false]; } | expr T_DOUBLE_ARROW expr { $$ = Node\ArrayItem[$3, $1, false]; } | expr T_DOUBLE_ARROW ampersand variable { $$ = Node\ArrayItem[$4, $1, true]; } | expr T_DOUBLE_ARROW list_expr { $$ = Node\ArrayItem[$3, $1, false]; } | T_ELLIPSIS expr { $$ = new Node\ArrayItem($2, null, false, attributes(), true); } | /* empty */ { /* Create an Error node now to remember the position. We'll later either report an error, or convert this into a null element, depending on whether this is a creation or destructuring context. */ $attrs = $this->createEmptyElemAttributes($this->tokenPos); $$ = new Node\ArrayItem(new Expr\Error($attrs), null, false, $attrs); } ; encaps_list: encaps_list encaps_var { push($1, $2); } | encaps_list encaps_string_part { push($1, $2); } | encaps_var { init($1); } | encaps_string_part encaps_var { init($1, $2); } ; encaps_string_part: T_ENCAPSED_AND_WHITESPACE { $attrs = attributes(); $attrs['rawValue'] = $1; $$ = new Node\InterpolatedStringPart($1, $attrs); } ; encaps_str_varname: T_STRING_VARNAME { $$ = Expr\Variable[$1]; } ; encaps_var: plain_variable | plain_variable '[' encaps_var_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } | plain_variable T_OBJECT_OPERATOR identifier_not_reserved { $$ = Expr\PropertyFetch[$1, $3]; } | plain_variable T_NULLSAFE_OBJECT_OPERATOR identifier_not_reserved { $$ = Expr\NullsafePropertyFetch[$1, $3]; } | T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = Expr\Variable[$2]; } | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}' { $$ = Expr\Variable[$2]; } | T_DOLLAR_OPEN_CURLY_BRACES encaps_str_varname '[' expr ']' '}' { $$ = Expr\ArrayDimFetch[$2, $4]; } | T_CURLY_OPEN variable '}' { $$ = $2; } ; encaps_var_offset: T_STRING { $$ = Scalar\String_[$1]; } | T_NUM_STRING { $$ = $this->parseNumString($1, attributes()); } | '-' T_NUM_STRING { $$ = $this->parseNumString('-' . $2, attributes()); } | plain_variable ; %% ================================================ FILE: grammar/phpyLang.php ================================================ \'[^\\\\\']*+(?:\\\\.[^\\\\\']*+)*+\') (?"[^\\\\"]*+(?:\\\\.[^\\\\"]*+)*+") (?(?&singleQuotedString)|(?&doubleQuotedString)) (?/\*[^*]*+(?:\*(?!/)[^*]*+)*+\*/) (?\{[^\'"/{}]*+(?:(?:(?&string)|(?&comment)|(?&code)|/)[^\'"/{}]*+)*+}) )'; const PARAMS = '\[(?[^[\]]*+(?:\[(?¶ms)\][^[\]]*+)*+)\]'; const ARGS = '\((?[^()]*+(?:\((?&args)\)[^()]*+)*+)\)'; /////////////////////////////// /// Preprocessing functions /// /////////////////////////////// function preprocessGrammar($code) { $code = resolveNodes($code); $code = resolveMacros($code); $code = resolveStackAccess($code); $code = str_replace('$this', '$self', $code); return $code; } function resolveNodes($code) { return preg_replace_callback( '~\b(?[A-Z][a-zA-Z_\\\\]++)\s*' . PARAMS . '~', function ($matches) { // recurse $matches['params'] = resolveNodes($matches['params']); $params = magicSplit( '(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,', $matches['params'] ); $paramCode = ''; foreach ($params as $param) { $paramCode .= $param . ', '; } return 'new ' . $matches['name'] . '(' . $paramCode . 'attributes())'; }, $code ); } function resolveMacros($code) { return preg_replace_callback( '~\b(?)(?!array\()(?[a-z][A-Za-z]++)' . ARGS . '~', function ($matches) { // recurse $matches['args'] = resolveMacros($matches['args']); $name = $matches['name']; $args = magicSplit( '(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,', $matches['args'] ); if ('attributes' === $name) { assertArgs(0, $args, $name); return '$this->getAttributes($this->tokenStartStack[#1], $this->tokenEndStack[$stackPos])'; } if ('stackAttributes' === $name) { assertArgs(1, $args, $name); return '$this->getAttributes($this->tokenStartStack[' . $args[0] . '], ' . ' $this->tokenEndStack[' . $args[0] . '])'; } if ('init' === $name) { return '$$ = array(' . implode(', ', $args) . ')'; } if ('push' === $name) { assertArgs(2, $args, $name); return $args[0] . '[] = ' . $args[1] . '; $$ = ' . $args[0]; } if ('pushNormalizing' === $name) { assertArgs(2, $args, $name); return 'if (' . $args[1] . ' !== null) { ' . $args[0] . '[] = ' . $args[1] . '; } $$ = ' . $args[0] . ';'; } if ('toBlock' == $name) { assertArgs(1, $args, $name); return 'if (' . $args[0] . ' instanceof Stmt\Block) { $$ = ' . $args[0] . '->stmts; } ' . 'else if (' . $args[0] . ' === null) { $$ = []; } ' . 'else { $$ = [' . $args[0] . ']; }'; } if ('parseVar' === $name) { assertArgs(1, $args, $name); return 'substr(' . $args[0] . ', 1)'; } if ('parseEncapsed' === $name) { assertArgs(3, $args, $name); return 'foreach (' . $args[0] . ' as $s) { if ($s instanceof Node\InterpolatedStringPart) {' . ' $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, ' . $args[1] . ', ' . $args[2] . '); } }'; } if ('makeNop' === $name) { assertArgs(1, $args, $name); return $args[0] . ' = $this->maybeCreateNop($this->tokenStartStack[#1], $this->tokenEndStack[$stackPos])'; } if ('makeZeroLengthNop' == $name) { assertArgs(1, $args, $name); return $args[0] . ' = $this->maybeCreateZeroLengthNop($this->tokenPos);'; } return $matches[0]; }, $code ); } function assertArgs($num, $args, $name) { if ($num != count($args)) { die('Wrong argument count for ' . $name . '().'); } } function resolveStackAccess($code) { $code = preg_replace('/\$\d+/', '$this->semStack[$0]', $code); $code = preg_replace('/#(\d+)/', '$$1', $code); return $code; } function removeTrailingWhitespace($code) { $lines = explode("\n", $code); $lines = array_map('rtrim', $lines); return implode("\n", $lines); } ////////////////////////////// /// Regex helper functions /// ////////////////////////////// function regex($regex) { return '~' . LIB . '(?:' . str_replace('~', '\~', $regex) . ')~'; } function magicSplit($regex, $string) { $pieces = preg_split(regex('(?:(?&string)|(?&comment)|(?&code))(*SKIP)(*FAIL)|' . $regex), $string); foreach ($pieces as &$piece) { $piece = trim($piece); } if ($pieces === ['']) { return []; } return $pieces; } ================================================ FILE: grammar/rebuildParsers.php ================================================ ['PHP7' => true], 'Php8' => ['PHP8' => true], ]; $grammarFile = __DIR__ . '/php.y'; $skeletonFile = __DIR__ . '/parser.template'; $tmpGrammarFile = __DIR__ . '/tmp_parser.phpy'; $tmpResultFile = __DIR__ . '/tmp_parser.php'; $resultDir = __DIR__ . '/../lib/PhpParser/Parser'; $kmyacc = getenv('KMYACC'); if (!$kmyacc) { // Use phpyacc from dev dependencies by default. $kmyacc = __DIR__ . '/../vendor/bin/phpyacc'; } $options = array_flip($argv); $optionDebug = isset($options['--debug']); $optionKeepTmpGrammar = isset($options['--keep-tmp-grammar']); /////////////////// /// Main script /// /////////////////// foreach ($parserToDefines as $name => $defines) { echo "Building temporary $name grammar file.\n"; $grammarCode = file_get_contents($grammarFile); $grammarCode = replaceIfBlocks($grammarCode, $defines); $grammarCode = preprocessGrammar($grammarCode); file_put_contents($tmpGrammarFile, $grammarCode); $additionalArgs = $optionDebug ? '-t -v' : ''; echo "Building $name parser.\n"; $output = execCmd("$kmyacc $additionalArgs -m $skeletonFile -p $name $tmpGrammarFile"); $resultCode = file_get_contents($tmpResultFile); $resultCode = removeTrailingWhitespace($resultCode); ensureDirExists($resultDir); file_put_contents("$resultDir/$name.php", $resultCode); unlink($tmpResultFile); if (!$optionKeepTmpGrammar) { unlink($tmpGrammarFile); } } //////////////////////////////// /// Utility helper functions /// //////////////////////////////// function ensureDirExists($dir) { if (!is_dir($dir)) { mkdir($dir, 0777, true); } } function execCmd($cmd) { $output = trim(shell_exec("$cmd 2>&1") ?? ''); if ($output !== "") { echo "> " . $cmd . "\n"; echo $output; } return $output; } function replaceIfBlocks(string $code, array $defines): string { return preg_replace_callback('/\n#if\s+(\w+)\n(.*?)\n#endif/s', function ($matches) use ($defines) { $value = $defines[$matches[1]] ?? false; return $value ? $matches[2] : ''; }, $code); } ================================================ FILE: lib/PhpParser/Builder/ClassConst.php ================================================ */ protected array $attributes = []; /** @var list */ protected array $constants = []; /** @var list */ protected array $attributeGroups = []; /** @var Identifier|Node\Name|Node\ComplexType|null */ protected ?Node $type = null; /** * Creates a class constant builder * * @param string|Identifier $name Name * @param Node\Expr|bool|null|int|float|string|array|\UnitEnum $value Value */ public function __construct($name, $value) { $this->constants = [new Const_($name, BuilderHelpers::normalizeValue($value))]; } /** * Add another constant to const group * * @param string|Identifier $name Name * @param Node\Expr|bool|null|int|float|string|array|\UnitEnum $value Value * * @return $this The builder instance (for fluid interface) */ public function addConst($name, $value) { $this->constants[] = new Const_($name, BuilderHelpers::normalizeValue($value)); return $this; } /** * Makes the constant public. * * @return $this The builder instance (for fluid interface) */ public function makePublic() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PUBLIC); return $this; } /** * Makes the constant protected. * * @return $this The builder instance (for fluid interface) */ public function makeProtected() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED); return $this; } /** * Makes the constant private. * * @return $this The builder instance (for fluid interface) */ public function makePrivate() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE); return $this; } /** * Makes the constant final. * * @return $this The builder instance (for fluid interface) */ public function makeFinal() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::FINAL); return $this; } /** * Sets doc comment for the constant. * * @param PhpParser\Comment\Doc|string $docComment Doc comment to set * * @return $this The builder instance (for fluid interface) */ public function setDocComment($docComment) { $this->attributes = [ 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] ]; return $this; } /** * Adds an attribute group. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return $this The builder instance (for fluid interface) */ public function addAttribute($attribute) { $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } /** * Sets the constant type. * * @param string|Node\Name|Identifier|Node\ComplexType $type * * @return $this */ public function setType($type) { $this->type = BuilderHelpers::normalizeType($type); return $this; } /** * Returns the built class node. * * @return Stmt\ClassConst The built constant node */ public function getNode(): PhpParser\Node { return new Stmt\ClassConst( $this->constants, $this->flags, $this->attributes, $this->attributeGroups, $this->type ); } } ================================================ FILE: lib/PhpParser/Builder/Class_.php ================================================ */ protected array $implements = []; protected int $flags = 0; /** @var list */ protected array $uses = []; /** @var list */ protected array $constants = []; /** @var list */ protected array $properties = []; /** @var list */ protected array $methods = []; /** @var list */ protected array $attributeGroups = []; /** * Creates a class builder. * * @param string $name Name of the class */ public function __construct(string $name) { $this->name = $name; } /** * Extends a class. * * @param Name|string $class Name of class to extend * * @return $this The builder instance (for fluid interface) */ public function extend($class) { $this->extends = BuilderHelpers::normalizeName($class); return $this; } /** * Implements one or more interfaces. * * @param Name|string ...$interfaces Names of interfaces to implement * * @return $this The builder instance (for fluid interface) */ public function implement(...$interfaces) { foreach ($interfaces as $interface) { $this->implements[] = BuilderHelpers::normalizeName($interface); } return $this; } /** * Makes the class abstract. * * @return $this The builder instance (for fluid interface) */ public function makeAbstract() { $this->flags = BuilderHelpers::addClassModifier($this->flags, Modifiers::ABSTRACT); return $this; } /** * Makes the class final. * * @return $this The builder instance (for fluid interface) */ public function makeFinal() { $this->flags = BuilderHelpers::addClassModifier($this->flags, Modifiers::FINAL); return $this; } /** * Makes the class readonly. * * @return $this The builder instance (for fluid interface) */ public function makeReadonly() { $this->flags = BuilderHelpers::addClassModifier($this->flags, Modifiers::READONLY); return $this; } /** * Adds a statement. * * @param Stmt|PhpParser\Builder $stmt The statement to add * * @return $this The builder instance (for fluid interface) */ public function addStmt($stmt) { $stmt = BuilderHelpers::normalizeNode($stmt); if ($stmt instanceof Stmt\Property) { $this->properties[] = $stmt; } elseif ($stmt instanceof Stmt\ClassMethod) { $this->methods[] = $stmt; } elseif ($stmt instanceof Stmt\TraitUse) { $this->uses[] = $stmt; } elseif ($stmt instanceof Stmt\ClassConst) { $this->constants[] = $stmt; } else { throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); } return $this; } /** * Adds an attribute group. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return $this The builder instance (for fluid interface) */ public function addAttribute($attribute) { $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } /** * Returns the built class node. * * @return Stmt\Class_ The built class node */ public function getNode(): PhpParser\Node { return new Stmt\Class_($this->name, [ 'flags' => $this->flags, 'extends' => $this->extends, 'implements' => $this->implements, 'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods), 'attrGroups' => $this->attributeGroups, ], $this->attributes); } } ================================================ FILE: lib/PhpParser/Builder/Declaration.php ================================================ */ protected array $attributes = []; /** * Adds a statement. * * @param PhpParser\Node\Stmt|PhpParser\Builder $stmt The statement to add * * @return $this The builder instance (for fluid interface) */ abstract public function addStmt($stmt); /** * Adds multiple statements. * * @param (PhpParser\Node\Stmt|PhpParser\Builder)[] $stmts The statements to add * * @return $this The builder instance (for fluid interface) */ public function addStmts(array $stmts) { foreach ($stmts as $stmt) { $this->addStmt($stmt); } return $this; } /** * Sets doc comment for the declaration. * * @param PhpParser\Comment\Doc|string $docComment Doc comment to set * * @return $this The builder instance (for fluid interface) */ public function setDocComment($docComment) { $this->attributes['comments'] = [ BuilderHelpers::normalizeDocComment($docComment) ]; return $this; } } ================================================ FILE: lib/PhpParser/Builder/EnumCase.php ================================================ */ protected array $attributes = []; /** @var list */ protected array $attributeGroups = []; /** * Creates an enum case builder. * * @param string|Identifier $name Name */ public function __construct($name) { $this->name = $name; } /** * Sets the value. * * @param Node\Expr|string|int $value * * @return $this */ public function setValue($value) { $this->value = BuilderHelpers::normalizeValue($value); return $this; } /** * Sets doc comment for the constant. * * @param PhpParser\Comment\Doc|string $docComment Doc comment to set * * @return $this The builder instance (for fluid interface) */ public function setDocComment($docComment) { $this->attributes = [ 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] ]; return $this; } /** * Adds an attribute group. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return $this The builder instance (for fluid interface) */ public function addAttribute($attribute) { $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } /** * Returns the built enum case node. * * @return Stmt\EnumCase The built constant node */ public function getNode(): PhpParser\Node { return new Stmt\EnumCase( $this->name, $this->value, $this->attributeGroups, $this->attributes ); } } ================================================ FILE: lib/PhpParser/Builder/Enum_.php ================================================ */ protected array $implements = []; /** @var list */ protected array $uses = []; /** @var list */ protected array $enumCases = []; /** @var list */ protected array $constants = []; /** @var list */ protected array $methods = []; /** @var list */ protected array $attributeGroups = []; /** * Creates an enum builder. * * @param string $name Name of the enum */ public function __construct(string $name) { $this->name = $name; } /** * Sets the scalar type. * * @param string|Identifier $scalarType * * @return $this */ public function setScalarType($scalarType) { $this->scalarType = BuilderHelpers::normalizeType($scalarType); return $this; } /** * Implements one or more interfaces. * * @param Name|string ...$interfaces Names of interfaces to implement * * @return $this The builder instance (for fluid interface) */ public function implement(...$interfaces) { foreach ($interfaces as $interface) { $this->implements[] = BuilderHelpers::normalizeName($interface); } return $this; } /** * Adds a statement. * * @param Stmt|PhpParser\Builder $stmt The statement to add * * @return $this The builder instance (for fluid interface) */ public function addStmt($stmt) { $stmt = BuilderHelpers::normalizeNode($stmt); if ($stmt instanceof Stmt\EnumCase) { $this->enumCases[] = $stmt; } elseif ($stmt instanceof Stmt\ClassMethod) { $this->methods[] = $stmt; } elseif ($stmt instanceof Stmt\TraitUse) { $this->uses[] = $stmt; } elseif ($stmt instanceof Stmt\ClassConst) { $this->constants[] = $stmt; } else { throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); } return $this; } /** * Adds an attribute group. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return $this The builder instance (for fluid interface) */ public function addAttribute($attribute) { $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } /** * Returns the built class node. * * @return Stmt\Enum_ The built enum node */ public function getNode(): PhpParser\Node { return new Stmt\Enum_($this->name, [ 'scalarType' => $this->scalarType, 'implements' => $this->implements, 'stmts' => array_merge($this->uses, $this->enumCases, $this->constants, $this->methods), 'attrGroups' => $this->attributeGroups, ], $this->attributes); } } ================================================ FILE: lib/PhpParser/Builder/FunctionLike.php ================================================ returnByRef = true; return $this; } /** * Adds a parameter. * * @param Node\Param|Param $param The parameter to add * * @return $this The builder instance (for fluid interface) */ public function addParam($param) { $param = BuilderHelpers::normalizeNode($param); if (!$param instanceof Node\Param) { throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType())); } $this->params[] = $param; return $this; } /** * Adds multiple parameters. * * @param (Node\Param|Param)[] $params The parameters to add * * @return $this The builder instance (for fluid interface) */ public function addParams(array $params) { foreach ($params as $param) { $this->addParam($param); } return $this; } /** * Sets the return type for PHP 7. * * @param string|Node\Name|Node\Identifier|Node\ComplexType $type * * @return $this The builder instance (for fluid interface) */ public function setReturnType($type) { $this->returnType = BuilderHelpers::normalizeType($type); return $this; } } ================================================ FILE: lib/PhpParser/Builder/Function_.php ================================================ */ protected array $stmts = []; /** @var list */ protected array $attributeGroups = []; /** * Creates a function builder. * * @param string $name Name of the function */ public function __construct(string $name) { $this->name = $name; } /** * Adds a statement. * * @param Node|PhpParser\Builder $stmt The statement to add * * @return $this The builder instance (for fluid interface) */ public function addStmt($stmt) { $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); return $this; } /** * Adds an attribute group. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return $this The builder instance (for fluid interface) */ public function addAttribute($attribute) { $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } /** * Returns the built function node. * * @return Stmt\Function_ The built function node */ public function getNode(): Node { return new Stmt\Function_($this->name, [ 'byRef' => $this->returnByRef, 'params' => $this->params, 'returnType' => $this->returnType, 'stmts' => $this->stmts, 'attrGroups' => $this->attributeGroups, ], $this->attributes); } } ================================================ FILE: lib/PhpParser/Builder/Interface_.php ================================================ */ protected array $extends = []; /** @var list */ protected array $constants = []; /** @var list */ protected array $methods = []; /** @var list */ protected array $attributeGroups = []; /** * Creates an interface builder. * * @param string $name Name of the interface */ public function __construct(string $name) { $this->name = $name; } /** * Extends one or more interfaces. * * @param Name|string ...$interfaces Names of interfaces to extend * * @return $this The builder instance (for fluid interface) */ public function extend(...$interfaces) { foreach ($interfaces as $interface) { $this->extends[] = BuilderHelpers::normalizeName($interface); } return $this; } /** * Adds a statement. * * @param Stmt|PhpParser\Builder $stmt The statement to add * * @return $this The builder instance (for fluid interface) */ public function addStmt($stmt) { $stmt = BuilderHelpers::normalizeNode($stmt); if ($stmt instanceof Stmt\ClassConst) { $this->constants[] = $stmt; } elseif ($stmt instanceof Stmt\ClassMethod) { // we erase all statements in the body of an interface method $stmt->stmts = null; $this->methods[] = $stmt; } else { throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); } return $this; } /** * Adds an attribute group. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return $this The builder instance (for fluid interface) */ public function addAttribute($attribute) { $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } /** * Returns the built interface node. * * @return Stmt\Interface_ The built interface node */ public function getNode(): PhpParser\Node { return new Stmt\Interface_($this->name, [ 'extends' => $this->extends, 'stmts' => array_merge($this->constants, $this->methods), 'attrGroups' => $this->attributeGroups, ], $this->attributes); } } ================================================ FILE: lib/PhpParser/Builder/Method.php ================================================ |null */ protected ?array $stmts = []; /** @var list */ protected array $attributeGroups = []; /** * Creates a method builder. * * @param string $name Name of the method */ public function __construct(string $name) { $this->name = $name; } /** * Makes the method public. * * @return $this The builder instance (for fluid interface) */ public function makePublic() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PUBLIC); return $this; } /** * Makes the method protected. * * @return $this The builder instance (for fluid interface) */ public function makeProtected() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED); return $this; } /** * Makes the method private. * * @return $this The builder instance (for fluid interface) */ public function makePrivate() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE); return $this; } /** * Makes the method static. * * @return $this The builder instance (for fluid interface) */ public function makeStatic() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::STATIC); return $this; } /** * Makes the method abstract. * * @return $this The builder instance (for fluid interface) */ public function makeAbstract() { if (!empty($this->stmts)) { throw new \LogicException('Cannot make method with statements abstract'); } $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::ABSTRACT); $this->stmts = null; // abstract methods don't have statements return $this; } /** * Makes the method final. * * @return $this The builder instance (for fluid interface) */ public function makeFinal() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::FINAL); return $this; } /** * Adds a statement. * * @param Node|PhpParser\Builder $stmt The statement to add * * @return $this The builder instance (for fluid interface) */ public function addStmt($stmt) { if (null === $this->stmts) { throw new \LogicException('Cannot add statements to an abstract method'); } $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); return $this; } /** * Adds an attribute group. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return $this The builder instance (for fluid interface) */ public function addAttribute($attribute) { $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } /** * Returns the built method node. * * @return Stmt\ClassMethod The built method node */ public function getNode(): Node { return new Stmt\ClassMethod($this->name, [ 'flags' => $this->flags, 'byRef' => $this->returnByRef, 'params' => $this->params, 'returnType' => $this->returnType, 'stmts' => $this->stmts, 'attrGroups' => $this->attributeGroups, ], $this->attributes); } } ================================================ FILE: lib/PhpParser/Builder/Namespace_.php ================================================ name = null !== $name ? BuilderHelpers::normalizeName($name) : null; } /** * Adds a statement. * * @param Node|PhpParser\Builder $stmt The statement to add * * @return $this The builder instance (for fluid interface) */ public function addStmt($stmt) { $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); return $this; } /** * Returns the built node. * * @return Stmt\Namespace_ The built node */ public function getNode(): Node { return new Stmt\Namespace_($this->name, $this->stmts, $this->attributes); } } ================================================ FILE: lib/PhpParser/Builder/Param.php ================================================ */ protected array $attributeGroups = []; /** * Creates a parameter builder. * * @param string $name Name of the parameter */ public function __construct(string $name) { $this->name = $name; } /** * Sets default value for the parameter. * * @param mixed $value Default value to use * * @return $this The builder instance (for fluid interface) */ public function setDefault($value) { $this->default = BuilderHelpers::normalizeValue($value); return $this; } /** * Sets type for the parameter. * * @param string|Node\Name|Node\Identifier|Node\ComplexType $type Parameter type * * @return $this The builder instance (for fluid interface) */ public function setType($type) { $this->type = BuilderHelpers::normalizeType($type); if ($this->type == 'void') { throw new \LogicException('Parameter type cannot be void'); } return $this; } /** * Make the parameter accept the value by reference. * * @return $this The builder instance (for fluid interface) */ public function makeByRef() { $this->byRef = true; return $this; } /** * Make the parameter variadic * * @return $this The builder instance (for fluid interface) */ public function makeVariadic() { $this->variadic = true; return $this; } /** * Makes the (promoted) parameter public. * * @return $this The builder instance (for fluid interface) */ public function makePublic() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PUBLIC); return $this; } /** * Makes the (promoted) parameter protected. * * @return $this The builder instance (for fluid interface) */ public function makeProtected() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED); return $this; } /** * Makes the (promoted) parameter private. * * @return $this The builder instance (for fluid interface) */ public function makePrivate() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE); return $this; } /** * Makes the (promoted) parameter readonly. * * @return $this The builder instance (for fluid interface) */ public function makeReadonly() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::READONLY); return $this; } /** * Gives the promoted property private(set) visibility. * * @return $this The builder instance (for fluid interface) */ public function makePrivateSet() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE_SET); return $this; } /** * Gives the promoted property protected(set) visibility. * * @return $this The builder instance (for fluid interface) */ public function makeProtectedSet() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED_SET); return $this; } /** * Adds an attribute group. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return $this The builder instance (for fluid interface) */ public function addAttribute($attribute) { $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } /** * Returns the built parameter node. * * @return Node\Param The built parameter node */ public function getNode(): Node { return new Node\Param( new Node\Expr\Variable($this->name), $this->default, $this->type, $this->byRef, $this->variadic, [], $this->flags, $this->attributeGroups ); } } ================================================ FILE: lib/PhpParser/Builder/Property.php ================================================ */ protected array $attributes = []; /** @var null|Identifier|Name|ComplexType */ protected ?Node $type = null; /** @var list */ protected array $attributeGroups = []; /** @var list */ protected array $hooks = []; /** * Creates a property builder. * * @param string $name Name of the property */ public function __construct(string $name) { $this->name = $name; } /** * Makes the property public. * * @return $this The builder instance (for fluid interface) */ public function makePublic() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PUBLIC); return $this; } /** * Makes the property protected. * * @return $this The builder instance (for fluid interface) */ public function makeProtected() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED); return $this; } /** * Makes the property private. * * @return $this The builder instance (for fluid interface) */ public function makePrivate() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE); return $this; } /** * Makes the property static. * * @return $this The builder instance (for fluid interface) */ public function makeStatic() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::STATIC); return $this; } /** * Makes the property readonly. * * @return $this The builder instance (for fluid interface) */ public function makeReadonly() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::READONLY); return $this; } /** * Makes the property abstract. Requires at least one property hook to be specified as well. * * @return $this The builder instance (for fluid interface) */ public function makeAbstract() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::ABSTRACT); return $this; } /** * Makes the property final. * * @return $this The builder instance (for fluid interface) */ public function makeFinal() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::FINAL); return $this; } /** * Gives the property private(set) visibility. * * @return $this The builder instance (for fluid interface) */ public function makePrivateSet() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE_SET); return $this; } /** * Gives the property protected(set) visibility. * * @return $this The builder instance (for fluid interface) */ public function makeProtectedSet() { $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED_SET); return $this; } /** * Sets default value for the property. * * @param mixed $value Default value to use * * @return $this The builder instance (for fluid interface) */ public function setDefault($value) { $this->default = BuilderHelpers::normalizeValue($value); return $this; } /** * Sets doc comment for the property. * * @param PhpParser\Comment\Doc|string $docComment Doc comment to set * * @return $this The builder instance (for fluid interface) */ public function setDocComment($docComment) { $this->attributes = [ 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] ]; return $this; } /** * Sets the property type for PHP 7.4+. * * @param string|Name|Identifier|ComplexType $type * * @return $this */ public function setType($type) { $this->type = BuilderHelpers::normalizeType($type); return $this; } /** * Adds an attribute group. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return $this The builder instance (for fluid interface) */ public function addAttribute($attribute) { $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } /** * Adds a property hook. * * @return $this The builder instance (for fluid interface) */ public function addHook(Node\PropertyHook $hook) { $this->hooks[] = $hook; return $this; } /** * Returns the built class node. * * @return Stmt\Property The built property node */ public function getNode(): PhpParser\Node { if ($this->flags & Modifiers::ABSTRACT && !$this->hooks) { throw new PhpParser\Error('Only hooked properties may be declared abstract'); } return new Stmt\Property( $this->flags !== 0 ? $this->flags : Modifiers::PUBLIC, [ new Node\PropertyItem($this->name, $this->default) ], $this->attributes, $this->type, $this->attributeGroups, $this->hooks ); } } ================================================ FILE: lib/PhpParser/Builder/TraitUse.php ================================================ and($trait); } } /** * Adds used trait. * * @param Node\Name|string $trait Trait name * * @return $this The builder instance (for fluid interface) */ public function and($trait) { $this->traits[] = BuilderHelpers::normalizeName($trait); return $this; } /** * Adds trait adaptation. * * @param Stmt\TraitUseAdaptation|Builder\TraitUseAdaptation $adaptation Trait adaptation * * @return $this The builder instance (for fluid interface) */ public function with($adaptation) { $adaptation = BuilderHelpers::normalizeNode($adaptation); if (!$adaptation instanceof Stmt\TraitUseAdaptation) { throw new \LogicException('Adaptation must have type TraitUseAdaptation'); } $this->adaptations[] = $adaptation; return $this; } /** * Returns the built node. * * @return Node The built node */ public function getNode(): Node { return new Stmt\TraitUse($this->traits, $this->adaptations); } } ================================================ FILE: lib/PhpParser/Builder/TraitUseAdaptation.php ================================================ type = self::TYPE_UNDEFINED; $this->trait = is_null($trait) ? null : BuilderHelpers::normalizeName($trait); $this->method = BuilderHelpers::normalizeIdentifier($method); } /** * Sets alias of method. * * @param Node\Identifier|string $alias Alias for adapted method * * @return $this The builder instance (for fluid interface) */ public function as($alias) { if ($this->type === self::TYPE_UNDEFINED) { $this->type = self::TYPE_ALIAS; } if ($this->type !== self::TYPE_ALIAS) { throw new \LogicException('Cannot set alias for not alias adaptation buider'); } $this->alias = BuilderHelpers::normalizeIdentifier($alias); return $this; } /** * Sets adapted method public. * * @return $this The builder instance (for fluid interface) */ public function makePublic() { $this->setModifier(Modifiers::PUBLIC); return $this; } /** * Sets adapted method protected. * * @return $this The builder instance (for fluid interface) */ public function makeProtected() { $this->setModifier(Modifiers::PROTECTED); return $this; } /** * Sets adapted method private. * * @return $this The builder instance (for fluid interface) */ public function makePrivate() { $this->setModifier(Modifiers::PRIVATE); return $this; } /** * Adds overwritten traits. * * @param Node\Name|string ...$traits Traits for overwrite * * @return $this The builder instance (for fluid interface) */ public function insteadof(...$traits) { if ($this->type === self::TYPE_UNDEFINED) { if (is_null($this->trait)) { throw new \LogicException('Precedence adaptation must have trait'); } $this->type = self::TYPE_PRECEDENCE; } if ($this->type !== self::TYPE_PRECEDENCE) { throw new \LogicException('Cannot add overwritten traits for not precedence adaptation buider'); } foreach ($traits as $trait) { $this->insteadof[] = BuilderHelpers::normalizeName($trait); } return $this; } protected function setModifier(int $modifier): void { if ($this->type === self::TYPE_UNDEFINED) { $this->type = self::TYPE_ALIAS; } if ($this->type !== self::TYPE_ALIAS) { throw new \LogicException('Cannot set access modifier for not alias adaptation buider'); } if (is_null($this->modifier)) { $this->modifier = $modifier; } else { throw new \LogicException('Multiple access type modifiers are not allowed'); } } /** * Returns the built node. * * @return Node The built node */ public function getNode(): Node { switch ($this->type) { case self::TYPE_ALIAS: return new Stmt\TraitUseAdaptation\Alias($this->trait, $this->method, $this->modifier, $this->alias); case self::TYPE_PRECEDENCE: return new Stmt\TraitUseAdaptation\Precedence($this->trait, $this->method, $this->insteadof); default: throw new \LogicException('Type of adaptation is not defined'); } } } ================================================ FILE: lib/PhpParser/Builder/Trait_.php ================================================ */ protected array $uses = []; /** @var list */ protected array $constants = []; /** @var list */ protected array $properties = []; /** @var list */ protected array $methods = []; /** @var list */ protected array $attributeGroups = []; /** * Creates an interface builder. * * @param string $name Name of the interface */ public function __construct(string $name) { $this->name = $name; } /** * Adds a statement. * * @param Stmt|PhpParser\Builder $stmt The statement to add * * @return $this The builder instance (for fluid interface) */ public function addStmt($stmt) { $stmt = BuilderHelpers::normalizeNode($stmt); if ($stmt instanceof Stmt\Property) { $this->properties[] = $stmt; } elseif ($stmt instanceof Stmt\ClassMethod) { $this->methods[] = $stmt; } elseif ($stmt instanceof Stmt\TraitUse) { $this->uses[] = $stmt; } elseif ($stmt instanceof Stmt\ClassConst) { $this->constants[] = $stmt; } else { throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); } return $this; } /** * Adds an attribute group. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return $this The builder instance (for fluid interface) */ public function addAttribute($attribute) { $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } /** * Returns the built trait node. * * @return Stmt\Trait_ The built interface node */ public function getNode(): PhpParser\Node { return new Stmt\Trait_( $this->name, [ 'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods), 'attrGroups' => $this->attributeGroups, ], $this->attributes ); } } ================================================ FILE: lib/PhpParser/Builder/Use_.php ================================================ name = BuilderHelpers::normalizeName($name); $this->type = $type; } /** * Sets alias for used name. * * @param string $alias Alias to use (last component of full name by default) * * @return $this The builder instance (for fluid interface) */ public function as(string $alias) { $this->alias = $alias; return $this; } /** * Returns the built node. * * @return Stmt\Use_ The built node */ public function getNode(): Node { return new Stmt\Use_([ new Node\UseItem($this->name, $this->alias) ], $this->type); } } ================================================ FILE: lib/PhpParser/Builder.php ================================================ args($args) ); } /** * Creates a namespace builder. * * @param null|string|Node\Name $name Name of the namespace * * @return Builder\Namespace_ The created namespace builder */ public function namespace($name): Builder\Namespace_ { return new Builder\Namespace_($name); } /** * Creates a class builder. * * @param string $name Name of the class * * @return Builder\Class_ The created class builder */ public function class(string $name): Builder\Class_ { return new Builder\Class_($name); } /** * Creates an interface builder. * * @param string $name Name of the interface * * @return Builder\Interface_ The created interface builder */ public function interface(string $name): Builder\Interface_ { return new Builder\Interface_($name); } /** * Creates a trait builder. * * @param string $name Name of the trait * * @return Builder\Trait_ The created trait builder */ public function trait(string $name): Builder\Trait_ { return new Builder\Trait_($name); } /** * Creates an enum builder. * * @param string $name Name of the enum * * @return Builder\Enum_ The created enum builder */ public function enum(string $name): Builder\Enum_ { return new Builder\Enum_($name); } /** * Creates a trait use builder. * * @param Node\Name|string ...$traits Trait names * * @return Builder\TraitUse The created trait use builder */ public function useTrait(...$traits): Builder\TraitUse { return new Builder\TraitUse(...$traits); } /** * Creates a trait use adaptation builder. * * @param Node\Name|string|null $trait Trait name * @param Node\Identifier|string $method Method name * * @return Builder\TraitUseAdaptation The created trait use adaptation builder */ public function traitUseAdaptation($trait, $method = null): Builder\TraitUseAdaptation { if ($method === null) { $method = $trait; $trait = null; } return new Builder\TraitUseAdaptation($trait, $method); } /** * Creates a method builder. * * @param string $name Name of the method * * @return Builder\Method The created method builder */ public function method(string $name): Builder\Method { return new Builder\Method($name); } /** * Creates a parameter builder. * * @param string $name Name of the parameter * * @return Builder\Param The created parameter builder */ public function param(string $name): Builder\Param { return new Builder\Param($name); } /** * Creates a property builder. * * @param string $name Name of the property * * @return Builder\Property The created property builder */ public function property(string $name): Builder\Property { return new Builder\Property($name); } /** * Creates a function builder. * * @param string $name Name of the function * * @return Builder\Function_ The created function builder */ public function function(string $name): Builder\Function_ { return new Builder\Function_($name); } /** * Creates a namespace/class use builder. * * @param Node\Name|string $name Name of the entity (namespace or class) to alias * * @return Builder\Use_ The created use builder */ public function use($name): Builder\Use_ { return new Builder\Use_($name, Use_::TYPE_NORMAL); } /** * Creates a function use builder. * * @param Node\Name|string $name Name of the function to alias * * @return Builder\Use_ The created use function builder */ public function useFunction($name): Builder\Use_ { return new Builder\Use_($name, Use_::TYPE_FUNCTION); } /** * Creates a constant use builder. * * @param Node\Name|string $name Name of the const to alias * * @return Builder\Use_ The created use const builder */ public function useConst($name): Builder\Use_ { return new Builder\Use_($name, Use_::TYPE_CONSTANT); } /** * Creates a class constant builder. * * @param string|Identifier $name Name * @param Node\Expr|bool|null|int|float|string|array $value Value * * @return Builder\ClassConst The created use const builder */ public function classConst($name, $value): Builder\ClassConst { return new Builder\ClassConst($name, $value); } /** * Creates an enum case builder. * * @param string|Identifier $name Name * * @return Builder\EnumCase The created use const builder */ public function enumCase($name): Builder\EnumCase { return new Builder\EnumCase($name); } /** * Creates node a for a literal value. * * @param Expr|bool|null|int|float|string|array|\UnitEnum $value $value */ public function val($value): Expr { return BuilderHelpers::normalizeValue($value); } /** * Creates variable node. * * @param string|Expr $name Name */ public function var($name): Expr\Variable { if (!\is_string($name) && !$name instanceof Expr) { throw new \LogicException('Variable name must be string or Expr'); } return new Expr\Variable($name); } /** * Normalizes an argument list. * * Creates Arg nodes for all arguments and converts literal values to expressions. * * @param array $args List of arguments to normalize * * @return list */ public function args(array $args): array { $normalizedArgs = []; foreach ($args as $key => $arg) { if (!($arg instanceof Arg)) { $arg = new Arg(BuilderHelpers::normalizeValue($arg)); } if (\is_string($key)) { $arg->name = BuilderHelpers::normalizeIdentifier($key); } $normalizedArgs[] = $arg; } return $normalizedArgs; } /** * Creates a function call node. * * @param string|Name|Expr $name Function name * @param array $args Function arguments */ public function funcCall($name, array $args = []): Expr\FuncCall { return new Expr\FuncCall( BuilderHelpers::normalizeNameOrExpr($name), $this->args($args) ); } /** * Creates a method call node. * * @param Expr $var Variable the method is called on * @param string|Identifier|Expr $name Method name * @param array $args Method arguments */ public function methodCall(Expr $var, $name, array $args = []): Expr\MethodCall { return new Expr\MethodCall( $var, BuilderHelpers::normalizeIdentifierOrExpr($name), $this->args($args) ); } /** * Creates a static method call node. * * @param string|Name|Expr $class Class name * @param string|Identifier|Expr $name Method name * @param array $args Method arguments */ public function staticCall($class, $name, array $args = []): Expr\StaticCall { return new Expr\StaticCall( BuilderHelpers::normalizeNameOrExpr($class), BuilderHelpers::normalizeIdentifierOrExpr($name), $this->args($args) ); } /** * Creates an object creation node. * * @param string|Name|Expr $class Class name * @param array $args Constructor arguments */ public function new($class, array $args = []): Expr\New_ { return new Expr\New_( BuilderHelpers::normalizeNameOrExpr($class), $this->args($args) ); } /** * Creates a constant fetch node. * * @param string|Name $name Constant name */ public function constFetch($name): Expr\ConstFetch { return new Expr\ConstFetch(BuilderHelpers::normalizeName($name)); } /** * Creates a property fetch node. * * @param Expr $var Variable holding object * @param string|Identifier|Expr $name Property name */ public function propertyFetch(Expr $var, $name): Expr\PropertyFetch { return new Expr\PropertyFetch($var, BuilderHelpers::normalizeIdentifierOrExpr($name)); } /** * Creates a class constant fetch node. * * @param string|Name|Expr $class Class name * @param string|Identifier|Expr $name Constant name */ public function classConstFetch($class, $name): Expr\ClassConstFetch { return new Expr\ClassConstFetch( BuilderHelpers::normalizeNameOrExpr($class), BuilderHelpers::normalizeIdentifierOrExpr($name) ); } /** * Creates nested Concat nodes from a list of expressions. * * @param Expr|string ...$exprs Expressions or literal strings */ public function concat(...$exprs): Concat { $numExprs = count($exprs); if ($numExprs < 2) { throw new \LogicException('Expected at least two expressions'); } $lastConcat = $this->normalizeStringExpr($exprs[0]); for ($i = 1; $i < $numExprs; $i++) { $lastConcat = new Concat($lastConcat, $this->normalizeStringExpr($exprs[$i])); } return $lastConcat; } /** * @param string|Expr $expr */ private function normalizeStringExpr($expr): Expr { if ($expr instanceof Expr) { return $expr; } if (\is_string($expr)) { return new String_($expr); } throw new \LogicException('Expected string or Expr'); } } ================================================ FILE: lib/PhpParser/BuilderHelpers.php ================================================ getNode(); } if ($node instanceof Node) { return $node; } throw new \LogicException('Expected node or builder object'); } /** * Normalizes a node to a statement. * * Expressions are wrapped in a Stmt\Expression node. * * @param Node|Builder $node The node to normalize * * @return Stmt The normalized statement node */ public static function normalizeStmt($node): Stmt { $node = self::normalizeNode($node); if ($node instanceof Stmt) { return $node; } if ($node instanceof Expr) { return new Stmt\Expression($node); } throw new \LogicException('Expected statement or expression node'); } /** * Normalizes strings to Identifier. * * @param string|Identifier $name The identifier to normalize * * @return Identifier The normalized identifier */ public static function normalizeIdentifier($name): Identifier { if ($name instanceof Identifier) { return $name; } if (\is_string($name)) { return new Identifier($name); } throw new \LogicException('Expected string or instance of Node\Identifier'); } /** * Normalizes strings to Identifier, also allowing expressions. * * @param string|Identifier|Expr $name The identifier to normalize * * @return Identifier|Expr The normalized identifier or expression */ public static function normalizeIdentifierOrExpr($name) { if ($name instanceof Identifier || $name instanceof Expr) { return $name; } if (\is_string($name)) { return new Identifier($name); } throw new \LogicException('Expected string or instance of Node\Identifier or Node\Expr'); } /** * Normalizes a name: Converts string names to Name nodes. * * @param Name|string $name The name to normalize * * @return Name The normalized name */ public static function normalizeName($name): Name { if ($name instanceof Name) { return $name; } if (is_string($name)) { if (!$name) { throw new \LogicException('Name cannot be empty'); } if ($name[0] === '\\') { return new Name\FullyQualified(substr($name, 1)); } if (0 === strpos($name, 'namespace\\')) { return new Name\Relative(substr($name, strlen('namespace\\'))); } return new Name($name); } throw new \LogicException('Name must be a string or an instance of Node\Name'); } /** * Normalizes a name: Converts string names to Name nodes, while also allowing expressions. * * @param Expr|Name|string $name The name to normalize * * @return Name|Expr The normalized name or expression */ public static function normalizeNameOrExpr($name) { if ($name instanceof Expr) { return $name; } if (!is_string($name) && !($name instanceof Name)) { throw new \LogicException( 'Name must be a string or an instance of Node\Name or Node\Expr' ); } return self::normalizeName($name); } /** * Normalizes a type: Converts plain-text type names into proper AST representation. * * In particular, builtin types become Identifiers, custom types become Names and nullables * are wrapped in NullableType nodes. * * @param string|Name|Identifier|ComplexType $type The type to normalize * * @return Name|Identifier|ComplexType The normalized type */ public static function normalizeType($type) { if (!is_string($type)) { if ( !$type instanceof Name && !$type instanceof Identifier && !$type instanceof ComplexType ) { throw new \LogicException( 'Type must be a string, or an instance of Name, Identifier or ComplexType' ); } return $type; } $nullable = false; if (strlen($type) > 0 && $type[0] === '?') { $nullable = true; $type = substr($type, 1); } $builtinTypes = [ 'array', 'callable', 'bool', 'int', 'float', 'string', 'iterable', 'void', 'object', 'null', 'false', 'mixed', 'never', 'true', ]; $lowerType = strtolower($type); if (in_array($lowerType, $builtinTypes)) { $type = new Identifier($lowerType); } else { $type = self::normalizeName($type); } $notNullableTypes = [ 'void', 'mixed', 'never', ]; if ($nullable && in_array((string) $type, $notNullableTypes)) { throw new \LogicException(sprintf('%s type cannot be nullable', $type)); } return $nullable ? new NullableType($type) : $type; } /** * Normalizes a value: Converts nulls, booleans, integers, * floats, strings and arrays into their respective nodes * * @param Node\Expr|bool|null|int|float|string|array|\UnitEnum $value The value to normalize * * @return Expr The normalized value */ public static function normalizeValue($value): Expr { if ($value instanceof Node\Expr) { return $value; } if (is_null($value)) { return new Expr\ConstFetch( new Name('null') ); } if (is_bool($value)) { return new Expr\ConstFetch( new Name($value ? 'true' : 'false') ); } if (is_int($value)) { return new Scalar\Int_($value); } if (is_float($value)) { return new Scalar\Float_($value); } if (is_string($value)) { return new Scalar\String_($value); } if (is_array($value)) { $items = []; $lastKey = -1; foreach ($value as $itemKey => $itemValue) { // for consecutive, numeric keys don't generate keys if (null !== $lastKey && ++$lastKey === $itemKey) { $items[] = new Node\ArrayItem( self::normalizeValue($itemValue) ); } else { $lastKey = null; $items[] = new Node\ArrayItem( self::normalizeValue($itemValue), self::normalizeValue($itemKey) ); } } return new Expr\Array_($items); } if ($value instanceof \UnitEnum) { return new Expr\ClassConstFetch(new FullyQualified(\get_class($value)), new Identifier($value->name)); } throw new \LogicException('Invalid value'); } /** * Normalizes a doc comment: Converts plain strings to PhpParser\Comment\Doc. * * @param Comment\Doc|string $docComment The doc comment to normalize * * @return Comment\Doc The normalized doc comment */ public static function normalizeDocComment($docComment): Comment\Doc { if ($docComment instanceof Comment\Doc) { return $docComment; } if (is_string($docComment)) { return new Comment\Doc($docComment); } throw new \LogicException('Doc comment must be a string or an instance of PhpParser\Comment\Doc'); } /** * Normalizes a attribute: Converts attribute to the Attribute Group if needed. * * @param Node\Attribute|Node\AttributeGroup $attribute * * @return Node\AttributeGroup The Attribute Group */ public static function normalizeAttribute($attribute): Node\AttributeGroup { if ($attribute instanceof Node\AttributeGroup) { return $attribute; } if (!($attribute instanceof Node\Attribute)) { throw new \LogicException('Attribute must be an instance of PhpParser\Node\Attribute or PhpParser\Node\AttributeGroup'); } return new Node\AttributeGroup([$attribute]); } /** * Adds a modifier and returns new modifier bitmask. * * @param int $modifiers Existing modifiers * @param int $modifier Modifier to set * * @return int New modifiers */ public static function addModifier(int $modifiers, int $modifier): int { Modifiers::verifyModifier($modifiers, $modifier); return $modifiers | $modifier; } /** * Adds a modifier and returns new modifier bitmask. * @return int New modifiers */ public static function addClassModifier(int $existingModifiers, int $modifierToSet): int { Modifiers::verifyClassModifier($existingModifiers, $modifierToSet); return $existingModifiers | $modifierToSet; } } ================================================ FILE: lib/PhpParser/Comment/Doc.php ================================================ text = $text; $this->startLine = $startLine; $this->startFilePos = $startFilePos; $this->startTokenPos = $startTokenPos; $this->endLine = $endLine; $this->endFilePos = $endFilePos; $this->endTokenPos = $endTokenPos; } /** * Gets the comment text. * * @return string The comment text (including comment delimiters like /*) */ public function getText(): string { return $this->text; } /** * Gets the line number the comment started on. * * @return int Line number (or -1 if not available) * @phpstan-return -1|positive-int */ public function getStartLine(): int { return $this->startLine; } /** * Gets the file offset the comment started on. * * @return int File offset (or -1 if not available) */ public function getStartFilePos(): int { return $this->startFilePos; } /** * Gets the token offset the comment started on. * * @return int Token offset (or -1 if not available) */ public function getStartTokenPos(): int { return $this->startTokenPos; } /** * Gets the line number the comment ends on. * * @return int Line number (or -1 if not available) * @phpstan-return -1|positive-int */ public function getEndLine(): int { return $this->endLine; } /** * Gets the file offset the comment ends on. * * @return int File offset (or -1 if not available) */ public function getEndFilePos(): int { return $this->endFilePos; } /** * Gets the token offset the comment ends on. * * @return int Token offset (or -1 if not available) */ public function getEndTokenPos(): int { return $this->endTokenPos; } /** * Gets the comment text. * * @return string The comment text (including comment delimiters like /*) */ public function __toString(): string { return $this->text; } /** * Gets the reformatted comment text. * * "Reformatted" here means that we try to clean up the whitespace at the * starts of the lines. This is necessary because we receive the comments * without leading whitespace on the first line, but with leading whitespace * on all subsequent lines. * * Additionally, this normalizes CRLF newlines to LF newlines. */ public function getReformattedText(): string { $text = str_replace("\r\n", "\n", $this->text); $newlinePos = strpos($text, "\n"); if (false === $newlinePos) { // Single line comments don't need further processing return $text; } if (preg_match('(^.*(?:\n\s+\*.*)+$)', $text)) { // Multi line comment of the type // // /* // * Some text. // * Some more text. // */ // // is handled by replacing the whitespace sequences before the * by a single space return preg_replace('(^\s+\*)m', ' *', $text); } if (preg_match('(^/\*\*?\s*\n)', $text) && preg_match('(\n(\s*)\*/$)', $text, $matches)) { // Multi line comment of the type // // /* // Some text. // Some more text. // */ // // is handled by removing the whitespace sequence on the line before the closing // */ on all lines. So if the last line is " */", then " " is removed at the // start of all lines. return preg_replace('(^' . preg_quote($matches[1]) . ')m', '', $text); } if (preg_match('(^/\*\*?\s*(?!\s))', $text, $matches)) { // Multi line comment of the type // // /* Some text. // Some more text. // Indented text. // Even more text. */ // // is handled by removing the difference between the shortest whitespace prefix on all // lines and the length of the "/* " opening sequence. $prefixLen = $this->getShortestWhitespacePrefixLen(substr($text, $newlinePos + 1)); $removeLen = $prefixLen - strlen($matches[0]); return preg_replace('(^\s{' . $removeLen . '})m', '', $text); } // No idea how to format this comment, so simply return as is return $text; } /** * Get length of shortest whitespace prefix (at the start of a line). * * If there is a line with no prefix whitespace, 0 is a valid return value. * * @param string $str String to check * @return int Length in characters. Tabs count as single characters. */ private function getShortestWhitespacePrefixLen(string $str): int { $lines = explode("\n", $str); $shortestPrefixLen = \PHP_INT_MAX; foreach ($lines as $line) { preg_match('(^\s*)', $line, $matches); $prefixLen = strlen($matches[0]); if ($prefixLen < $shortestPrefixLen) { $shortestPrefixLen = $prefixLen; } } return $shortestPrefixLen; } /** * @return array{nodeType:string, text:mixed, line:mixed, filePos:mixed} */ public function jsonSerialize(): array { // Technically not a node, but we make it look like one anyway $type = $this instanceof Comment\Doc ? 'Comment_Doc' : 'Comment'; return [ 'nodeType' => $type, 'text' => $this->text, // TODO: Rename these to include "start". 'line' => $this->startLine, 'filePos' => $this->startFilePos, 'tokenPos' => $this->startTokenPos, 'endLine' => $this->endLine, 'endFilePos' => $this->endFilePos, 'endTokenPos' => $this->endTokenPos, ]; } } ================================================ FILE: lib/PhpParser/ConstExprEvaluationException.php ================================================ fallbackEvaluator = $fallbackEvaluator ?? function (Expr $expr) { throw new ConstExprEvaluationException( "Expression of type {$expr->getType()} cannot be evaluated" ); }; } /** * Silently evaluates a constant expression into a PHP value. * * Thrown Errors, warnings or notices will be converted into a ConstExprEvaluationException. * The original source of the exception is available through getPrevious(). * * If some part of the expression cannot be evaluated, the fallback evaluator passed to the * constructor will be invoked. By default, if no fallback is provided, an exception of type * ConstExprEvaluationException is thrown. * * See class doc comment for caveats and limitations. * * @param Expr $expr Constant expression to evaluate * @return mixed Result of evaluation * * @throws ConstExprEvaluationException if the expression cannot be evaluated or an error occurred */ public function evaluateSilently(Expr $expr) { set_error_handler(function ($num, $str, $file, $line) { throw new \ErrorException($str, 0, $num, $file, $line); }); try { return $this->evaluate($expr); } catch (\Throwable $e) { if (!$e instanceof ConstExprEvaluationException) { $e = new ConstExprEvaluationException( "An error occurred during constant expression evaluation", 0, $e); } throw $e; } finally { restore_error_handler(); } } /** * Directly evaluates a constant expression into a PHP value. * * May generate Error exceptions, warnings or notices. Use evaluateSilently() to convert these * into a ConstExprEvaluationException. * * If some part of the expression cannot be evaluated, the fallback evaluator passed to the * constructor will be invoked. By default, if no fallback is provided, an exception of type * ConstExprEvaluationException is thrown. * * See class doc comment for caveats and limitations. * * @param Expr $expr Constant expression to evaluate * @return mixed Result of evaluation * * @throws ConstExprEvaluationException if the expression cannot be evaluated */ public function evaluateDirectly(Expr $expr) { return $this->evaluate($expr); } /** @return mixed */ private function evaluate(Expr $expr) { if ($expr instanceof Scalar\Int_ || $expr instanceof Scalar\Float_ || $expr instanceof Scalar\String_ ) { return $expr->value; } if ($expr instanceof Expr\Array_) { return $this->evaluateArray($expr); } // Unary operators if ($expr instanceof Expr\UnaryPlus) { return +$this->evaluate($expr->expr); } if ($expr instanceof Expr\UnaryMinus) { return -$this->evaluate($expr->expr); } if ($expr instanceof Expr\BooleanNot) { return !$this->evaluate($expr->expr); } if ($expr instanceof Expr\BitwiseNot) { return ~$this->evaluate($expr->expr); } if ($expr instanceof Expr\BinaryOp) { return $this->evaluateBinaryOp($expr); } if ($expr instanceof Expr\Ternary) { return $this->evaluateTernary($expr); } if ($expr instanceof Expr\ArrayDimFetch && null !== $expr->dim) { return $this->evaluate($expr->var)[$this->evaluate($expr->dim)]; } if ($expr instanceof Expr\ConstFetch) { return $this->evaluateConstFetch($expr); } return ($this->fallbackEvaluator)($expr); } private function evaluateArray(Expr\Array_ $expr): array { $array = []; foreach ($expr->items as $item) { if (null !== $item->key) { $array[$this->evaluate($item->key)] = $this->evaluate($item->value); } elseif ($item->unpack) { $array = array_merge($array, $this->evaluate($item->value)); } else { $array[] = $this->evaluate($item->value); } } return $array; } /** @return mixed */ private function evaluateTernary(Expr\Ternary $expr) { if (null === $expr->if) { return $this->evaluate($expr->cond) ?: $this->evaluate($expr->else); } return $this->evaluate($expr->cond) ? $this->evaluate($expr->if) : $this->evaluate($expr->else); } /** @return mixed */ private function evaluateBinaryOp(Expr\BinaryOp $expr) { if ($expr instanceof Expr\BinaryOp\Coalesce && $expr->left instanceof Expr\ArrayDimFetch ) { // This needs to be special cased to respect BP_VAR_IS fetch semantics return $this->evaluate($expr->left->var)[$this->evaluate($expr->left->dim)] ?? $this->evaluate($expr->right); } // The evaluate() calls are repeated in each branch, because some of the operators are // short-circuiting and evaluating the RHS in advance may be illegal in that case $l = $expr->left; $r = $expr->right; switch ($expr->getOperatorSigil()) { case '&': return $this->evaluate($l) & $this->evaluate($r); case '|': return $this->evaluate($l) | $this->evaluate($r); case '^': return $this->evaluate($l) ^ $this->evaluate($r); case '&&': return $this->evaluate($l) && $this->evaluate($r); case '||': return $this->evaluate($l) || $this->evaluate($r); case '??': return $this->evaluate($l) ?? $this->evaluate($r); case '.': return $this->evaluate($l) . $this->evaluate($r); case '/': return $this->evaluate($l) / $this->evaluate($r); case '==': return $this->evaluate($l) == $this->evaluate($r); case '>': return $this->evaluate($l) > $this->evaluate($r); case '>=': return $this->evaluate($l) >= $this->evaluate($r); case '===': return $this->evaluate($l) === $this->evaluate($r); case 'and': return $this->evaluate($l) and $this->evaluate($r); case 'or': return $this->evaluate($l) or $this->evaluate($r); case 'xor': return $this->evaluate($l) xor $this->evaluate($r); case '-': return $this->evaluate($l) - $this->evaluate($r); case '%': return $this->evaluate($l) % $this->evaluate($r); case '*': return $this->evaluate($l) * $this->evaluate($r); case '!=': return $this->evaluate($l) != $this->evaluate($r); case '!==': return $this->evaluate($l) !== $this->evaluate($r); case '+': return $this->evaluate($l) + $this->evaluate($r); case '**': return $this->evaluate($l) ** $this->evaluate($r); case '<<': return $this->evaluate($l) << $this->evaluate($r); case '>>': return $this->evaluate($l) >> $this->evaluate($r); case '<': return $this->evaluate($l) < $this->evaluate($r); case '<=': return $this->evaluate($l) <= $this->evaluate($r); case '<=>': return $this->evaluate($l) <=> $this->evaluate($r); case '|>': $lval = $this->evaluate($l); return $this->evaluate($r)($lval); } throw new \Exception('Should not happen'); } /** @return mixed */ private function evaluateConstFetch(Expr\ConstFetch $expr) { $name = $expr->name->toLowerString(); switch ($name) { case 'null': return null; case 'false': return false; case 'true': return true; } return ($this->fallbackEvaluator)($expr); } } ================================================ FILE: lib/PhpParser/Error.php ================================================ */ protected array $attributes; /** * Creates an Exception signifying a parse error. * * @param string $message Error message * @param array $attributes Attributes of node/token where error occurred */ public function __construct(string $message, array $attributes = []) { $this->rawMessage = $message; $this->attributes = $attributes; $this->updateMessage(); } /** * Gets the error message * * @return string Error message */ public function getRawMessage(): string { return $this->rawMessage; } /** * Gets the line the error starts in. * * @return int Error start line * @phpstan-return -1|positive-int */ public function getStartLine(): int { return $this->attributes['startLine'] ?? -1; } /** * Gets the line the error ends in. * * @return int Error end line * @phpstan-return -1|positive-int */ public function getEndLine(): int { return $this->attributes['endLine'] ?? -1; } /** * Gets the attributes of the node/token the error occurred at. * * @return array */ public function getAttributes(): array { return $this->attributes; } /** * Sets the attributes of the node/token the error occurred at. * * @param array $attributes */ public function setAttributes(array $attributes): void { $this->attributes = $attributes; $this->updateMessage(); } /** * Sets the line of the PHP file the error occurred in. * * @param string $message Error message */ public function setRawMessage(string $message): void { $this->rawMessage = $message; $this->updateMessage(); } /** * Sets the line the error starts in. * * @param int $line Error start line */ public function setStartLine(int $line): void { $this->attributes['startLine'] = $line; $this->updateMessage(); } /** * Returns whether the error has start and end column information. * * For column information enable the startFilePos and endFilePos in the lexer options. */ public function hasColumnInfo(): bool { return isset($this->attributes['startFilePos'], $this->attributes['endFilePos']); } /** * Gets the start column (1-based) into the line where the error started. * * @param string $code Source code of the file */ public function getStartColumn(string $code): int { if (!$this->hasColumnInfo()) { throw new \RuntimeException('Error does not have column information'); } return $this->toColumn($code, $this->attributes['startFilePos']); } /** * Gets the end column (1-based) into the line where the error ended. * * @param string $code Source code of the file */ public function getEndColumn(string $code): int { if (!$this->hasColumnInfo()) { throw new \RuntimeException('Error does not have column information'); } return $this->toColumn($code, $this->attributes['endFilePos']); } /** * Formats message including line and column information. * * @param string $code Source code associated with the error, for calculation of the columns * * @return string Formatted message */ public function getMessageWithColumnInfo(string $code): string { return sprintf( '%s from %d:%d to %d:%d', $this->getRawMessage(), $this->getStartLine(), $this->getStartColumn($code), $this->getEndLine(), $this->getEndColumn($code) ); } /** * Converts a file offset into a column. * * @param string $code Source code that $pos indexes into * @param int $pos 0-based position in $code * * @return int 1-based column (relative to start of line) */ private function toColumn(string $code, int $pos): int { if ($pos > strlen($code)) { throw new \RuntimeException('Invalid position information'); } $lineStartPos = strrpos($code, "\n", $pos - strlen($code)); if (false === $lineStartPos) { $lineStartPos = -1; } return $pos - $lineStartPos; } /** * Updates the exception message after a change to rawMessage or rawLine. */ protected function updateMessage(): void { $this->message = $this->rawMessage; if (-1 === $this->getStartLine()) { $this->message .= ' on unknown line'; } else { $this->message .= ' on line ' . $this->getStartLine(); } } } ================================================ FILE: lib/PhpParser/ErrorHandler/Collecting.php ================================================ errors[] = $error; } /** * Get collected errors. * * @return Error[] */ public function getErrors(): array { return $this->errors; } /** * Check whether there are any errors. */ public function hasErrors(): bool { return !empty($this->errors); } /** * Reset/clear collected errors. */ public function clearErrors(): void { $this->errors = []; } } ================================================ FILE: lib/PhpParser/ErrorHandler/Throwing.php ================================================ type = $type; $this->old = $old; $this->new = $new; } } ================================================ FILE: lib/PhpParser/Internal/Differ.php ================================================ isEqual = $isEqual; } /** * Calculate diff (edit script) from $old to $new. * * @param T[] $old Original array * @param T[] $new New array * * @return DiffElem[] Diff (edit script) */ public function diff(array $old, array $new): array { $old = \array_values($old); $new = \array_values($new); list($trace, $x, $y) = $this->calculateTrace($old, $new); return $this->extractDiff($trace, $x, $y, $old, $new); } /** * Calculate diff, including "replace" operations. * * If a sequence of remove operations is followed by the same number of add operations, these * will be coalesced into replace operations. * * @param T[] $old Original array * @param T[] $new New array * * @return DiffElem[] Diff (edit script), including replace operations */ public function diffWithReplacements(array $old, array $new): array { return $this->coalesceReplacements($this->diff($old, $new)); } /** * @param T[] $old * @param T[] $new * @return array{array>, int, int} */ private function calculateTrace(array $old, array $new): array { $n = \count($old); $m = \count($new); $max = $n + $m; $v = [1 => 0]; $trace = []; for ($d = 0; $d <= $max; $d++) { $trace[] = $v; for ($k = -$d; $k <= $d; $k += 2) { if ($k === -$d || ($k !== $d && $v[$k - 1] < $v[$k + 1])) { $x = $v[$k + 1]; } else { $x = $v[$k - 1] + 1; } $y = $x - $k; while ($x < $n && $y < $m && ($this->isEqual)($old[$x], $new[$y])) { $x++; $y++; } $v[$k] = $x; if ($x >= $n && $y >= $m) { return [$trace, $x, $y]; } } } throw new \Exception('Should not happen'); } /** * @param array> $trace * @param T[] $old * @param T[] $new * @return DiffElem[] */ private function extractDiff(array $trace, int $x, int $y, array $old, array $new): array { $result = []; for ($d = \count($trace) - 1; $d >= 0; $d--) { $v = $trace[$d]; $k = $x - $y; if ($k === -$d || ($k !== $d && $v[$k - 1] < $v[$k + 1])) { $prevK = $k + 1; } else { $prevK = $k - 1; } $prevX = $v[$prevK]; $prevY = $prevX - $prevK; while ($x > $prevX && $y > $prevY) { $result[] = new DiffElem(DiffElem::TYPE_KEEP, $old[$x - 1], $new[$y - 1]); $x--; $y--; } if ($d === 0) { break; } while ($x > $prevX) { $result[] = new DiffElem(DiffElem::TYPE_REMOVE, $old[$x - 1], null); $x--; } while ($y > $prevY) { $result[] = new DiffElem(DiffElem::TYPE_ADD, null, $new[$y - 1]); $y--; } } return array_reverse($result); } /** * Coalesce equal-length sequences of remove+add into a replace operation. * * @param DiffElem[] $diff * @return DiffElem[] */ private function coalesceReplacements(array $diff): array { $newDiff = []; $c = \count($diff); for ($i = 0; $i < $c; $i++) { $diffType = $diff[$i]->type; if ($diffType !== DiffElem::TYPE_REMOVE) { $newDiff[] = $diff[$i]; continue; } $j = $i; while ($j < $c && $diff[$j]->type === DiffElem::TYPE_REMOVE) { $j++; } $k = $j; while ($k < $c && $diff[$k]->type === DiffElem::TYPE_ADD) { $k++; } if ($j - $i === $k - $j) { $len = $j - $i; for ($n = 0; $n < $len; $n++) { $newDiff[] = new DiffElem( DiffElem::TYPE_REPLACE, $diff[$i + $n]->old, $diff[$j + $n]->new ); } } else { for (; $i < $k; $i++) { $newDiff[] = $diff[$i]; } } $i = $k - 1; } return $newDiff; } } ================================================ FILE: lib/PhpParser/Internal/PrintableNewAnonClassNode.php ================================================ $attributes Attributes */ public function __construct( array $attrGroups, int $flags, array $args, ?Node\Name $extends, array $implements, array $stmts, array $attributes ) { parent::__construct($attributes); $this->attrGroups = $attrGroups; $this->flags = $flags; $this->args = $args; $this->extends = $extends; $this->implements = $implements; $this->stmts = $stmts; } public static function fromNewNode(Expr\New_ $newNode): self { $class = $newNode->class; assert($class instanceof Node\Stmt\Class_); // We don't assert that $class->name is null here, to allow consumers to assign unique names // to anonymous classes for their own purposes. We simplify ignore the name here. return new self( $class->attrGroups, $class->flags, $newNode->args, $class->extends, $class->implements, $class->stmts, $newNode->getAttributes() ); } public function getType(): string { return 'Expr_PrintableNewAnonClass'; } public function getSubNodeNames(): array { return ['attrGroups', 'flags', 'args', 'extends', 'implements', 'stmts']; } } ================================================ FILE: lib/PhpParser/Internal/TokenPolyfill.php ================================================ = 80000) { class TokenPolyfill extends \PhpToken { } return; } /** * This is a polyfill for the PhpToken class introduced in PHP 8.0. We do not actually polyfill * PhpToken, because composer might end up picking a different polyfill implementation, which does * not meet our requirements. * * @internal */ class TokenPolyfill { /** @var int The ID of the token. Either a T_* constant of a character code < 256. */ public int $id; /** @var string The textual content of the token. */ public string $text; /** @var int The 1-based starting line of the token (or -1 if unknown). */ public int $line; /** @var int The 0-based starting position of the token (or -1 if unknown). */ public int $pos; /** @var array Tokens ignored by the PHP parser. */ private const IGNORABLE_TOKENS = [ \T_WHITESPACE => true, \T_COMMENT => true, \T_DOC_COMMENT => true, \T_OPEN_TAG => true, ]; /** @var array Tokens that may be part of a T_NAME_* identifier. */ private static array $identifierTokens; /** * Create a Token with the given ID and text, as well optional line and position information. */ final public function __construct(int $id, string $text, int $line = -1, int $pos = -1) { $this->id = $id; $this->text = $text; $this->line = $line; $this->pos = $pos; } /** * Get the name of the token. For single-char tokens this will be the token character. * Otherwise it will be a T_* style name, or null if the token ID is unknown. */ public function getTokenName(): ?string { if ($this->id < 256) { return \chr($this->id); } $name = token_name($this->id); return $name === 'UNKNOWN' ? null : $name; } /** * Check whether the token is of the given kind. The kind may be either an integer that matches * the token ID, a string that matches the token text, or an array of integers/strings. In the * latter case, the function returns true if any of the kinds in the array match. * * @param int|string|(int|string)[] $kind */ public function is($kind): bool { if (\is_int($kind)) { return $this->id === $kind; } if (\is_string($kind)) { return $this->text === $kind; } if (\is_array($kind)) { foreach ($kind as $entry) { if (\is_int($entry)) { if ($this->id === $entry) { return true; } } elseif (\is_string($entry)) { if ($this->text === $entry) { return true; } } else { throw new \TypeError( 'Argument #1 ($kind) must only have elements of type string|int, ' . gettype($entry) . ' given'); } } return false; } throw new \TypeError( 'Argument #1 ($kind) must be of type string|int|array, ' .gettype($kind) . ' given'); } /** * Check whether this token would be ignored by the PHP parser. Returns true for T_WHITESPACE, * T_COMMENT, T_DOC_COMMENT and T_OPEN_TAG, and false for everything else. */ public function isIgnorable(): bool { return isset(self::IGNORABLE_TOKENS[$this->id]); } /** * Return the textual content of the token. */ public function __toString(): string { return $this->text; } /** * Tokenize the given source code and return an array of tokens. * * This performs certain canonicalizations to match the PHP 8.0 token format: * * Bad characters are represented using T_BAD_CHARACTER rather than omitted. * * T_COMMENT does not include trailing newlines, instead the newline is part of a following * T_WHITESPACE token. * * Namespaced names are represented using T_NAME_* tokens. * * @return static[] */ public static function tokenize(string $code, int $flags = 0): array { self::init(); $tokens = []; $line = 1; $pos = 0; $origTokens = \token_get_all($code, $flags); $numTokens = \count($origTokens); for ($i = 0; $i < $numTokens; $i++) { $token = $origTokens[$i]; if (\is_string($token)) { if (\strlen($token) === 2) { // b" and B" are tokenized as single-char tokens, even though they aren't. $tokens[] = new static(\ord('"'), $token, $line, $pos); $pos += 2; } else { $tokens[] = new static(\ord($token), $token, $line, $pos); $pos++; } } else { $id = $token[0]; $text = $token[1]; // Emulate PHP 8.0 comment format, which does not include trailing whitespace anymore. if ($id === \T_COMMENT && \substr($text, 0, 2) !== '/*' && \preg_match('/(\r\n|\n|\r)$/D', $text, $matches) ) { $trailingNewline = $matches[0]; $text = \substr($text, 0, -\strlen($trailingNewline)); $tokens[] = new static($id, $text, $line, $pos); $pos += \strlen($text); if ($i + 1 < $numTokens && $origTokens[$i + 1][0] === \T_WHITESPACE) { // Move trailing newline into following T_WHITESPACE token, if it already exists. $origTokens[$i + 1][1] = $trailingNewline . $origTokens[$i + 1][1]; $origTokens[$i + 1][2]--; } else { // Otherwise, we need to create a new T_WHITESPACE token. $tokens[] = new static(\T_WHITESPACE, $trailingNewline, $line, $pos); $line++; $pos += \strlen($trailingNewline); } continue; } // Emulate PHP 8.0 T_NAME_* tokens, by combining sequences of T_NS_SEPARATOR and // T_STRING into a single token. if (($id === \T_NS_SEPARATOR || isset(self::$identifierTokens[$id]))) { $newText = $text; $lastWasSeparator = $id === \T_NS_SEPARATOR; for ($j = $i + 1; $j < $numTokens; $j++) { if ($lastWasSeparator) { if (!isset(self::$identifierTokens[$origTokens[$j][0]])) { break; } $lastWasSeparator = false; } else { if ($origTokens[$j][0] !== \T_NS_SEPARATOR) { break; } $lastWasSeparator = true; } $newText .= $origTokens[$j][1]; } if ($lastWasSeparator) { // Trailing separator is not part of the name. $j--; $newText = \substr($newText, 0, -1); } if ($j > $i + 1) { if ($id === \T_NS_SEPARATOR) { $id = \T_NAME_FULLY_QUALIFIED; } elseif ($id === \T_NAMESPACE) { $id = \T_NAME_RELATIVE; } else { $id = \T_NAME_QUALIFIED; } $tokens[] = new static($id, $newText, $line, $pos); $pos += \strlen($newText); $i = $j - 1; continue; } } $tokens[] = new static($id, $text, $line, $pos); $line += \substr_count($text, "\n"); $pos += \strlen($text); } } return $tokens; } /** Initialize private static state needed by tokenize(). */ private static function init(): void { if (isset(self::$identifierTokens)) { return; } // Based on semi_reserved production. self::$identifierTokens = \array_fill_keys([ \T_STRING, \T_STATIC, \T_ABSTRACT, \T_FINAL, \T_PRIVATE, \T_PROTECTED, \T_PUBLIC, \T_READONLY, \T_INCLUDE, \T_INCLUDE_ONCE, \T_EVAL, \T_REQUIRE, \T_REQUIRE_ONCE, \T_LOGICAL_OR, \T_LOGICAL_XOR, \T_LOGICAL_AND, \T_INSTANCEOF, \T_NEW, \T_CLONE, \T_EXIT, \T_IF, \T_ELSEIF, \T_ELSE, \T_ENDIF, \T_ECHO, \T_DO, \T_WHILE, \T_ENDWHILE, \T_FOR, \T_ENDFOR, \T_FOREACH, \T_ENDFOREACH, \T_DECLARE, \T_ENDDECLARE, \T_AS, \T_TRY, \T_CATCH, \T_FINALLY, \T_THROW, \T_USE, \T_INSTEADOF, \T_GLOBAL, \T_VAR, \T_UNSET, \T_ISSET, \T_EMPTY, \T_CONTINUE, \T_GOTO, \T_FUNCTION, \T_CONST, \T_RETURN, \T_PRINT, \T_YIELD, \T_LIST, \T_SWITCH, \T_ENDSWITCH, \T_CASE, \T_DEFAULT, \T_BREAK, \T_ARRAY, \T_CALLABLE, \T_EXTENDS, \T_IMPLEMENTS, \T_NAMESPACE, \T_TRAIT, \T_INTERFACE, \T_CLASS, \T_CLASS_C, \T_TRAIT_C, \T_FUNC_C, \T_METHOD_C, \T_LINE, \T_FILE, \T_DIR, \T_NS_C, \T_HALT_COMPILER, \T_FN, \T_MATCH, ], true); } } ================================================ FILE: lib/PhpParser/Internal/TokenStream.php ================================================ tokens = $tokens; $this->indentMap = $this->calcIndentMap($tabWidth); } /** * Whether the given position is immediately surrounded by parenthesis. * * @param int $startPos Start position * @param int $endPos End position */ public function haveParens(int $startPos, int $endPos): bool { return $this->haveTokenImmediatelyBefore($startPos, '(') && $this->haveTokenImmediatelyAfter($endPos, ')'); } /** * Whether the given position is immediately surrounded by braces. * * @param int $startPos Start position * @param int $endPos End position */ public function haveBraces(int $startPos, int $endPos): bool { return ($this->haveTokenImmediatelyBefore($startPos, '{') || $this->haveTokenImmediatelyBefore($startPos, T_CURLY_OPEN)) && $this->haveTokenImmediatelyAfter($endPos, '}'); } /** * Check whether the position is directly preceded by a certain token type. * * During this check whitespace and comments are skipped. * * @param int $pos Position before which the token should occur * @param int|string $expectedTokenType Token to check for * * @return bool Whether the expected token was found */ public function haveTokenImmediatelyBefore(int $pos, $expectedTokenType): bool { $tokens = $this->tokens; $pos--; for (; $pos >= 0; $pos--) { $token = $tokens[$pos]; if ($token->is($expectedTokenType)) { return true; } if (!$token->isIgnorable()) { break; } } return false; } /** * Check whether the position is directly followed by a certain token type. * * During this check whitespace and comments are skipped. * * @param int $pos Position after which the token should occur * @param int|string $expectedTokenType Token to check for * * @return bool Whether the expected token was found */ public function haveTokenImmediatelyAfter(int $pos, $expectedTokenType): bool { $tokens = $this->tokens; $pos++; for ($c = \count($tokens); $pos < $c; $pos++) { $token = $tokens[$pos]; if ($token->is($expectedTokenType)) { return true; } if (!$token->isIgnorable()) { break; } } return false; } /** @param int|string|(int|string)[] $skipTokenType */ public function skipLeft(int $pos, $skipTokenType): int { $tokens = $this->tokens; $pos = $this->skipLeftWhitespace($pos); if ($skipTokenType === \T_WHITESPACE) { return $pos; } if (!$tokens[$pos]->is($skipTokenType)) { // Shouldn't happen. The skip token MUST be there throw new \Exception('Encountered unexpected token'); } $pos--; return $this->skipLeftWhitespace($pos); } /** @param int|string|(int|string)[] $skipTokenType */ public function skipRight(int $pos, $skipTokenType): int { $tokens = $this->tokens; $pos = $this->skipRightWhitespace($pos); if ($skipTokenType === \T_WHITESPACE) { return $pos; } if (!$tokens[$pos]->is($skipTokenType)) { // Shouldn't happen. The skip token MUST be there throw new \Exception('Encountered unexpected token'); } $pos++; return $this->skipRightWhitespace($pos); } /** * Return first non-whitespace token position smaller or equal to passed position. * * @param int $pos Token position * @return int Non-whitespace token position */ public function skipLeftWhitespace(int $pos): int { $tokens = $this->tokens; for (; $pos >= 0; $pos--) { if (!$tokens[$pos]->isIgnorable()) { break; } } return $pos; } /** * Return first non-whitespace position greater or equal to passed position. * * @param int $pos Token position * @return int Non-whitespace token position */ public function skipRightWhitespace(int $pos): int { $tokens = $this->tokens; for ($count = \count($tokens); $pos < $count; $pos++) { if (!$tokens[$pos]->isIgnorable()) { break; } } return $pos; } /** @param int|string|(int|string)[] $findTokenType */ public function findRight(int $pos, $findTokenType): int { $tokens = $this->tokens; for ($count = \count($tokens); $pos < $count; $pos++) { if ($tokens[$pos]->is($findTokenType)) { return $pos; } } return -1; } /** * Whether the given position range contains a certain token type. * * @param int $startPos Starting position (inclusive) * @param int $endPos Ending position (exclusive) * @param int|string $tokenType Token type to look for * @return bool Whether the token occurs in the given range */ public function haveTokenInRange(int $startPos, int $endPos, $tokenType): bool { $tokens = $this->tokens; for ($pos = $startPos; $pos < $endPos; $pos++) { if ($tokens[$pos]->is($tokenType)) { return true; } } return false; } public function haveTagInRange(int $startPos, int $endPos): bool { return $this->haveTokenInRange($startPos, $endPos, \T_OPEN_TAG) || $this->haveTokenInRange($startPos, $endPos, \T_CLOSE_TAG); } /** * Get indentation before token position. * * @param int $pos Token position * * @return int Indentation depth (in spaces) */ public function getIndentationBefore(int $pos): int { return $this->indentMap[$pos]; } /** * Get the code corresponding to a token offset range, optionally adjusted for indentation. * * @param int $from Token start position (inclusive) * @param int $to Token end position (exclusive) * @param int $indent By how much the code should be indented (can be negative as well) * * @return string Code corresponding to token range, adjusted for indentation */ public function getTokenCode(int $from, int $to, int $indent): string { $tokens = $this->tokens; $result = ''; for ($pos = $from; $pos < $to; $pos++) { $token = $tokens[$pos]; $id = $token->id; $text = $token->text; if ($id === \T_CONSTANT_ENCAPSED_STRING || $id === \T_ENCAPSED_AND_WHITESPACE) { $result .= $text; } else { // TODO Handle non-space indentation if ($indent < 0) { $result .= str_replace("\n" . str_repeat(" ", -$indent), "\n", $text); } elseif ($indent > 0) { $result .= str_replace("\n", "\n" . str_repeat(" ", $indent), $text); } else { $result .= $text; } } } return $result; } /** * Precalculate the indentation at every token position. * * @return int[] Token position to indentation map */ private function calcIndentMap(int $tabWidth): array { $indentMap = []; $indent = 0; foreach ($this->tokens as $i => $token) { $indentMap[] = $indent; if ($token->id === \T_WHITESPACE) { $content = $token->text; $newlinePos = \strrpos($content, "\n"); if (false !== $newlinePos) { $indent = $this->getIndent(\substr($content, $newlinePos + 1), $tabWidth); } elseif ($i === 1 && $this->tokens[0]->id === \T_OPEN_TAG && $this->tokens[0]->text[\strlen($this->tokens[0]->text) - 1] === "\n") { // Special case: Newline at the end of opening tag followed by whitespace. $indent = $this->getIndent($content, $tabWidth); } } } // Add a sentinel for one past end of the file $indentMap[] = $indent; return $indentMap; } private function getIndent(string $ws, int $tabWidth): int { $spaces = \substr_count($ws, " "); $tabs = \substr_count($ws, "\t"); assert(\strlen($ws) === $spaces + $tabs); return $spaces + $tabs * $tabWidth; } } ================================================ FILE: lib/PhpParser/JsonDecoder.php ================================================ [] Node type to reflection class map */ private array $reflectionClassCache; /** @return mixed */ public function decode(string $json) { $value = json_decode($json, true); if (json_last_error()) { throw new \RuntimeException('JSON decoding error: ' . json_last_error_msg()); } return $this->decodeRecursive($value); } /** * @param mixed $value * @return mixed */ private function decodeRecursive($value) { if (\is_array($value)) { if (isset($value['nodeType'])) { if ($value['nodeType'] === 'Comment' || $value['nodeType'] === 'Comment_Doc') { return $this->decodeComment($value); } return $this->decodeNode($value); } return $this->decodeArray($value); } return $value; } private function decodeArray(array $array): array { $decodedArray = []; foreach ($array as $key => $value) { $decodedArray[$key] = $this->decodeRecursive($value); } return $decodedArray; } private function decodeNode(array $value): Node { $nodeType = $value['nodeType']; if (!\is_string($nodeType)) { throw new \RuntimeException('Node type must be a string'); } $reflectionClass = $this->reflectionClassFromNodeType($nodeType); $node = $reflectionClass->newInstanceWithoutConstructor(); if (isset($value['attributes'])) { if (!\is_array($value['attributes'])) { throw new \RuntimeException('Attributes must be an array'); } $node->setAttributes($this->decodeArray($value['attributes'])); } foreach ($value as $name => $subNode) { if ($name === 'nodeType' || $name === 'attributes') { continue; } $node->$name = $this->decodeRecursive($subNode); } return $node; } private function decodeComment(array $value): Comment { $className = $value['nodeType'] === 'Comment' ? Comment::class : Comment\Doc::class; if (!isset($value['text'])) { throw new \RuntimeException('Comment must have text'); } return new $className( $value['text'], $value['line'] ?? -1, $value['filePos'] ?? -1, $value['tokenPos'] ?? -1, $value['endLine'] ?? -1, $value['endFilePos'] ?? -1, $value['endTokenPos'] ?? -1 ); } /** @return \ReflectionClass */ private function reflectionClassFromNodeType(string $nodeType): \ReflectionClass { if (!isset($this->reflectionClassCache[$nodeType])) { $className = $this->classNameFromNodeType($nodeType); $this->reflectionClassCache[$nodeType] = new \ReflectionClass($className); } return $this->reflectionClassCache[$nodeType]; } /** @return class-string */ private function classNameFromNodeType(string $nodeType): string { $className = 'PhpParser\\Node\\' . strtr($nodeType, '_', '\\'); if (class_exists($className)) { return $className; } $className .= '_'; if (class_exists($className)) { return $className; } throw new \RuntimeException("Unknown node type \"$nodeType\""); } } ================================================ FILE: lib/PhpParser/Lexer/Emulative.php ================================================ */ private array $emulators = []; private PhpVersion $targetPhpVersion; private PhpVersion $hostPhpVersion; /** * @param PhpVersion|null $phpVersion PHP version to emulate. Defaults to newest supported. */ public function __construct(?PhpVersion $phpVersion = null) { $this->targetPhpVersion = $phpVersion ?? PhpVersion::getNewestSupported(); $this->hostPhpVersion = PhpVersion::getHostVersion(); $emulators = [ new FnTokenEmulator(), new MatchTokenEmulator(), new NullsafeTokenEmulator(), new AttributeEmulator(), new EnumTokenEmulator(), new ReadonlyTokenEmulator(), new ExplicitOctalEmulator(), new ReadonlyFunctionTokenEmulator(), new PropertyTokenEmulator(), new AsymmetricVisibilityTokenEmulator(), new PipeOperatorEmulator(), new VoidCastEmulator(), ]; // Collect emulators that are relevant for the PHP version we're running // and the PHP version we're targeting for emulation. foreach ($emulators as $emulator) { $emulatorPhpVersion = $emulator->getPhpVersion(); if ($this->isForwardEmulationNeeded($emulatorPhpVersion)) { $this->emulators[] = $emulator; } elseif ($this->isReverseEmulationNeeded($emulatorPhpVersion)) { $this->emulators[] = new ReverseEmulator($emulator); } } } public function tokenize(string $code, ?ErrorHandler $errorHandler = null): array { $emulators = array_filter($this->emulators, function ($emulator) use ($code) { return $emulator->isEmulationNeeded($code); }); if (empty($emulators)) { // Nothing to emulate, yay return parent::tokenize($code, $errorHandler); } if ($errorHandler === null) { $errorHandler = new ErrorHandler\Throwing(); } $this->patches = []; foreach ($emulators as $emulator) { $code = $emulator->preprocessCode($code, $this->patches); } $collector = new ErrorHandler\Collecting(); $tokens = parent::tokenize($code, $collector); $this->sortPatches(); $tokens = $this->fixupTokens($tokens); $errors = $collector->getErrors(); if (!empty($errors)) { $this->fixupErrors($errors); foreach ($errors as $error) { $errorHandler->handleError($error); } } foreach ($emulators as $emulator) { $tokens = $emulator->emulate($code, $tokens); } return $tokens; } private function isForwardEmulationNeeded(PhpVersion $emulatorPhpVersion): bool { return $this->hostPhpVersion->older($emulatorPhpVersion) && $this->targetPhpVersion->newerOrEqual($emulatorPhpVersion); } private function isReverseEmulationNeeded(PhpVersion $emulatorPhpVersion): bool { return $this->hostPhpVersion->newerOrEqual($emulatorPhpVersion) && $this->targetPhpVersion->older($emulatorPhpVersion); } private function sortPatches(): void { // Patches may be contributed by different emulators. // Make sure they are sorted by increasing patch position. usort($this->patches, function ($p1, $p2) { return $p1[0] <=> $p2[0]; }); } /** * @param list $tokens * @return list */ private function fixupTokens(array $tokens): array { if (\count($this->patches) === 0) { return $tokens; } // Load first patch $patchIdx = 0; list($patchPos, $patchType, $patchText) = $this->patches[$patchIdx]; // We use a manual loop over the tokens, because we modify the array on the fly $posDelta = 0; $lineDelta = 0; for ($i = 0, $c = \count($tokens); $i < $c; $i++) { $token = $tokens[$i]; $pos = $token->pos; $token->pos += $posDelta; $token->line += $lineDelta; $localPosDelta = 0; $len = \strlen($token->text); while ($patchPos >= $pos && $patchPos < $pos + $len) { $patchTextLen = \strlen($patchText); if ($patchType === 'remove') { if ($patchPos === $pos && $patchTextLen === $len) { // Remove token entirely array_splice($tokens, $i, 1, []); $i--; $c--; } else { // Remove from token string $token->text = substr_replace( $token->text, '', $patchPos - $pos + $localPosDelta, $patchTextLen ); $localPosDelta -= $patchTextLen; } $lineDelta -= \substr_count($patchText, "\n"); } elseif ($patchType === 'add') { // Insert into the token string $token->text = substr_replace( $token->text, $patchText, $patchPos - $pos + $localPosDelta, 0 ); $localPosDelta += $patchTextLen; $lineDelta += \substr_count($patchText, "\n"); } elseif ($patchType === 'replace') { // Replace inside the token string $token->text = substr_replace( $token->text, $patchText, $patchPos - $pos + $localPosDelta, $patchTextLen ); } else { assert(false); } // Fetch the next patch $patchIdx++; if ($patchIdx >= \count($this->patches)) { // No more patches. However, we still need to adjust position. $patchPos = \PHP_INT_MAX; break; } list($patchPos, $patchType, $patchText) = $this->patches[$patchIdx]; } $posDelta += $localPosDelta; } return $tokens; } /** * Fixup line and position information in errors. * * @param Error[] $errors */ private function fixupErrors(array $errors): void { foreach ($errors as $error) { $attrs = $error->getAttributes(); $posDelta = 0; $lineDelta = 0; foreach ($this->patches as $patch) { list($patchPos, $patchType, $patchText) = $patch; if ($patchPos >= $attrs['startFilePos']) { // No longer relevant break; } if ($patchType === 'add') { $posDelta += strlen($patchText); $lineDelta += substr_count($patchText, "\n"); } elseif ($patchType === 'remove') { $posDelta -= strlen($patchText); $lineDelta -= substr_count($patchText, "\n"); } } $attrs['startFilePos'] += $posDelta; $attrs['endFilePos'] += $posDelta; $attrs['startLine'] += $lineDelta; $attrs['endLine'] += $lineDelta; $error->setAttributes($attrs); } } } ================================================ FILE: lib/PhpParser/Lexer/TokenEmulator/AsymmetricVisibilityTokenEmulator.php ================================================ \T_PUBLIC_SET, \T_PROTECTED => \T_PROTECTED_SET, \T_PRIVATE => \T_PRIVATE_SET, ]; for ($i = 0, $c = count($tokens); $i < $c; ++$i) { $token = $tokens[$i]; if (isset($map[$token->id]) && $i + 3 < $c && $tokens[$i + 1]->text === '(' && $tokens[$i + 2]->id === \T_STRING && \strtolower($tokens[$i + 2]->text) === 'set' && $tokens[$i + 3]->text === ')' && $this->isKeywordContext($tokens, $i) ) { array_splice($tokens, $i, 4, [ new Token( $map[$token->id], $token->text . '(' . $tokens[$i + 2]->text . ')', $token->line, $token->pos), ]); $c -= 3; } } return $tokens; } public function reverseEmulate(string $code, array $tokens): array { $reverseMap = [ \T_PUBLIC_SET => \T_PUBLIC, \T_PROTECTED_SET => \T_PROTECTED, \T_PRIVATE_SET => \T_PRIVATE, ]; for ($i = 0, $c = count($tokens); $i < $c; ++$i) { $token = $tokens[$i]; if (isset($reverseMap[$token->id]) && \preg_match('/(public|protected|private)\((set)\)/i', $token->text, $matches) ) { [, $modifier, $set] = $matches; $modifierLen = \strlen($modifier); array_splice($tokens, $i, 1, [ new Token($reverseMap[$token->id], $modifier, $token->line, $token->pos), new Token(\ord('('), '(', $token->line, $token->pos + $modifierLen), new Token(\T_STRING, $set, $token->line, $token->pos + $modifierLen + 1), new Token(\ord(')'), ')', $token->line, $token->pos + $modifierLen + 4), ]); $i += 3; $c += 3; } } return $tokens; } /** @param Token[] $tokens */ protected function isKeywordContext(array $tokens, int $pos): bool { $prevToken = $this->getPreviousNonSpaceToken($tokens, $pos); if ($prevToken === null) { return false; } return $prevToken->id !== \T_OBJECT_OPERATOR && $prevToken->id !== \T_NULLSAFE_OBJECT_OPERATOR; } /** @param Token[] $tokens */ private function getPreviousNonSpaceToken(array $tokens, int $start): ?Token { for ($i = $start - 1; $i >= 0; --$i) { if ($tokens[$i]->id === T_WHITESPACE) { continue; } return $tokens[$i]; } return null; } } ================================================ FILE: lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php ================================================ text === '#' && isset($tokens[$i + 1]) && $tokens[$i + 1]->text === '[') { array_splice($tokens, $i, 2, [ new Token(\T_ATTRIBUTE, '#[', $token->line, $token->pos), ]); $c--; continue; } } return $tokens; } public function reverseEmulate(string $code, array $tokens): array { // TODO return $tokens; } public function preprocessCode(string $code, array &$patches): string { $pos = 0; while (false !== $pos = strpos($code, '#[', $pos)) { // Replace #[ with %[ $code[$pos] = '%'; $patches[] = [$pos, 'replace', '#']; $pos += 2; } return $code; } } ================================================ FILE: lib/PhpParser/Lexer/TokenEmulator/EnumTokenEmulator.php ================================================ id === \T_WHITESPACE && $tokens[$pos + 2]->id === \T_STRING; } } ================================================ FILE: lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php ================================================ id == \T_LNUMBER && $token->text === '0' && isset($tokens[$i + 1]) && $tokens[$i + 1]->id == \T_STRING && preg_match('/[oO][0-7]+(?:_[0-7]+)*/', $tokens[$i + 1]->text) ) { $tokenKind = $this->resolveIntegerOrFloatToken($tokens[$i + 1]->text); array_splice($tokens, $i, 2, [ new Token($tokenKind, '0' . $tokens[$i + 1]->text, $token->line, $token->pos), ]); $c--; } } return $tokens; } private function resolveIntegerOrFloatToken(string $str): int { $str = substr($str, 1); $str = str_replace('_', '', $str); $num = octdec($str); return is_float($num) ? \T_DNUMBER : \T_LNUMBER; } public function reverseEmulate(string $code, array $tokens): array { // Explicit octals were not legal code previously, don't bother. return $tokens; } } ================================================ FILE: lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php ================================================ getKeywordString()) !== false; } /** @param Token[] $tokens */ protected function isKeywordContext(array $tokens, int $pos): bool { $prevToken = $this->getPreviousNonSpaceToken($tokens, $pos); if ($prevToken === null) { return false; } return $prevToken->id !== \T_OBJECT_OPERATOR && $prevToken->id !== \T_NULLSAFE_OBJECT_OPERATOR; } public function emulate(string $code, array $tokens): array { $keywordString = $this->getKeywordString(); foreach ($tokens as $i => $token) { if ($token->id === T_STRING && strtolower($token->text) === $keywordString && $this->isKeywordContext($tokens, $i)) { $token->id = $this->getKeywordToken(); } } return $tokens; } /** @param Token[] $tokens */ private function getPreviousNonSpaceToken(array $tokens, int $start): ?Token { for ($i = $start - 1; $i >= 0; --$i) { if ($tokens[$i]->id === T_WHITESPACE) { continue; } return $tokens[$i]; } return null; } public function reverseEmulate(string $code, array $tokens): array { $keywordToken = $this->getKeywordToken(); foreach ($tokens as $token) { if ($token->id === $keywordToken) { $token->id = \T_STRING; } } return $tokens; } } ================================================ FILE: lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php ================================================ ') !== false; } public function emulate(string $code, array $tokens): array { // We need to manually iterate and manage a count because we'll change // the tokens array on the way for ($i = 0, $c = count($tokens); $i < $c; ++$i) { $token = $tokens[$i]; if ($token->text === '?' && isset($tokens[$i + 1]) && $tokens[$i + 1]->id === \T_OBJECT_OPERATOR) { array_splice($tokens, $i, 2, [ new Token(\T_NULLSAFE_OBJECT_OPERATOR, '?->', $token->line, $token->pos), ]); $c--; continue; } // Handle ?-> inside encapsed string. if ($token->id === \T_ENCAPSED_AND_WHITESPACE && isset($tokens[$i - 1]) && $tokens[$i - 1]->id === \T_VARIABLE && preg_match('/^\?->([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/', $token->text, $matches) ) { $replacement = [ new Token(\T_NULLSAFE_OBJECT_OPERATOR, '?->', $token->line, $token->pos), new Token(\T_STRING, $matches[1], $token->line, $token->pos + 3), ]; $matchLen = \strlen($matches[0]); if ($matchLen !== \strlen($token->text)) { $replacement[] = new Token( \T_ENCAPSED_AND_WHITESPACE, \substr($token->text, $matchLen), $token->line, $token->pos + $matchLen ); } array_splice($tokens, $i, 1, $replacement); $c += \count($replacement) - 1; continue; } } return $tokens; } public function reverseEmulate(string $code, array $tokens): array { // ?-> was not valid code previously, don't bother. return $tokens; } } ================================================ FILE: lib/PhpParser/Lexer/TokenEmulator/PipeOperatorEmulator.php ================================================ ') !== false; } public function emulate(string $code, array $tokens): array { for ($i = 0, $c = count($tokens); $i < $c; ++$i) { $token = $tokens[$i]; if ($token->text === '|' && isset($tokens[$i + 1]) && $tokens[$i + 1]->text === '>') { array_splice($tokens, $i, 2, [ new Token(\T_PIPE, '|>', $token->line, $token->pos), ]); $c--; } } return $tokens; } public function reverseEmulate(string $code, array $tokens): array { for ($i = 0, $c = count($tokens); $i < $c; ++$i) { $token = $tokens[$i]; if ($token->id === \T_PIPE) { array_splice($tokens, $i, 1, [ new Token(\ord('|'), '|', $token->line, $token->pos), new Token(\ord('>'), '>', $token->line, $token->pos + 1), ]); $i++; $c++; } } return $tokens; } } ================================================ FILE: lib/PhpParser/Lexer/TokenEmulator/PropertyTokenEmulator.php ================================================ text === '(' || ($tokens[$pos + 1]->id === \T_WHITESPACE && isset($tokens[$pos + 2]) && $tokens[$pos + 2]->text === '('))); } } ================================================ FILE: lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php ================================================ emulator = $emulator; } public function getPhpVersion(): PhpVersion { return $this->emulator->getPhpVersion(); } public function isEmulationNeeded(string $code): bool { return $this->emulator->isEmulationNeeded($code); } public function emulate(string $code, array $tokens): array { return $this->emulator->reverseEmulate($code, $tokens); } public function reverseEmulate(string $code, array $tokens): array { return $this->emulator->emulate($code, $tokens); } public function preprocessCode(string $code, array &$patches): string { return $code; } } ================================================ FILE: lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php ================================================ text !== '(') { continue; } $numTokens = 1; $text = '('; $j = $i + 1; if ($j < $c && $tokens[$j]->id === \T_WHITESPACE && preg_match('/[ \t]+/', $tokens[$j]->text)) { $text .= $tokens[$j]->text; $numTokens++; $j++; } if ($j >= $c || $tokens[$j]->id !== \T_STRING || \strtolower($tokens[$j]->text) !== 'void') { continue; } $text .= $tokens[$j]->text; $numTokens++; $k = $j + 1; if ($k < $c && $tokens[$k]->id === \T_WHITESPACE && preg_match('/[ \t]+/', $tokens[$k]->text)) { $text .= $tokens[$k]->text; $numTokens++; $k++; } if ($k >= $c || $tokens[$k]->text !== ')') { continue; } $text .= ')'; $numTokens++; array_splice($tokens, $i, $numTokens, [ new Token(\T_VOID_CAST, $text, $token->line, $token->pos), ]); $c -= $numTokens - 1; } return $tokens; } public function reverseEmulate(string $code, array $tokens): array { for ($i = 0, $c = count($tokens); $i < $c; ++$i) { $token = $tokens[$i]; if ($token->id !== \T_VOID_CAST) { continue; } if (!preg_match('/^\(([ \t]*)(void)([ \t]*)\)$/i', $token->text, $match)) { throw new \LogicException('Unexpected T_VOID_CAST contents'); } $newTokens = []; $pos = $token->pos; $newTokens[] = new Token(\ord('('), '(', $token->line, $pos); $pos++; if ($match[1] !== '') { $newTokens[] = new Token(\T_WHITESPACE, $match[1], $token->line, $pos); $pos += \strlen($match[1]); } $newTokens[] = new Token(\T_STRING, $match[2], $token->line, $pos); $pos += \strlen($match[2]); if ($match[3] !== '') { $newTokens[] = new Token(\T_WHITESPACE, $match[3], $token->line, $pos); $pos += \strlen($match[3]); } $newTokens[] = new Token(\ord(')'), ')', $token->line, $pos); array_splice($tokens, $i, 1, $newTokens); $i += \count($newTokens) - 1; $c += \count($newTokens) - 1; } return $tokens; } } ================================================ FILE: lib/PhpParser/Lexer.php ================================================ postprocessTokens($tokens, $errorHandler); if (false !== $scream) { ini_set('xdebug.scream', $scream); } return $tokens; } private function handleInvalidCharacter(Token $token, ErrorHandler $errorHandler): void { $chr = $token->text; if ($chr === "\0") { // PHP cuts error message after null byte, so need special case $errorMsg = 'Unexpected null byte'; } else { $errorMsg = sprintf( 'Unexpected character "%s" (ASCII %d)', $chr, ord($chr) ); } $errorHandler->handleError(new Error($errorMsg, [ 'startLine' => $token->line, 'endLine' => $token->line, 'startFilePos' => $token->pos, 'endFilePos' => $token->pos, ])); } private function isUnterminatedComment(Token $token): bool { return $token->is([\T_COMMENT, \T_DOC_COMMENT]) && substr($token->text, 0, 2) === '/*' && substr($token->text, -2) !== '*/'; } /** * @param list $tokens */ protected function postprocessTokens(array &$tokens, ErrorHandler $errorHandler): void { // This function reports errors (bad characters and unterminated comments) in the token // array, and performs certain canonicalizations: // * Use PHP 8.1 T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG and // T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG tokens used to disambiguate intersection types. // * Add a sentinel token with ID 0. $numTokens = \count($tokens); if ($numTokens === 0) { // Empty input edge case: Just add the sentinel token. $tokens[] = new Token(0, "\0", 1, 0); return; } for ($i = 0; $i < $numTokens; $i++) { $token = $tokens[$i]; if ($token->id === \T_BAD_CHARACTER) { $this->handleInvalidCharacter($token, $errorHandler); } if ($token->id === \ord('&')) { $next = $i + 1; while (isset($tokens[$next]) && $tokens[$next]->id === \T_WHITESPACE) { $next++; } $followedByVarOrVarArg = isset($tokens[$next]) && $tokens[$next]->is([\T_VARIABLE, \T_ELLIPSIS]); $token->id = $followedByVarOrVarArg ? \T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG : \T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG; } } // Check for unterminated comment $lastToken = $tokens[$numTokens - 1]; if ($this->isUnterminatedComment($lastToken)) { $errorHandler->handleError(new Error('Unterminated comment', [ 'startLine' => $lastToken->line, 'endLine' => $lastToken->getEndLine(), 'startFilePos' => $lastToken->pos, 'endFilePos' => $lastToken->getEndPos(), ])); } // Add sentinel token. $tokens[] = new Token(0, "\0", $lastToken->getEndLine(), $lastToken->getEndPos()); } } ================================================ FILE: lib/PhpParser/Modifiers.php ================================================ 'public', self::PROTECTED => 'protected', self::PRIVATE => 'private', self::STATIC => 'static', self::ABSTRACT => 'abstract', self::FINAL => 'final', self::READONLY => 'readonly', self::PUBLIC_SET => 'public(set)', self::PROTECTED_SET => 'protected(set)', self::PRIVATE_SET => 'private(set)', ]; public static function toString(int $modifier): string { if (!isset(self::TO_STRING_MAP[$modifier])) { throw new \InvalidArgumentException("Unknown modifier $modifier"); } return self::TO_STRING_MAP[$modifier]; } private static function isValidModifier(int $modifier): bool { $isPow2 = ($modifier & ($modifier - 1)) == 0 && $modifier != 0; return $isPow2 && $modifier <= self::PRIVATE_SET; } /** * @internal */ public static function verifyClassModifier(int $a, int $b): void { assert(self::isValidModifier($b)); if (($a & $b) != 0) { throw new Error( 'Multiple ' . self::toString($b) . ' modifiers are not allowed'); } if ($a & 48 && $b & 48) { throw new Error('Cannot use the final modifier on an abstract class'); } } /** * @internal */ public static function verifyModifier(int $a, int $b): void { assert(self::isValidModifier($b)); if (($a & Modifiers::VISIBILITY_MASK && $b & Modifiers::VISIBILITY_MASK) || ($a & Modifiers::VISIBILITY_SET_MASK && $b & Modifiers::VISIBILITY_SET_MASK) ) { throw new Error('Multiple access type modifiers are not allowed'); } if (($a & $b) != 0) { throw new Error( 'Multiple ' . self::toString($b) . ' modifiers are not allowed'); } if ($a & 48 && $b & 48) { throw new Error('Cannot use the final modifier on an abstract class member'); } } } ================================================ FILE: lib/PhpParser/NameContext.php ================================================ [aliasName => originalName]] */ protected array $aliases = []; /** @var Name[][] Same as $aliases but preserving original case */ protected array $origAliases = []; /** @var ErrorHandler Error handler */ protected ErrorHandler $errorHandler; /** * Create a name context. * * @param ErrorHandler $errorHandler Error handling used to report errors */ public function __construct(ErrorHandler $errorHandler) { $this->errorHandler = $errorHandler; } /** * Start a new namespace. * * This also resets the alias table. * * @param Name|null $namespace Null is the global namespace */ public function startNamespace(?Name $namespace = null): void { $this->namespace = $namespace; $this->origAliases = $this->aliases = [ Stmt\Use_::TYPE_NORMAL => [], Stmt\Use_::TYPE_FUNCTION => [], Stmt\Use_::TYPE_CONSTANT => [], ]; } /** * Add an alias / import. * * @param Name $name Original name * @param string $aliasName Aliased name * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_* * @param array $errorAttrs Attributes to use to report an error */ public function addAlias(Name $name, string $aliasName, int $type, array $errorAttrs = []): void { // Constant names are case sensitive, everything else case insensitive if ($type === Stmt\Use_::TYPE_CONSTANT) { $aliasLookupName = $aliasName; } else { $aliasLookupName = strtolower($aliasName); } if (isset($this->aliases[$type][$aliasLookupName])) { $typeStringMap = [ Stmt\Use_::TYPE_NORMAL => '', Stmt\Use_::TYPE_FUNCTION => 'function ', Stmt\Use_::TYPE_CONSTANT => 'const ', ]; $this->errorHandler->handleError(new Error( sprintf( 'Cannot use %s%s as %s because the name is already in use', $typeStringMap[$type], $name, $aliasName ), $errorAttrs )); return; } $this->aliases[$type][$aliasLookupName] = $name; $this->origAliases[$type][$aliasName] = $name; } /** * Get current namespace. * * @return null|Name Namespace (or null if global namespace) */ public function getNamespace(): ?Name { return $this->namespace; } /** * Get resolved name. * * @param Name $name Name to resolve * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_{FUNCTION|CONSTANT} * * @return null|Name Resolved name, or null if static resolution is not possible */ public function getResolvedName(Name $name, int $type): ?Name { // don't resolve special class names if ($type === Stmt\Use_::TYPE_NORMAL && $name->isSpecialClassName()) { if (!$name->isUnqualified()) { $this->errorHandler->handleError(new Error( sprintf("'\\%s' is an invalid class name", $name->toString()), $name->getAttributes() )); } return $name; } // fully qualified names are already resolved if ($name->isFullyQualified()) { return $name; } // Try to resolve aliases if (null !== $resolvedName = $this->resolveAlias($name, $type)) { return $resolvedName; } if ($type !== Stmt\Use_::TYPE_NORMAL && $name->isUnqualified()) { if (null === $this->namespace) { // outside of a namespace unaliased unqualified is same as fully qualified return new FullyQualified($name, $name->getAttributes()); } // Cannot resolve statically return null; } // if no alias exists prepend current namespace return FullyQualified::concat($this->namespace, $name, $name->getAttributes()); } /** * Get resolved class name. * * @param Name $name Class ame to resolve * * @return Name Resolved name */ public function getResolvedClassName(Name $name): Name { return $this->getResolvedName($name, Stmt\Use_::TYPE_NORMAL); } /** * Get possible ways of writing a fully qualified name (e.g., by making use of aliases). * * @param string $name Fully-qualified name (without leading namespace separator) * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_* * * @return Name[] Possible representations of the name */ public function getPossibleNames(string $name, int $type): array { $lcName = strtolower($name); if ($type === Stmt\Use_::TYPE_NORMAL) { // self, parent and static must always be unqualified if ($lcName === "self" || $lcName === "parent" || $lcName === "static") { return [new Name($name)]; } } // Collect possible ways to write this name, starting with the fully-qualified name $possibleNames = [new FullyQualified($name)]; if (null !== $nsRelativeName = $this->getNamespaceRelativeName($name, $lcName, $type)) { // Make sure there is no alias that makes the normally namespace-relative name // into something else if (null === $this->resolveAlias($nsRelativeName, $type)) { $possibleNames[] = $nsRelativeName; } } // Check for relevant namespace use statements foreach ($this->origAliases[Stmt\Use_::TYPE_NORMAL] as $alias => $orig) { $lcOrig = $orig->toLowerString(); if (0 === strpos($lcName, $lcOrig . '\\')) { $possibleNames[] = new Name($alias . substr($name, strlen($lcOrig))); } } // Check for relevant type-specific use statements foreach ($this->origAliases[$type] as $alias => $orig) { if ($type === Stmt\Use_::TYPE_CONSTANT) { // Constants are complicated-sensitive $normalizedOrig = $this->normalizeConstName($orig->toString()); if ($normalizedOrig === $this->normalizeConstName($name)) { $possibleNames[] = new Name($alias); } } else { // Everything else is case-insensitive if ($orig->toLowerString() === $lcName) { $possibleNames[] = new Name($alias); } } } return $possibleNames; } /** * Get shortest representation of this fully-qualified name. * * @param string $name Fully-qualified name (without leading namespace separator) * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_* * * @return Name Shortest representation */ public function getShortName(string $name, int $type): Name { $possibleNames = $this->getPossibleNames($name, $type); // Find shortest name $shortestName = null; $shortestLength = \INF; foreach ($possibleNames as $possibleName) { $length = strlen($possibleName->toCodeString()); if ($length < $shortestLength) { $shortestName = $possibleName; $shortestLength = $length; } } return $shortestName; } private function resolveAlias(Name $name, int $type): ?FullyQualified { $firstPart = $name->getFirst(); if ($name->isQualified()) { // resolve aliases for qualified names, always against class alias table $checkName = strtolower($firstPart); if (isset($this->aliases[Stmt\Use_::TYPE_NORMAL][$checkName])) { $alias = $this->aliases[Stmt\Use_::TYPE_NORMAL][$checkName]; return FullyQualified::concat($alias, $name->slice(1), $name->getAttributes()); } } elseif ($name->isUnqualified()) { // constant aliases are case-sensitive, function aliases case-insensitive $checkName = $type === Stmt\Use_::TYPE_CONSTANT ? $firstPart : strtolower($firstPart); if (isset($this->aliases[$type][$checkName])) { // resolve unqualified aliases return new FullyQualified($this->aliases[$type][$checkName], $name->getAttributes()); } } // No applicable aliases return null; } private function getNamespaceRelativeName(string $name, string $lcName, int $type): ?Name { if (null === $this->namespace) { return new Name($name); } if ($type === Stmt\Use_::TYPE_CONSTANT) { // The constants true/false/null always resolve to the global symbols, even inside a // namespace, so they may be used without qualification if ($lcName === "true" || $lcName === "false" || $lcName === "null") { return new Name($name); } } $namespacePrefix = strtolower($this->namespace . '\\'); if (0 === strpos($lcName, $namespacePrefix)) { return new Name(substr($name, strlen($namespacePrefix))); } return null; } private function normalizeConstName(string $name): string { $nsSep = strrpos($name, '\\'); if (false === $nsSep) { return $name; } // Constants have case-insensitive namespace and case-sensitive short-name $ns = substr($name, 0, $nsSep); $shortName = substr($name, $nsSep + 1); return strtolower($ns) . '\\' . $shortName; } } ================================================ FILE: lib/PhpParser/Node/Arg.php ================================================ $attributes Additional attributes * @param Identifier|null $name Parameter name (for named parameters) */ public function __construct( Expr $value, bool $byRef = false, bool $unpack = false, array $attributes = [], ?Identifier $name = null ) { $this->attributes = $attributes; $this->name = $name; $this->value = $value; $this->byRef = $byRef; $this->unpack = $unpack; } public function getSubNodeNames(): array { return ['name', 'value', 'byRef', 'unpack']; } public function getType(): string { return 'Arg'; } } ================================================ FILE: lib/PhpParser/Node/ArrayItem.php ================================================ $attributes Additional attributes */ public function __construct(Expr $value, ?Expr $key = null, bool $byRef = false, array $attributes = [], bool $unpack = false) { $this->attributes = $attributes; $this->key = $key; $this->value = $value; $this->byRef = $byRef; $this->unpack = $unpack; } public function getSubNodeNames(): array { return ['key', 'value', 'byRef', 'unpack']; } public function getType(): string { return 'ArrayItem'; } } // @deprecated compatibility alias class_alias(ArrayItem::class, Expr\ArrayItem::class); ================================================ FILE: lib/PhpParser/Node/Attribute.php ================================================ Attribute arguments */ public array $args; /** * @param Node\Name $name Attribute name * @param list $args Attribute arguments * @param array $attributes Additional node attributes */ public function __construct(Name $name, array $args = [], array $attributes = []) { $this->attributes = $attributes; $this->name = $name; $this->args = $args; } public function getSubNodeNames(): array { return ['name', 'args']; } public function getType(): string { return 'Attribute'; } } ================================================ FILE: lib/PhpParser/Node/AttributeGroup.php ================================================ $attributes Additional node attributes */ public function __construct(array $attrs, array $attributes = []) { $this->attributes = $attributes; $this->attrs = $attrs; } public function getSubNodeNames(): array { return ['attrs']; } public function getType(): string { return 'AttributeGroup'; } } ================================================ FILE: lib/PhpParser/Node/ClosureUse.php ================================================ $attributes Additional attributes */ public function __construct(Expr\Variable $var, bool $byRef = false, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; $this->byRef = $byRef; } public function getSubNodeNames(): array { return ['var', 'byRef']; } public function getType(): string { return 'ClosureUse'; } } // @deprecated compatibility alias class_alias(ClosureUse::class, Expr\ClosureUse::class); ================================================ FILE: lib/PhpParser/Node/ComplexType.php ================================================ $attributes Additional attributes */ public function __construct($name, Expr $value, array $attributes = []) { $this->attributes = $attributes; $this->name = \is_string($name) ? new Identifier($name) : $name; $this->value = $value; } public function getSubNodeNames(): array { return ['name', 'value']; } public function getType(): string { return 'Const'; } } ================================================ FILE: lib/PhpParser/Node/DeclareItem.php ================================================ value pair node. * * @param string|Node\Identifier $key Key * @param Node\Expr $value Value * @param array $attributes Additional attributes */ public function __construct($key, Node\Expr $value, array $attributes = []) { $this->attributes = $attributes; $this->key = \is_string($key) ? new Node\Identifier($key) : $key; $this->value = $value; } public function getSubNodeNames(): array { return ['key', 'value']; } public function getType(): string { return 'DeclareItem'; } } // @deprecated compatibility alias class_alias(DeclareItem::class, Stmt\DeclareDeclare::class); ================================================ FILE: lib/PhpParser/Node/Expr/ArrayDimFetch.php ================================================ $attributes Additional attributes */ public function __construct(Expr $var, ?Expr $dim = null, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; $this->dim = $dim; } public function getSubNodeNames(): array { return ['var', 'dim']; } public function getType(): string { return 'Expr_ArrayDimFetch'; } } ================================================ FILE: lib/PhpParser/Node/Expr/ArrayItem.php ================================================ $attributes Additional attributes */ public function __construct(array $items = [], array $attributes = []) { $this->attributes = $attributes; $this->items = $items; } public function getSubNodeNames(): array { return ['items']; } public function getType(): string { return 'Expr_Array'; } } ================================================ FILE: lib/PhpParser/Node/Expr/ArrowFunction.php ================================================ false : Whether the closure is static * 'byRef' => false : Whether to return by reference * 'params' => array() : Parameters * 'returnType' => null : Return type * 'attrGroups' => array() : PHP attribute groups * @param array $attributes Additional attributes */ public function __construct(array $subNodes, array $attributes = []) { $this->attributes = $attributes; $this->static = $subNodes['static'] ?? false; $this->byRef = $subNodes['byRef'] ?? false; $this->params = $subNodes['params'] ?? []; $this->returnType = $subNodes['returnType'] ?? null; $this->expr = $subNodes['expr']; $this->attrGroups = $subNodes['attrGroups'] ?? []; } public function getSubNodeNames(): array { return ['attrGroups', 'static', 'byRef', 'params', 'returnType', 'expr']; } public function returnsByRef(): bool { return $this->byRef; } public function getParams(): array { return $this->params; } public function getReturnType() { return $this->returnType; } public function getAttrGroups(): array { return $this->attrGroups; } /** * @return Node\Stmt\Return_[] */ public function getStmts(): array { return [new Node\Stmt\Return_($this->expr)]; } public function getType(): string { return 'Expr_ArrowFunction'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Assign.php ================================================ $attributes Additional attributes */ public function __construct(Expr $var, Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; $this->expr = $expr; } public function getSubNodeNames(): array { return ['var', 'expr']; } public function getType(): string { return 'Expr_Assign'; } } ================================================ FILE: lib/PhpParser/Node/Expr/AssignOp/BitwiseAnd.php ================================================ $attributes Additional attributes */ public function __construct(Expr $var, Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; $this->expr = $expr; } public function getSubNodeNames(): array { return ['var', 'expr']; } } ================================================ FILE: lib/PhpParser/Node/Expr/AssignRef.php ================================================ $attributes Additional attributes */ public function __construct(Expr $var, Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; $this->expr = $expr; } public function getSubNodeNames(): array { return ['var', 'expr']; } public function getType(): string { return 'Expr_AssignRef'; } } ================================================ FILE: lib/PhpParser/Node/Expr/BinaryOp/BitwiseAnd.php ================================================ '; } public function getType(): string { return 'Expr_BinaryOp_Greater'; } } ================================================ FILE: lib/PhpParser/Node/Expr/BinaryOp/GreaterOrEqual.php ================================================ ='; } public function getType(): string { return 'Expr_BinaryOp_GreaterOrEqual'; } } ================================================ FILE: lib/PhpParser/Node/Expr/BinaryOp/Identical.php ================================================ '; } public function getType(): string { return 'Expr_BinaryOp_Pipe'; } } ================================================ FILE: lib/PhpParser/Node/Expr/BinaryOp/Plus.php ================================================ >'; } public function getType(): string { return 'Expr_BinaryOp_ShiftRight'; } } ================================================ FILE: lib/PhpParser/Node/Expr/BinaryOp/Smaller.php ================================================ '; } public function getType(): string { return 'Expr_BinaryOp_Spaceship'; } } ================================================ FILE: lib/PhpParser/Node/Expr/BinaryOp.php ================================================ $attributes Additional attributes */ public function __construct(Expr $left, Expr $right, array $attributes = []) { $this->attributes = $attributes; $this->left = $left; $this->right = $right; } public function getSubNodeNames(): array { return ['left', 'right']; } /** * Get the operator sigil for this binary operation. * * In the case there are multiple possible sigils for an operator, this method does not * necessarily return the one used in the parsed code. */ abstract public function getOperatorSigil(): string; } ================================================ FILE: lib/PhpParser/Node/Expr/BitwiseNot.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_BitwiseNot'; } } ================================================ FILE: lib/PhpParser/Node/Expr/BooleanNot.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_BooleanNot'; } } ================================================ FILE: lib/PhpParser/Node/Expr/CallLike.php ================================================ */ abstract public function getRawArgs(): array; /** * Returns whether this call expression is actually a first class callable. */ public function isFirstClassCallable(): bool { $rawArgs = $this->getRawArgs(); return count($rawArgs) === 1 && current($rawArgs) instanceof VariadicPlaceholder; } /** * Assert that this is not a first-class callable and return only ordinary Args. * * @return Arg[] */ public function getArgs(): array { assert(!$this->isFirstClassCallable()); return $this->getRawArgs(); } /** * Retrieves a specific argument from the raw arguments. * * Returns the named argument that matches the given `$name`, or the * positional (unnamed) argument that exists at the given `$position`, * otherwise, returns `null` for first-class callables or if no match is found. */ public function getArg(string $name, int $position): ?Arg { if ($this->isFirstClassCallable()) { return null; } foreach ($this->getRawArgs() as $i => $arg) { if ($arg->unpack) { continue; } if ( ($arg->name !== null && $arg->name->toString() === $name) || ($arg->name === null && $i === $position) ) { return $arg; } } return null; } } ================================================ FILE: lib/PhpParser/Node/Expr/Cast/Array_.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } } ================================================ FILE: lib/PhpParser/Node/Expr/ClassConstFetch.php ================================================ $attributes Additional attributes */ public function __construct(Node $class, $name, array $attributes = []) { $this->attributes = $attributes; $this->class = $class; $this->name = \is_string($name) ? new Identifier($name) : $name; } public function getSubNodeNames(): array { return ['class', 'name']; } public function getType(): string { return 'Expr_ClassConstFetch'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Clone_.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_Clone'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Closure.php ================================================ false : Whether the closure is static * 'byRef' => false : Whether to return by reference * 'params' => array(): Parameters * 'uses' => array(): use()s * 'returnType' => null : Return type * 'stmts' => array(): Statements * 'attrGroups' => array(): PHP attributes groups * @param array $attributes Additional attributes */ public function __construct(array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->static = $subNodes['static'] ?? false; $this->byRef = $subNodes['byRef'] ?? false; $this->params = $subNodes['params'] ?? []; $this->uses = $subNodes['uses'] ?? []; $this->returnType = $subNodes['returnType'] ?? null; $this->stmts = $subNodes['stmts'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } public function getSubNodeNames(): array { return ['attrGroups', 'static', 'byRef', 'params', 'uses', 'returnType', 'stmts']; } public function returnsByRef(): bool { return $this->byRef; } public function getParams(): array { return $this->params; } public function getReturnType() { return $this->returnType; } /** @return Node\Stmt[] */ public function getStmts(): array { return $this->stmts; } public function getAttrGroups(): array { return $this->attrGroups; } public function getType(): string { return 'Expr_Closure'; } } ================================================ FILE: lib/PhpParser/Node/Expr/ClosureUse.php ================================================ $attributes Additional attributes */ public function __construct(Name $name, array $attributes = []) { $this->attributes = $attributes; $this->name = $name; } public function getSubNodeNames(): array { return ['name']; } public function getType(): string { return 'Expr_ConstFetch'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Empty_.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_Empty'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Error.php ================================================ $attributes Additional attributes */ public function __construct(array $attributes = []) { $this->attributes = $attributes; } public function getSubNodeNames(): array { return []; } public function getType(): string { return 'Expr_Error'; } } ================================================ FILE: lib/PhpParser/Node/Expr/ErrorSuppress.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_ErrorSuppress'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Eval_.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_Eval'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Exit_.php ================================================ $attributes Additional attributes */ public function __construct(?Expr $expr = null, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_Exit'; } } ================================================ FILE: lib/PhpParser/Node/Expr/FuncCall.php ================================================ Arguments */ public array $args; /** * Constructs a function call node. * * @param Node\Name|Expr $name Function name * @param array $args Arguments * @param array $attributes Additional attributes */ public function __construct(Node $name, array $args = [], array $attributes = []) { $this->attributes = $attributes; $this->name = $name; $this->args = $args; } public function getSubNodeNames(): array { return ['name', 'args']; } public function getType(): string { return 'Expr_FuncCall'; } public function getRawArgs(): array { return $this->args; } } ================================================ FILE: lib/PhpParser/Node/Expr/Include_.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, int $type, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; $this->type = $type; } public function getSubNodeNames(): array { return ['expr', 'type']; } public function getType(): string { return 'Expr_Include'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Instanceof_.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, Node $class, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; $this->class = $class; } public function getSubNodeNames(): array { return ['expr', 'class']; } public function getType(): string { return 'Expr_Instanceof'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Isset_.php ================================================ $attributes Additional attributes */ public function __construct(array $vars, array $attributes = []) { $this->attributes = $attributes; $this->vars = $vars; } public function getSubNodeNames(): array { return ['vars']; } public function getType(): string { return 'Expr_Isset'; } } ================================================ FILE: lib/PhpParser/Node/Expr/List_.php ================================================ $attributes Additional attributes */ public function __construct(array $items, array $attributes = []) { $this->attributes = $attributes; $this->items = $items; } public function getSubNodeNames(): array { return ['items']; } public function getType(): string { return 'Expr_List'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Match_.php ================================================ $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $arms = [], array $attributes = []) { $this->attributes = $attributes; $this->cond = $cond; $this->arms = $arms; } public function getSubNodeNames(): array { return ['cond', 'arms']; } public function getType(): string { return 'Expr_Match'; } } ================================================ FILE: lib/PhpParser/Node/Expr/MethodCall.php ================================================ Arguments */ public array $args; /** * Constructs a function call node. * * @param Expr $var Variable holding object * @param string|Identifier|Expr $name Method name * @param array $args Arguments * @param array $attributes Additional attributes */ public function __construct(Expr $var, $name, array $args = [], array $attributes = []) { $this->attributes = $attributes; $this->var = $var; $this->name = \is_string($name) ? new Identifier($name) : $name; $this->args = $args; } public function getSubNodeNames(): array { return ['var', 'name', 'args']; } public function getType(): string { return 'Expr_MethodCall'; } public function getRawArgs(): array { return $this->args; } } ================================================ FILE: lib/PhpParser/Node/Expr/New_.php ================================================ Arguments */ public array $args; /** * Constructs a function call node. * * @param Node\Name|Expr|Node\Stmt\Class_ $class Class name (or class node for anonymous classes) * @param array $args Arguments * @param array $attributes Additional attributes */ public function __construct(Node $class, array $args = [], array $attributes = []) { $this->attributes = $attributes; $this->class = $class; $this->args = $args; } public function getSubNodeNames(): array { return ['class', 'args']; } public function getType(): string { return 'Expr_New'; } public function getRawArgs(): array { return $this->args; } } ================================================ FILE: lib/PhpParser/Node/Expr/NullsafeMethodCall.php ================================================ Arguments */ public array $args; /** * Constructs a nullsafe method call node. * * @param Expr $var Variable holding object * @param string|Identifier|Expr $name Method name * @param array $args Arguments * @param array $attributes Additional attributes */ public function __construct(Expr $var, $name, array $args = [], array $attributes = []) { $this->attributes = $attributes; $this->var = $var; $this->name = \is_string($name) ? new Identifier($name) : $name; $this->args = $args; } public function getSubNodeNames(): array { return ['var', 'name', 'args']; } public function getType(): string { return 'Expr_NullsafeMethodCall'; } public function getRawArgs(): array { return $this->args; } } ================================================ FILE: lib/PhpParser/Node/Expr/NullsafePropertyFetch.php ================================================ $attributes Additional attributes */ public function __construct(Expr $var, $name, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; $this->name = \is_string($name) ? new Identifier($name) : $name; } public function getSubNodeNames(): array { return ['var', 'name']; } public function getType(): string { return 'Expr_NullsafePropertyFetch'; } } ================================================ FILE: lib/PhpParser/Node/Expr/PostDec.php ================================================ $attributes Additional attributes */ public function __construct(Expr $var, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; } public function getSubNodeNames(): array { return ['var']; } public function getType(): string { return 'Expr_PostDec'; } } ================================================ FILE: lib/PhpParser/Node/Expr/PostInc.php ================================================ $attributes Additional attributes */ public function __construct(Expr $var, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; } public function getSubNodeNames(): array { return ['var']; } public function getType(): string { return 'Expr_PostInc'; } } ================================================ FILE: lib/PhpParser/Node/Expr/PreDec.php ================================================ $attributes Additional attributes */ public function __construct(Expr $var, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; } public function getSubNodeNames(): array { return ['var']; } public function getType(): string { return 'Expr_PreDec'; } } ================================================ FILE: lib/PhpParser/Node/Expr/PreInc.php ================================================ $attributes Additional attributes */ public function __construct(Expr $var, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; } public function getSubNodeNames(): array { return ['var']; } public function getType(): string { return 'Expr_PreInc'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Print_.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_Print'; } } ================================================ FILE: lib/PhpParser/Node/Expr/PropertyFetch.php ================================================ $attributes Additional attributes */ public function __construct(Expr $var, $name, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; $this->name = \is_string($name) ? new Identifier($name) : $name; } public function getSubNodeNames(): array { return ['var', 'name']; } public function getType(): string { return 'Expr_PropertyFetch'; } } ================================================ FILE: lib/PhpParser/Node/Expr/ShellExec.php ================================================ $attributes Additional attributes */ public function __construct(array $parts, array $attributes = []) { $this->attributes = $attributes; $this->parts = $parts; } public function getSubNodeNames(): array { return ['parts']; } public function getType(): string { return 'Expr_ShellExec'; } } ================================================ FILE: lib/PhpParser/Node/Expr/StaticCall.php ================================================ Arguments */ public array $args; /** * Constructs a static method call node. * * @param Node\Name|Expr $class Class name * @param string|Identifier|Expr $name Method name * @param array $args Arguments * @param array $attributes Additional attributes */ public function __construct(Node $class, $name, array $args = [], array $attributes = []) { $this->attributes = $attributes; $this->class = $class; $this->name = \is_string($name) ? new Identifier($name) : $name; $this->args = $args; } public function getSubNodeNames(): array { return ['class', 'name', 'args']; } public function getType(): string { return 'Expr_StaticCall'; } public function getRawArgs(): array { return $this->args; } } ================================================ FILE: lib/PhpParser/Node/Expr/StaticPropertyFetch.php ================================================ $attributes Additional attributes */ public function __construct(Node $class, $name, array $attributes = []) { $this->attributes = $attributes; $this->class = $class; $this->name = \is_string($name) ? new VarLikeIdentifier($name) : $name; } public function getSubNodeNames(): array { return ['class', 'name']; } public function getType(): string { return 'Expr_StaticPropertyFetch'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Ternary.php ================================================ $attributes Additional attributes */ public function __construct(Expr $cond, ?Expr $if, Expr $else, array $attributes = []) { $this->attributes = $attributes; $this->cond = $cond; $this->if = $if; $this->else = $else; } public function getSubNodeNames(): array { return ['cond', 'if', 'else']; } public function getType(): string { return 'Expr_Ternary'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Throw_.php ================================================ $attributes Additional attributes */ public function __construct(Node\Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_Throw'; } } ================================================ FILE: lib/PhpParser/Node/Expr/UnaryMinus.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_UnaryMinus'; } } ================================================ FILE: lib/PhpParser/Node/Expr/UnaryPlus.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_UnaryPlus'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Variable.php ================================================ $attributes Additional attributes */ public function __construct($name, array $attributes = []) { $this->attributes = $attributes; $this->name = $name; } public function getSubNodeNames(): array { return ['name']; } public function getType(): string { return 'Expr_Variable'; } } ================================================ FILE: lib/PhpParser/Node/Expr/YieldFrom.php ================================================ $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Expr_YieldFrom'; } } ================================================ FILE: lib/PhpParser/Node/Expr/Yield_.php ================================================ $attributes Additional attributes */ public function __construct(?Expr $value = null, ?Expr $key = null, array $attributes = []) { $this->attributes = $attributes; $this->key = $key; $this->value = $value; } public function getSubNodeNames(): array { return ['key', 'value']; } public function getType(): string { return 'Expr_Yield'; } } ================================================ FILE: lib/PhpParser/Node/Expr.php ================================================ */ private static array $specialClassNames = [ 'self' => true, 'parent' => true, 'static' => true, ]; /** * Constructs an identifier node. * * @param string $name Identifier as string * @param array $attributes Additional attributes */ public function __construct(string $name, array $attributes = []) { if ($name === '') { throw new \InvalidArgumentException('Identifier name cannot be empty'); } $this->attributes = $attributes; $this->name = $name; } public function getSubNodeNames(): array { return ['name']; } /** * Get identifier as string. * * @psalm-return non-empty-string * @return string Identifier as string. */ public function toString(): string { return $this->name; } /** * Get lowercased identifier as string. * * @psalm-return non-empty-string&lowercase-string * @return string Lowercased identifier as string */ public function toLowerString(): string { return strtolower($this->name); } /** * Checks whether the identifier is a special class name (self, parent or static). * * @return bool Whether identifier is a special class name */ public function isSpecialClassName(): bool { return isset(self::$specialClassNames[strtolower($this->name)]); } /** * Get identifier as string. * * @psalm-return non-empty-string * @return string Identifier as string */ public function __toString(): string { return $this->name; } public function getType(): string { return 'Identifier'; } } ================================================ FILE: lib/PhpParser/Node/InterpolatedStringPart.php ================================================ $attributes Additional attributes */ public function __construct(string $value, array $attributes = []) { $this->attributes = $attributes; $this->value = $value; } public function getSubNodeNames(): array { return ['value']; } public function getType(): string { return 'InterpolatedStringPart'; } } // @deprecated compatibility alias class_alias(InterpolatedStringPart::class, Scalar\EncapsedStringPart::class); ================================================ FILE: lib/PhpParser/Node/IntersectionType.php ================================================ $attributes Additional attributes */ public function __construct(array $types, array $attributes = []) { $this->attributes = $attributes; $this->types = $types; } public function getSubNodeNames(): array { return ['types']; } public function getType(): string { return 'IntersectionType'; } } ================================================ FILE: lib/PhpParser/Node/MatchArm.php ================================================ */ public ?array $conds; public Expr $body; /** * @param null|list $conds */ public function __construct(?array $conds, Node\Expr $body, array $attributes = []) { $this->conds = $conds; $this->body = $body; $this->attributes = $attributes; } public function getSubNodeNames(): array { return ['conds', 'body']; } public function getType(): string { return 'MatchArm'; } } ================================================ FILE: lib/PhpParser/Node/Name/FullyQualified.php ================================================ toString(); } public function getType(): string { return 'Name_FullyQualified'; } } ================================================ FILE: lib/PhpParser/Node/Name/Relative.php ================================================ toString(); } public function getType(): string { return 'Name_Relative'; } } ================================================ FILE: lib/PhpParser/Node/Name.php ================================================ */ private static array $specialClassNames = [ 'self' => true, 'parent' => true, 'static' => true, ]; /** * Constructs a name node. * * @param string|string[]|self $name Name as string, part array or Name instance (copy ctor) * @param array $attributes Additional attributes */ final public function __construct($name, array $attributes = []) { $this->attributes = $attributes; $this->name = self::prepareName($name); } public function getSubNodeNames(): array { return ['name']; } /** * Get parts of name (split by the namespace separator). * * @psalm-return non-empty-list * @return string[] Parts of name */ public function getParts(): array { return \explode('\\', $this->name); } /** * Gets the first part of the name, i.e. everything before the first namespace separator. * * @return string First part of the name */ public function getFirst(): string { if (false !== $pos = \strpos($this->name, '\\')) { return \substr($this->name, 0, $pos); } return $this->name; } /** * Gets the last part of the name, i.e. everything after the last namespace separator. * * @return string Last part of the name */ public function getLast(): string { if (false !== $pos = \strrpos($this->name, '\\')) { return \substr($this->name, $pos + 1); } return $this->name; } /** * Checks whether the name is unqualified. (E.g. Name) * * @return bool Whether the name is unqualified */ public function isUnqualified(): bool { return false === \strpos($this->name, '\\'); } /** * Checks whether the name is qualified. (E.g. Name\Name) * * @return bool Whether the name is qualified */ public function isQualified(): bool { return false !== \strpos($this->name, '\\'); } /** * Checks whether the name is fully qualified. (E.g. \Name) * * @return bool Whether the name is fully qualified */ public function isFullyQualified(): bool { return false; } /** * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name) * * @return bool Whether the name is relative */ public function isRelative(): bool { return false; } /** * Returns a string representation of the name itself, without taking the name type into * account (e.g., not including a leading backslash for fully qualified names). * * @psalm-return non-empty-string * @return string String representation */ public function toString(): string { return $this->name; } /** * Returns a string representation of the name as it would occur in code (e.g., including * leading backslash for fully qualified names. * * @psalm-return non-empty-string * @return string String representation */ public function toCodeString(): string { return $this->toString(); } /** * Returns lowercased string representation of the name, without taking the name type into * account (e.g., no leading backslash for fully qualified names). * * @psalm-return non-empty-string&lowercase-string * @return string Lowercased string representation */ public function toLowerString(): string { return strtolower($this->name); } /** * Checks whether the identifier is a special class name (self, parent or static). * * @return bool Whether identifier is a special class name */ public function isSpecialClassName(): bool { return isset(self::$specialClassNames[strtolower($this->name)]); } /** * Returns a string representation of the name by imploding the namespace parts with the * namespace separator. * * @psalm-return non-empty-string * @return string String representation */ public function __toString(): string { return $this->name; } /** * Gets a slice of a name (similar to array_slice). * * This method returns a new instance of the same type as the original and with the same * attributes. * * If the slice is empty, null is returned. The null value will be correctly handled in * concatenations using concat(). * * Offset and length have the same meaning as in array_slice(). * * @param int $offset Offset to start the slice at (may be negative) * @param int|null $length Length of the slice (may be negative) * * @return static|null Sliced name */ public function slice(int $offset, ?int $length = null) { if ($offset === 1 && $length === null) { // Short-circuit the common case. if (false !== $pos = \strpos($this->name, '\\')) { return new static(\substr($this->name, $pos + 1)); } return null; } $parts = \explode('\\', $this->name); $numParts = \count($parts); $realOffset = $offset < 0 ? $offset + $numParts : $offset; if ($realOffset < 0 || $realOffset > $numParts) { throw new \OutOfBoundsException(sprintf('Offset %d is out of bounds', $offset)); } if (null === $length) { $realLength = $numParts - $realOffset; } else { $realLength = $length < 0 ? $length + $numParts - $realOffset : $length; if ($realLength < 0 || $realLength > $numParts - $realOffset) { throw new \OutOfBoundsException(sprintf('Length %d is out of bounds', $length)); } } if ($realLength === 0) { // Empty slice is represented as null return null; } return new static(array_slice($parts, $realOffset, $realLength), $this->attributes); } /** * Concatenate two names, yielding a new Name instance. * * The type of the generated instance depends on which class this method is called on, for * example Name\FullyQualified::concat() will yield a Name\FullyQualified instance. * * If one of the arguments is null, a new instance of the other name will be returned. If both * arguments are null, null will be returned. As such, writing * Name::concat($namespace, $shortName) * where $namespace is a Name node or null will work as expected. * * @param string|string[]|self|null $name1 The first name * @param string|string[]|self|null $name2 The second name * @param array $attributes Attributes to assign to concatenated name * * @return static|null Concatenated name */ public static function concat($name1, $name2, array $attributes = []) { if (null === $name1 && null === $name2) { return null; } if (null === $name1) { return new static($name2, $attributes); } if (null === $name2) { return new static($name1, $attributes); } else { return new static( self::prepareName($name1) . '\\' . self::prepareName($name2), $attributes ); } } /** * Prepares a (string, array or Name node) name for use in name changing methods by converting * it to a string. * * @param string|string[]|self $name Name to prepare * * @psalm-return non-empty-string * @return string Prepared name */ private static function prepareName($name): string { if (\is_string($name)) { if ('' === $name) { throw new \InvalidArgumentException('Name cannot be empty'); } return $name; } if (\is_array($name)) { if (empty($name)) { throw new \InvalidArgumentException('Name cannot be empty'); } return implode('\\', $name); } if ($name instanceof self) { return $name->name; } throw new \InvalidArgumentException( 'Expected string, array of parts or Name instance' ); } public function getType(): string { return 'Name'; } } ================================================ FILE: lib/PhpParser/Node/NullableType.php ================================================ $attributes Additional attributes */ public function __construct(Node $type, array $attributes = []) { $this->attributes = $attributes; $this->type = $type; } public function getSubNodeNames(): array { return ['type']; } public function getType(): string { return 'NullableType'; } } ================================================ FILE: lib/PhpParser/Node/Param.php ================================================ $attributes Additional attributes * @param int $flags Optional visibility flags * @param list $attrGroups PHP attribute groups * @param PropertyHook[] $hooks Property hooks for promoted properties */ public function __construct( Expr $var, ?Expr $default = null, ?Node $type = null, bool $byRef = false, bool $variadic = false, array $attributes = [], int $flags = 0, array $attrGroups = [], array $hooks = [] ) { $this->attributes = $attributes; $this->type = $type; $this->byRef = $byRef; $this->variadic = $variadic; $this->var = $var; $this->default = $default; $this->flags = $flags; $this->attrGroups = $attrGroups; $this->hooks = $hooks; } public function getSubNodeNames(): array { return ['attrGroups', 'flags', 'type', 'byRef', 'variadic', 'var', 'default', 'hooks']; } public function getType(): string { return 'Param'; } /** * Whether this parameter uses constructor property promotion. */ public function isPromoted(): bool { return $this->flags !== 0 || $this->hooks !== []; } public function isFinal(): bool { return (bool) ($this->flags & Modifiers::FINAL); } public function isPublic(): bool { $public = (bool) ($this->flags & Modifiers::PUBLIC); if ($public) { return true; } if (!$this->isPromoted()) { return false; } return ($this->flags & Modifiers::VISIBILITY_MASK) === 0; } public function isProtected(): bool { return (bool) ($this->flags & Modifiers::PROTECTED); } public function isPrivate(): bool { return (bool) ($this->flags & Modifiers::PRIVATE); } public function isReadonly(): bool { return (bool) ($this->flags & Modifiers::READONLY); } /** * Whether the promoted property has explicit public(set) visibility. */ public function isPublicSet(): bool { return (bool) ($this->flags & Modifiers::PUBLIC_SET); } /** * Whether the promoted property has explicit protected(set) visibility. */ public function isProtectedSet(): bool { return (bool) ($this->flags & Modifiers::PROTECTED_SET); } /** * Whether the promoted property has explicit private(set) visibility. */ public function isPrivateSet(): bool { return (bool) ($this->flags & Modifiers::PRIVATE_SET); } } ================================================ FILE: lib/PhpParser/Node/PropertyHook.php ================================================ 0 : Flags * 'byRef' => false : Whether hook returns by reference * 'params' => array(): Parameters * 'attrGroups' => array(): PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, $body, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->name = \is_string($name) ? new Identifier($name) : $name; $this->body = $body; $this->flags = $subNodes['flags'] ?? 0; $this->byRef = $subNodes['byRef'] ?? false; $this->params = $subNodes['params'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } public function returnsByRef(): bool { return $this->byRef; } public function getParams(): array { return $this->params; } public function getReturnType() { return null; } /** * Whether the property hook is final. */ public function isFinal(): bool { return (bool) ($this->flags & Modifiers::FINAL); } public function getStmts(): ?array { if ($this->body instanceof Expr) { $name = $this->name->toLowerString(); if ($name === 'get') { return [new Return_($this->body)]; } if ($name === 'set') { if (!$this->hasAttribute('propertyName')) { throw new \LogicException( 'Can only use getStmts() on a "set" hook if the "propertyName" attribute is set'); } $propName = $this->getAttribute('propertyName'); $prop = new PropertyFetch(new Variable('this'), (string) $propName); return [new Expression(new Assign($prop, $this->body))]; } throw new \LogicException('Unknown property hook "' . $name . '"'); } return $this->body; } public function getAttrGroups(): array { return $this->attrGroups; } public function getType(): string { return 'PropertyHook'; } public function getSubNodeNames(): array { return ['attrGroups', 'flags', 'byRef', 'name', 'params', 'body']; } } ================================================ FILE: lib/PhpParser/Node/PropertyItem.php ================================================ $attributes Additional attributes */ public function __construct($name, ?Node\Expr $default = null, array $attributes = []) { $this->attributes = $attributes; $this->name = \is_string($name) ? new Node\VarLikeIdentifier($name) : $name; $this->default = $default; } public function getSubNodeNames(): array { return ['name', 'default']; } public function getType(): string { return 'PropertyItem'; } } // @deprecated compatibility alias class_alias(PropertyItem::class, Stmt\PropertyProperty::class); ================================================ FILE: lib/PhpParser/Node/Scalar/DNumber.php ================================================ $attributes Additional attributes */ public function __construct(float $value, array $attributes = []) { $this->attributes = $attributes; $this->value = $value; } public function getSubNodeNames(): array { return ['value']; } /** * @param mixed[] $attributes */ public static function fromString(string $str, array $attributes = []): Float_ { $attributes['rawValue'] = $str; $float = self::parse($str); return new Float_($float, $attributes); } /** * @internal * * Parses a DNUMBER token like PHP would. * * @param string $str A string number * * @return float The parsed number */ public static function parse(string $str): float { $str = str_replace('_', '', $str); // Check whether this is one of the special integer notations. if ('0' === $str[0]) { // hex if ('x' === $str[1] || 'X' === $str[1]) { return hexdec($str); } // bin if ('b' === $str[1] || 'B' === $str[1]) { return bindec($str); } // oct, but only if the string does not contain any of '.eE'. if (false === strpbrk($str, '.eE')) { // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit // (8 or 9) so that only the digits before that are used. return octdec(substr($str, 0, strcspn($str, '89'))); } } // dec return (float) $str; } public function getType(): string { return 'Scalar_Float'; } } // @deprecated compatibility alias class_alias(Float_::class, DNumber::class); ================================================ FILE: lib/PhpParser/Node/Scalar/Int_.php ================================================ $attributes Additional attributes */ public function __construct(int $value, array $attributes = []) { $this->attributes = $attributes; $this->value = $value; } public function getSubNodeNames(): array { return ['value']; } /** * Constructs an Int node from a string number literal. * * @param string $str String number literal (decimal, octal, hex or binary) * @param array $attributes Additional attributes * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) * * @return Int_ The constructed LNumber, including kind attribute */ public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false): Int_ { $attributes['rawValue'] = $str; $str = str_replace('_', '', $str); if ('0' !== $str[0] || '0' === $str) { $attributes['kind'] = Int_::KIND_DEC; return new Int_((int) $str, $attributes); } if ('x' === $str[1] || 'X' === $str[1]) { $attributes['kind'] = Int_::KIND_HEX; return new Int_(hexdec($str), $attributes); } if ('b' === $str[1] || 'B' === $str[1]) { $attributes['kind'] = Int_::KIND_BIN; return new Int_(bindec($str), $attributes); } if (!$allowInvalidOctal && strpbrk($str, '89')) { throw new Error('Invalid numeric literal', $attributes); } // Strip optional explicit octal prefix. if ('o' === $str[1] || 'O' === $str[1]) { $str = substr($str, 2); } // use intval instead of octdec to get proper cutting behavior with malformed numbers $attributes['kind'] = Int_::KIND_OCT; return new Int_(intval($str, 8), $attributes); } public function getType(): string { return 'Scalar_Int'; } } // @deprecated compatibility alias class_alias(Int_::class, LNumber::class); ================================================ FILE: lib/PhpParser/Node/Scalar/InterpolatedString.php ================================================ $attributes Additional attributes */ public function __construct(array $parts, array $attributes = []) { $this->attributes = $attributes; $this->parts = $parts; } public function getSubNodeNames(): array { return ['parts']; } public function getType(): string { return 'Scalar_InterpolatedString'; } } // @deprecated compatibility alias class_alias(InterpolatedString::class, Encapsed::class); ================================================ FILE: lib/PhpParser/Node/Scalar/LNumber.php ================================================ $attributes Additional attributes */ public function __construct(array $attributes = []) { $this->attributes = $attributes; } public function getSubNodeNames(): array { return []; } /** * Get name of magic constant. * * @return string Name of magic constant */ abstract public function getName(): string; } ================================================ FILE: lib/PhpParser/Node/Scalar/String_.php ================================================ Escaped character to its decoded value */ protected static array $replacements = [ '\\' => '\\', '$' => '$', 'n' => "\n", 'r' => "\r", 't' => "\t", 'f' => "\f", 'v' => "\v", 'e' => "\x1B", ]; /** * Constructs a string scalar node. * * @param string $value Value of the string * @param array $attributes Additional attributes */ public function __construct(string $value, array $attributes = []) { $this->attributes = $attributes; $this->value = $value; } public function getSubNodeNames(): array { return ['value']; } /** * @param array $attributes * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes */ public static function fromString(string $str, array $attributes = [], bool $parseUnicodeEscape = true): self { $attributes['kind'] = ($str[0] === "'" || ($str[1] === "'" && ($str[0] === 'b' || $str[0] === 'B'))) ? Scalar\String_::KIND_SINGLE_QUOTED : Scalar\String_::KIND_DOUBLE_QUOTED; $attributes['rawValue'] = $str; $string = self::parse($str, $parseUnicodeEscape); return new self($string, $attributes); } /** * @internal * * Parses a string token. * * @param string $str String token content * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes * * @return string The parsed string */ public static function parse(string $str, bool $parseUnicodeEscape = true): string { $bLength = 0; if ('b' === $str[0] || 'B' === $str[0]) { $bLength = 1; } if ('\'' === $str[$bLength]) { return str_replace( ['\\\\', '\\\''], ['\\', '\''], substr($str, $bLength + 1, -1) ); } else { return self::parseEscapeSequences( substr($str, $bLength + 1, -1), '"', $parseUnicodeEscape ); } } /** * @internal * * Parses escape sequences in strings (all string types apart from single quoted). * * @param string $str String without quotes * @param null|string $quote Quote type * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes * * @return string String with escape sequences parsed */ public static function parseEscapeSequences(string $str, ?string $quote, bool $parseUnicodeEscape = true): string { if (null !== $quote) { $str = str_replace('\\' . $quote, $quote, $str); } $extra = ''; if ($parseUnicodeEscape) { $extra = '|u\{([0-9a-fA-F]+)\}'; } return preg_replace_callback( '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}' . $extra . ')~', function ($matches) { $str = $matches[1]; if (isset(self::$replacements[$str])) { return self::$replacements[$str]; } if ('x' === $str[0] || 'X' === $str[0]) { return chr(hexdec(substr($str, 1))); } if ('u' === $str[0]) { $dec = hexdec($matches[2]); // If it overflowed to float, treat as INT_MAX, it will throw an error anyway. return self::codePointToUtf8(\is_int($dec) ? $dec : \PHP_INT_MAX); } else { return chr(octdec($str) & 255); } }, $str ); } /** * Converts a Unicode code point to its UTF-8 encoded representation. * * @param int $num Code point * * @return string UTF-8 representation of code point */ private static function codePointToUtf8(int $num): string { if ($num <= 0x7F) { return chr($num); } if ($num <= 0x7FF) { return chr(($num >> 6) + 0xC0) . chr(($num & 0x3F) + 0x80); } if ($num <= 0xFFFF) { return chr(($num >> 12) + 0xE0) . chr((($num >> 6) & 0x3F) + 0x80) . chr(($num & 0x3F) + 0x80); } if ($num <= 0x1FFFFF) { return chr(($num >> 18) + 0xF0) . chr((($num >> 12) & 0x3F) + 0x80) . chr((($num >> 6) & 0x3F) + 0x80) . chr(($num & 0x3F) + 0x80); } throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large'); } public function getType(): string { return 'Scalar_String'; } } ================================================ FILE: lib/PhpParser/Node/Scalar.php ================================================ $attributes Additional attributes */ public function __construct( Expr\Variable $var, ?Node\Expr $default = null, array $attributes = [] ) { $this->attributes = $attributes; $this->var = $var; $this->default = $default; } public function getSubNodeNames(): array { return ['var', 'default']; } public function getType(): string { return 'StaticVar'; } } // @deprecated compatibility alias class_alias(StaticVar::class, Stmt\StaticVar::class); ================================================ FILE: lib/PhpParser/Node/Stmt/Block.php ================================================ $attributes Additional attributes */ public function __construct(array $stmts, array $attributes = []) { $this->attributes = $attributes; $this->stmts = $stmts; } public function getType(): string { return 'Stmt_Block'; } public function getSubNodeNames(): array { return ['stmts']; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Break_.php ================================================ $attributes Additional attributes */ public function __construct(?Node\Expr $num = null, array $attributes = []) { $this->attributes = $attributes; $this->num = $num; } public function getSubNodeNames(): array { return ['num']; } public function getType(): string { return 'Stmt_Break'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Case_.php ================================================ $attributes Additional attributes */ public function __construct(?Node\Expr $cond, array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->cond = $cond; $this->stmts = $stmts; } public function getSubNodeNames(): array { return ['cond', 'stmts']; } public function getType(): string { return 'Stmt_Case'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Catch_.php ================================================ $attributes Additional attributes */ public function __construct( array $types, ?Expr\Variable $var = null, array $stmts = [], array $attributes = [] ) { $this->attributes = $attributes; $this->types = $types; $this->var = $var; $this->stmts = $stmts; } public function getSubNodeNames(): array { return ['types', 'var', 'stmts']; } public function getType(): string { return 'Stmt_Catch'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/ClassConst.php ================================================ $attributes Additional attributes * @param list $attrGroups PHP attribute groups * @param null|Node\Identifier|Node\Name|Node\ComplexType $type Type declaration */ public function __construct( array $consts, int $flags = 0, array $attributes = [], array $attrGroups = [], ?Node $type = null ) { $this->attributes = $attributes; $this->flags = $flags; $this->consts = $consts; $this->attrGroups = $attrGroups; $this->type = $type; } public function getSubNodeNames(): array { return ['attrGroups', 'flags', 'type', 'consts']; } /** * Whether constant is explicitly or implicitly public. */ public function isPublic(): bool { return ($this->flags & Modifiers::PUBLIC) !== 0 || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; } /** * Whether constant is protected. */ public function isProtected(): bool { return (bool) ($this->flags & Modifiers::PROTECTED); } /** * Whether constant is private. */ public function isPrivate(): bool { return (bool) ($this->flags & Modifiers::PRIVATE); } /** * Whether constant is final. */ public function isFinal(): bool { return (bool) ($this->flags & Modifiers::FINAL); } public function getType(): string { return 'Stmt_ClassConst'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/ClassLike.php ================================================ */ public function getTraitUses(): array { $traitUses = []; foreach ($this->stmts as $stmt) { if ($stmt instanceof TraitUse) { $traitUses[] = $stmt; } } return $traitUses; } /** * @return list */ public function getConstants(): array { $constants = []; foreach ($this->stmts as $stmt) { if ($stmt instanceof ClassConst) { $constants[] = $stmt; } } return $constants; } /** * @return list */ public function getProperties(): array { $properties = []; foreach ($this->stmts as $stmt) { if ($stmt instanceof Property) { $properties[] = $stmt; } } return $properties; } /** * Gets property with the given name defined directly in this class/interface/trait. * * @param string $name Name of the property * * @return Property|null Property node or null if the property does not exist */ public function getProperty(string $name): ?Property { foreach ($this->stmts as $stmt) { if ($stmt instanceof Property) { foreach ($stmt->props as $prop) { if ($prop instanceof PropertyItem && $name === $prop->name->toString()) { return $stmt; } } } } return null; } /** * Gets all methods defined directly in this class/interface/trait * * @return list */ public function getMethods(): array { $methods = []; foreach ($this->stmts as $stmt) { if ($stmt instanceof ClassMethod) { $methods[] = $stmt; } } return $methods; } /** * Gets method with the given name defined directly in this class/interface/trait. * * @param string $name Name of the method (compared case-insensitively) * * @return ClassMethod|null Method node or null if the method does not exist */ public function getMethod(string $name): ?ClassMethod { $lowerName = strtolower($name); foreach ($this->stmts as $stmt) { if ($stmt instanceof ClassMethod && $lowerName === $stmt->name->toLowerString()) { return $stmt; } } return null; } } ================================================ FILE: lib/PhpParser/Node/Stmt/ClassMethod.php ================================================ */ private static array $magicNames = [ '__construct' => true, '__destruct' => true, '__call' => true, '__callstatic' => true, '__get' => true, '__set' => true, '__isset' => true, '__unset' => true, '__sleep' => true, '__wakeup' => true, '__tostring' => true, '__set_state' => true, '__clone' => true, '__invoke' => true, '__debuginfo' => true, '__serialize' => true, '__unserialize' => true, ]; /** * Constructs a class method node. * * @param string|Node\Identifier $name Name * @param array{ * flags?: int, * byRef?: bool, * params?: Node\Param[], * returnType?: null|Node\Identifier|Node\Name|Node\ComplexType, * stmts?: Node\Stmt[]|null, * attrGroups?: Node\AttributeGroup[], * } $subNodes Array of the following optional subnodes: * 'flags => 0 : Flags * 'byRef' => false : Whether to return by reference * 'params' => array() : Parameters * 'returnType' => null : Return type * 'stmts' => array() : Statements * 'attrGroups' => array() : PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0; $this->byRef = $subNodes['byRef'] ?? false; $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->params = $subNodes['params'] ?? []; $this->returnType = $subNodes['returnType'] ?? null; $this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } public function getSubNodeNames(): array { return ['attrGroups', 'flags', 'byRef', 'name', 'params', 'returnType', 'stmts']; } public function returnsByRef(): bool { return $this->byRef; } public function getParams(): array { return $this->params; } public function getReturnType() { return $this->returnType; } public function getStmts(): ?array { return $this->stmts; } public function getAttrGroups(): array { return $this->attrGroups; } /** * Whether the method is explicitly or implicitly public. */ public function isPublic(): bool { return ($this->flags & Modifiers::PUBLIC) !== 0 || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; } /** * Whether the method is protected. */ public function isProtected(): bool { return (bool) ($this->flags & Modifiers::PROTECTED); } /** * Whether the method is private. */ public function isPrivate(): bool { return (bool) ($this->flags & Modifiers::PRIVATE); } /** * Whether the method is abstract. */ public function isAbstract(): bool { return (bool) ($this->flags & Modifiers::ABSTRACT); } /** * Whether the method is final. */ public function isFinal(): bool { return (bool) ($this->flags & Modifiers::FINAL); } /** * Whether the method is static. */ public function isStatic(): bool { return (bool) ($this->flags & Modifiers::STATIC); } /** * Whether the method is magic. */ public function isMagic(): bool { return isset(self::$magicNames[$this->name->toLowerString()]); } public function getType(): string { return 'Stmt_ClassMethod'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Class_.php ================================================ 0 : Flags * 'extends' => null : Name of extended class * 'implements' => array(): Names of implemented interfaces * 'stmts' => array(): Statements * 'attrGroups' => array(): PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0; $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->extends = $subNodes['extends'] ?? null; $this->implements = $subNodes['implements'] ?? []; $this->stmts = $subNodes['stmts'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } public function getSubNodeNames(): array { return ['attrGroups', 'flags', 'name', 'extends', 'implements', 'stmts']; } /** * Whether the class is explicitly abstract. */ public function isAbstract(): bool { return (bool) ($this->flags & Modifiers::ABSTRACT); } /** * Whether the class is final. */ public function isFinal(): bool { return (bool) ($this->flags & Modifiers::FINAL); } public function isReadonly(): bool { return (bool) ($this->flags & Modifiers::READONLY); } /** * Whether the class is anonymous. */ public function isAnonymous(): bool { return null === $this->name; } public function getType(): string { return 'Stmt_Class'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Const_.php ================================================ $attributes Additional attributes * @param list $attrGroups PHP attribute groups */ public function __construct( array $consts, array $attributes = [], array $attrGroups = [] ) { $this->attributes = $attributes; $this->attrGroups = $attrGroups; $this->consts = $consts; } public function getSubNodeNames(): array { return ['attrGroups', 'consts']; } public function getType(): string { return 'Stmt_Const'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Continue_.php ================================================ $attributes Additional attributes */ public function __construct(?Node\Expr $num = null, array $attributes = []) { $this->attributes = $attributes; $this->num = $num; } public function getSubNodeNames(): array { return ['num']; } public function getType(): string { return 'Stmt_Continue'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/DeclareDeclare.php ================================================ $attributes Additional attributes */ public function __construct(array $declares, ?array $stmts = null, array $attributes = []) { $this->attributes = $attributes; $this->declares = $declares; $this->stmts = $stmts; } public function getSubNodeNames(): array { return ['declares', 'stmts']; } public function getType(): string { return 'Stmt_Declare'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Do_.php ================================================ $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->cond = $cond; $this->stmts = $stmts; } public function getSubNodeNames(): array { return ['stmts', 'cond']; } public function getType(): string { return 'Stmt_Do'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Echo_.php ================================================ $attributes Additional attributes */ public function __construct(array $exprs, array $attributes = []) { $this->attributes = $attributes; $this->exprs = $exprs; } public function getSubNodeNames(): array { return ['exprs']; } public function getType(): string { return 'Stmt_Echo'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/ElseIf_.php ================================================ $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->cond = $cond; $this->stmts = $stmts; } public function getSubNodeNames(): array { return ['cond', 'stmts']; } public function getType(): string { return 'Stmt_ElseIf'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Else_.php ================================================ $attributes Additional attributes */ public function __construct(array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->stmts = $stmts; } public function getSubNodeNames(): array { return ['stmts']; } public function getType(): string { return 'Stmt_Else'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/EnumCase.php ================================================ $attrGroups PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, ?Node\Expr $expr = null, array $attrGroups = [], array $attributes = []) { parent::__construct($attributes); $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->expr = $expr; $this->attrGroups = $attrGroups; } public function getSubNodeNames(): array { return ['attrGroups', 'name', 'expr']; } public function getType(): string { return 'Stmt_EnumCase'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Enum_.php ================================================ null : Scalar type * 'implements' => array() : Names of implemented interfaces * 'stmts' => array() : Statements * 'attrGroups' => array() : PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->scalarType = $subNodes['scalarType'] ?? null; $this->implements = $subNodes['implements'] ?? []; $this->stmts = $subNodes['stmts'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; parent::__construct($attributes); } public function getSubNodeNames(): array { return ['attrGroups', 'name', 'scalarType', 'implements', 'stmts']; } public function getType(): string { return 'Stmt_Enum'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Expression.php ================================================ $attributes Additional attributes */ public function __construct(Node\Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Stmt_Expression'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Finally_.php ================================================ $attributes Additional attributes */ public function __construct(array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->stmts = $stmts; } public function getSubNodeNames(): array { return ['stmts']; } public function getType(): string { return 'Stmt_Finally'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/For_.php ================================================ array(): Init expressions * 'cond' => array(): Loop conditions * 'loop' => array(): Loop expressions * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct(array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->init = $subNodes['init'] ?? []; $this->cond = $subNodes['cond'] ?? []; $this->loop = $subNodes['loop'] ?? []; $this->stmts = $subNodes['stmts'] ?? []; } public function getSubNodeNames(): array { return ['init', 'cond', 'loop', 'stmts']; } public function getType(): string { return 'Stmt_For'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Foreach_.php ================================================ null : Variable to assign key to * 'byRef' => false : Whether to assign value by reference * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; $this->keyVar = $subNodes['keyVar'] ?? null; $this->byRef = $subNodes['byRef'] ?? false; $this->valueVar = $valueVar; $this->stmts = $subNodes['stmts'] ?? []; } public function getSubNodeNames(): array { return ['expr', 'keyVar', 'byRef', 'valueVar', 'stmts']; } public function getType(): string { return 'Stmt_Foreach'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Function_.php ================================================ false : Whether to return by reference * 'params' => array(): Parameters * 'returnType' => null : Return type * 'stmts' => array(): Statements * 'attrGroups' => array(): PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->byRef = $subNodes['byRef'] ?? false; $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->params = $subNodes['params'] ?? []; $this->returnType = $subNodes['returnType'] ?? null; $this->stmts = $subNodes['stmts'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } public function getSubNodeNames(): array { return ['attrGroups', 'byRef', 'name', 'params', 'returnType', 'stmts']; } public function returnsByRef(): bool { return $this->byRef; } public function getParams(): array { return $this->params; } public function getReturnType() { return $this->returnType; } public function getAttrGroups(): array { return $this->attrGroups; } /** @return Node\Stmt[] */ public function getStmts(): array { return $this->stmts; } public function getType(): string { return 'Stmt_Function'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Global_.php ================================================ $attributes Additional attributes */ public function __construct(array $vars, array $attributes = []) { $this->attributes = $attributes; $this->vars = $vars; } public function getSubNodeNames(): array { return ['vars']; } public function getType(): string { return 'Stmt_Global'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Goto_.php ================================================ $attributes Additional attributes */ public function __construct($name, array $attributes = []) { $this->attributes = $attributes; $this->name = \is_string($name) ? new Identifier($name) : $name; } public function getSubNodeNames(): array { return ['name']; } public function getType(): string { return 'Stmt_Goto'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/GroupUse.php ================================================ $attributes Additional attributes */ public function __construct(Name $prefix, array $uses, int $type = Use_::TYPE_NORMAL, array $attributes = []) { $this->attributes = $attributes; $this->type = $type; $this->prefix = $prefix; $this->uses = $uses; } public function getSubNodeNames(): array { return ['type', 'prefix', 'uses']; } public function getType(): string { return 'Stmt_GroupUse'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/HaltCompiler.php ================================================ $attributes Additional attributes */ public function __construct(string $remaining, array $attributes = []) { $this->attributes = $attributes; $this->remaining = $remaining; } public function getSubNodeNames(): array { return ['remaining']; } public function getType(): string { return 'Stmt_HaltCompiler'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/If_.php ================================================ array(): Statements * 'elseifs' => array(): Elseif clauses * 'else' => null : Else clause * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->cond = $cond; $this->stmts = $subNodes['stmts'] ?? []; $this->elseifs = $subNodes['elseifs'] ?? []; $this->else = $subNodes['else'] ?? null; } public function getSubNodeNames(): array { return ['cond', 'stmts', 'elseifs', 'else']; } public function getType(): string { return 'Stmt_If'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/InlineHTML.php ================================================ $attributes Additional attributes */ public function __construct(string $value, array $attributes = []) { $this->attributes = $attributes; $this->value = $value; } public function getSubNodeNames(): array { return ['value']; } public function getType(): string { return 'Stmt_InlineHTML'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Interface_.php ================================================ array(): Name of extended interfaces * 'stmts' => array(): Statements * 'attrGroups' => array(): PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->extends = $subNodes['extends'] ?? []; $this->stmts = $subNodes['stmts'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } public function getSubNodeNames(): array { return ['attrGroups', 'name', 'extends', 'stmts']; } public function getType(): string { return 'Stmt_Interface'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Label.php ================================================ $attributes Additional attributes */ public function __construct($name, array $attributes = []) { $this->attributes = $attributes; $this->name = \is_string($name) ? new Identifier($name) : $name; } public function getSubNodeNames(): array { return ['name']; } public function getType(): string { return 'Stmt_Label'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Namespace_.php ================================================ $attributes Additional attributes */ public function __construct(?Node\Name $name = null, ?array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->name = $name; $this->stmts = $stmts; } public function getSubNodeNames(): array { return ['name', 'stmts']; } public function getType(): string { return 'Stmt_Namespace'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Nop.php ================================================ $attributes Additional attributes * @param null|Identifier|Name|ComplexType $type Type declaration * @param Node\AttributeGroup[] $attrGroups PHP attribute groups * @param Node\PropertyHook[] $hooks Property hooks */ public function __construct(int $flags, array $props, array $attributes = [], ?Node $type = null, array $attrGroups = [], array $hooks = []) { $this->attributes = $attributes; $this->flags = $flags; $this->props = $props; $this->type = $type; $this->attrGroups = $attrGroups; $this->hooks = $hooks; } public function getSubNodeNames(): array { return ['attrGroups', 'flags', 'type', 'props', 'hooks']; } /** * Whether the property is explicitly or implicitly public. */ public function isPublic(): bool { return ($this->flags & Modifiers::PUBLIC) !== 0 || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; } /** * Whether the property is protected. */ public function isProtected(): bool { return (bool) ($this->flags & Modifiers::PROTECTED); } /** * Whether the property is private. */ public function isPrivate(): bool { return (bool) ($this->flags & Modifiers::PRIVATE); } /** * Whether the property is static. */ public function isStatic(): bool { return (bool) ($this->flags & Modifiers::STATIC); } /** * Whether the property is readonly. */ public function isReadonly(): bool { return (bool) ($this->flags & Modifiers::READONLY); } /** * Whether the property is abstract. */ public function isAbstract(): bool { return (bool) ($this->flags & Modifiers::ABSTRACT); } /** * Whether the property is final. */ public function isFinal(): bool { return (bool) ($this->flags & Modifiers::FINAL); } /** * Whether the property has explicit public(set) visibility. */ public function isPublicSet(): bool { return (bool) ($this->flags & Modifiers::PUBLIC_SET); } /** * Whether the property has explicit protected(set) visibility. */ public function isProtectedSet(): bool { return (bool) ($this->flags & Modifiers::PROTECTED_SET); } /** * Whether the property has explicit private(set) visibility. */ public function isPrivateSet(): bool { return (bool) ($this->flags & Modifiers::PRIVATE_SET); } public function getType(): string { return 'Stmt_Property'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/PropertyProperty.php ================================================ $attributes Additional attributes */ public function __construct(?Node\Expr $expr = null, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } public function getSubNodeNames(): array { return ['expr']; } public function getType(): string { return 'Stmt_Return'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/StaticVar.php ================================================ $attributes Additional attributes */ public function __construct(array $vars, array $attributes = []) { $this->attributes = $attributes; $this->vars = $vars; } public function getSubNodeNames(): array { return ['vars']; } public function getType(): string { return 'Stmt_Static'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Switch_.php ================================================ $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $cases, array $attributes = []) { $this->attributes = $attributes; $this->cond = $cond; $this->cases = $cases; } public function getSubNodeNames(): array { return ['cond', 'cases']; } public function getType(): string { return 'Stmt_Switch'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/TraitUse.php ================================================ $attributes Additional attributes */ public function __construct(array $traits, array $adaptations = [], array $attributes = []) { $this->attributes = $attributes; $this->traits = $traits; $this->adaptations = $adaptations; } public function getSubNodeNames(): array { return ['traits', 'adaptations']; } public function getType(): string { return 'Stmt_TraitUse'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php ================================================ $attributes Additional attributes */ public function __construct(?Node\Name $trait, $method, ?int $newModifier, $newName, array $attributes = []) { $this->attributes = $attributes; $this->trait = $trait; $this->method = \is_string($method) ? new Node\Identifier($method) : $method; $this->newModifier = $newModifier; $this->newName = \is_string($newName) ? new Node\Identifier($newName) : $newName; } public function getSubNodeNames(): array { return ['trait', 'method', 'newModifier', 'newName']; } public function getType(): string { return 'Stmt_TraitUseAdaptation_Alias'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php ================================================ $attributes Additional attributes */ public function __construct(Node\Name $trait, $method, array $insteadof, array $attributes = []) { $this->attributes = $attributes; $this->trait = $trait; $this->method = \is_string($method) ? new Node\Identifier($method) : $method; $this->insteadof = $insteadof; } public function getSubNodeNames(): array { return ['trait', 'method', 'insteadof']; } public function getType(): string { return 'Stmt_TraitUseAdaptation_Precedence'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/TraitUseAdaptation.php ================================================ array(): Statements * 'attrGroups' => array(): PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->stmts = $subNodes['stmts'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } public function getSubNodeNames(): array { return ['attrGroups', 'name', 'stmts']; } public function getType(): string { return 'Stmt_Trait'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/TryCatch.php ================================================ $attributes Additional attributes */ public function __construct(array $stmts, array $catches, ?Finally_ $finally = null, array $attributes = []) { $this->attributes = $attributes; $this->stmts = $stmts; $this->catches = $catches; $this->finally = $finally; } public function getSubNodeNames(): array { return ['stmts', 'catches', 'finally']; } public function getType(): string { return 'Stmt_TryCatch'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/Unset_.php ================================================ $attributes Additional attributes */ public function __construct(array $vars, array $attributes = []) { $this->attributes = $attributes; $this->vars = $vars; } public function getSubNodeNames(): array { return ['vars']; } public function getType(): string { return 'Stmt_Unset'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/UseUse.php ================================================ $attributes Additional attributes */ public function __construct(array $uses, int $type = self::TYPE_NORMAL, array $attributes = []) { $this->attributes = $attributes; $this->type = $type; $this->uses = $uses; } public function getSubNodeNames(): array { return ['type', 'uses']; } public function getType(): string { return 'Stmt_Use'; } } ================================================ FILE: lib/PhpParser/Node/Stmt/While_.php ================================================ $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->cond = $cond; $this->stmts = $stmts; } public function getSubNodeNames(): array { return ['cond', 'stmts']; } public function getType(): string { return 'Stmt_While'; } } ================================================ FILE: lib/PhpParser/Node/Stmt.php ================================================ $attributes Additional attributes */ public function __construct(array $types, array $attributes = []) { $this->attributes = $attributes; $this->types = $types; } public function getSubNodeNames(): array { return ['types']; } public function getType(): string { return 'UnionType'; } } ================================================ FILE: lib/PhpParser/Node/UseItem.php ================================================ $attributes Additional attributes */ public function __construct(Node\Name $name, $alias = null, int $type = Use_::TYPE_UNKNOWN, array $attributes = []) { $this->attributes = $attributes; $this->type = $type; $this->name = $name; $this->alias = \is_string($alias) ? new Identifier($alias) : $alias; } public function getSubNodeNames(): array { return ['type', 'name', 'alias']; } /** * Get alias. If not explicitly given this is the last component of the used name. */ public function getAlias(): Identifier { if (null !== $this->alias) { return $this->alias; } return new Identifier($this->name->getLast()); } public function getType(): string { return 'UseItem'; } } // @deprecated compatibility alias class_alias(UseItem::class, Stmt\UseUse::class); ================================================ FILE: lib/PhpParser/Node/VarLikeIdentifier.php ================================================ $attributes Additional attributes */ public function __construct(array $attributes = []) { $this->attributes = $attributes; } public function getType(): string { return 'VariadicPlaceholder'; } public function getSubNodeNames(): array { return []; } } ================================================ FILE: lib/PhpParser/Node.php ================================================ */ public function getAttributes(): array; /** * Replaces all the attributes of this node. * * @param array $attributes */ public function setAttributes(array $attributes): void; } ================================================ FILE: lib/PhpParser/NodeAbstract.php ================================================ Attributes */ protected array $attributes; /** * Creates a Node. * * @param array $attributes Array of attributes */ public function __construct(array $attributes = []) { $this->attributes = $attributes; } /** * Gets line the node started in (alias of getStartLine). * * @return int Start line (or -1 if not available) * @phpstan-return -1|positive-int */ public function getLine(): int { return $this->attributes['startLine'] ?? -1; } /** * Gets line the node started in. * * Requires the 'startLine' attribute to be enabled in the lexer (enabled by default). * * @return int Start line (or -1 if not available) * @phpstan-return -1|positive-int */ public function getStartLine(): int { return $this->attributes['startLine'] ?? -1; } /** * Gets the line the node ended in. * * Requires the 'endLine' attribute to be enabled in the lexer (enabled by default). * * @return int End line (or -1 if not available) * @phpstan-return -1|positive-int */ public function getEndLine(): int { return $this->attributes['endLine'] ?? -1; } /** * Gets the token offset of the first token that is part of this node. * * The offset is an index into the array returned by Lexer::getTokens(). * * Requires the 'startTokenPos' attribute to be enabled in the lexer (DISABLED by default). * * @return int Token start position (or -1 if not available) */ public function getStartTokenPos(): int { return $this->attributes['startTokenPos'] ?? -1; } /** * Gets the token offset of the last token that is part of this node. * * The offset is an index into the array returned by Lexer::getTokens(). * * Requires the 'endTokenPos' attribute to be enabled in the lexer (DISABLED by default). * * @return int Token end position (or -1 if not available) */ public function getEndTokenPos(): int { return $this->attributes['endTokenPos'] ?? -1; } /** * Gets the file offset of the first character that is part of this node. * * Requires the 'startFilePos' attribute to be enabled in the lexer (DISABLED by default). * * @return int File start position (or -1 if not available) */ public function getStartFilePos(): int { return $this->attributes['startFilePos'] ?? -1; } /** * Gets the file offset of the last character that is part of this node. * * Requires the 'endFilePos' attribute to be enabled in the lexer (DISABLED by default). * * @return int File end position (or -1 if not available) */ public function getEndFilePos(): int { return $this->attributes['endFilePos'] ?? -1; } /** * Gets all comments directly preceding this node. * * The comments are also available through the "comments" attribute. * * @return Comment[] */ public function getComments(): array { return $this->attributes['comments'] ?? []; } /** * Gets the doc comment of the node. * * @return null|Comment\Doc Doc comment object or null */ public function getDocComment(): ?Comment\Doc { $comments = $this->getComments(); for ($i = count($comments) - 1; $i >= 0; $i--) { $comment = $comments[$i]; if ($comment instanceof Comment\Doc) { return $comment; } } return null; } /** * Sets the doc comment of the node. * * This will either replace an existing doc comment or add it to the comments array. * * @param Comment\Doc $docComment Doc comment to set */ public function setDocComment(Comment\Doc $docComment): void { $comments = $this->getComments(); for ($i = count($comments) - 1; $i >= 0; $i--) { if ($comments[$i] instanceof Comment\Doc) { // Replace existing doc comment. $comments[$i] = $docComment; $this->setAttribute('comments', $comments); return; } } // Append new doc comment. $comments[] = $docComment; $this->setAttribute('comments', $comments); } public function setAttribute(string $key, $value): void { $this->attributes[$key] = $value; } public function hasAttribute(string $key): bool { return array_key_exists($key, $this->attributes); } public function getAttribute(string $key, $default = null) { if (array_key_exists($key, $this->attributes)) { return $this->attributes[$key]; } return $default; } public function getAttributes(): array { return $this->attributes; } public function setAttributes(array $attributes): void { $this->attributes = $attributes; } /** * @return array */ public function jsonSerialize(): array { return ['nodeType' => $this->getType()] + get_object_vars($this); } } ================================================ FILE: lib/PhpParser/NodeDumper.php ================================================ true, 'startLine' => true, 'endLine' => true, 'startFilePos' => true, 'endFilePos' => true, 'startTokenPos' => true, 'endTokenPos' => true, ]; /** * Constructs a NodeDumper. * * Supported options: * * bool dumpComments: Whether comments should be dumped. * * bool dumpPositions: Whether line/offset information should be dumped. To dump offset * information, the code needs to be passed to dump(). * * bool dumpOtherAttributes: Whether non-comment, non-position attributes should be dumped. * * @param array $options Options (see description) */ public function __construct(array $options = []) { $this->dumpComments = !empty($options['dumpComments']); $this->dumpPositions = !empty($options['dumpPositions']); $this->dumpOtherAttributes = !empty($options['dumpOtherAttributes']); } /** * Dumps a node or array. * * @param array|Node $node Node or array to dump * @param string|null $code Code corresponding to dumped AST. This only needs to be passed if * the dumpPositions option is enabled and the dumping of node offsets * is desired. * * @return string Dumped value */ public function dump($node, ?string $code = null): string { $this->code = $code; $this->res = ''; $this->nl = "\n"; $this->dumpRecursive($node, false); return $this->res; } /** @param mixed $node */ protected function dumpRecursive($node, bool $indent = true): void { if ($indent) { $this->nl .= " "; } if ($node instanceof Node) { $this->res .= $node->getType(); if ($this->dumpPositions && null !== $p = $this->dumpPosition($node)) { $this->res .= $p; } $this->res .= '('; foreach ($node->getSubNodeNames() as $key) { $this->res .= "$this->nl " . $key . ': '; $value = $node->$key; if (\is_int($value)) { if ('flags' === $key || 'newModifier' === $key) { $this->res .= $this->dumpFlags($value); continue; } if ('type' === $key && $node instanceof Include_) { $this->res .= $this->dumpIncludeType($value); continue; } if ('type' === $key && ($node instanceof Use_ || $node instanceof UseItem || $node instanceof GroupUse)) { $this->res .= $this->dumpUseType($value); continue; } } $this->dumpRecursive($value); } if ($this->dumpComments && $comments = $node->getComments()) { $this->res .= "$this->nl comments: "; $this->dumpRecursive($comments); } if ($this->dumpOtherAttributes) { foreach ($node->getAttributes() as $key => $value) { if (isset(self::IGNORE_ATTRIBUTES[$key])) { continue; } $this->res .= "$this->nl $key: "; if (\is_int($value)) { if ('kind' === $key) { if ($node instanceof Int_) { $this->res .= $this->dumpIntKind($value); continue; } if ($node instanceof String_ || $node instanceof InterpolatedString) { $this->res .= $this->dumpStringKind($value); continue; } if ($node instanceof Array_) { $this->res .= $this->dumpArrayKind($value); continue; } if ($node instanceof List_) { $this->res .= $this->dumpListKind($value); continue; } } } $this->dumpRecursive($value); } } $this->res .= "$this->nl)"; } elseif (\is_array($node)) { $this->res .= 'array('; foreach ($node as $key => $value) { $this->res .= "$this->nl " . $key . ': '; $this->dumpRecursive($value); } $this->res .= "$this->nl)"; } elseif ($node instanceof Comment) { $this->res .= \str_replace("\n", $this->nl, $node->getReformattedText()); } elseif (\is_string($node)) { $this->res .= \str_replace("\n", $this->nl, $node); } elseif (\is_int($node) || \is_float($node)) { $this->res .= $node; } elseif (null === $node) { $this->res .= 'null'; } elseif (false === $node) { $this->res .= 'false'; } elseif (true === $node) { $this->res .= 'true'; } else { throw new \InvalidArgumentException('Can only dump nodes and arrays.'); } if ($indent) { $this->nl = \substr($this->nl, 0, -4); } } protected function dumpFlags(int $flags): string { $strs = []; if ($flags & Modifiers::PUBLIC) { $strs[] = 'PUBLIC'; } if ($flags & Modifiers::PROTECTED) { $strs[] = 'PROTECTED'; } if ($flags & Modifiers::PRIVATE) { $strs[] = 'PRIVATE'; } if ($flags & Modifiers::ABSTRACT) { $strs[] = 'ABSTRACT'; } if ($flags & Modifiers::STATIC) { $strs[] = 'STATIC'; } if ($flags & Modifiers::FINAL) { $strs[] = 'FINAL'; } if ($flags & Modifiers::READONLY) { $strs[] = 'READONLY'; } if ($flags & Modifiers::PUBLIC_SET) { $strs[] = 'PUBLIC_SET'; } if ($flags & Modifiers::PROTECTED_SET) { $strs[] = 'PROTECTED_SET'; } if ($flags & Modifiers::PRIVATE_SET) { $strs[] = 'PRIVATE_SET'; } if ($strs) { return implode(' | ', $strs) . ' (' . $flags . ')'; } else { return (string) $flags; } } /** @param array $map */ private function dumpEnum(int $value, array $map): string { if (!isset($map[$value])) { return (string) $value; } return $map[$value] . ' (' . $value . ')'; } private function dumpIncludeType(int $type): string { return $this->dumpEnum($type, [ Include_::TYPE_INCLUDE => 'TYPE_INCLUDE', Include_::TYPE_INCLUDE_ONCE => 'TYPE_INCLUDE_ONCE', Include_::TYPE_REQUIRE => 'TYPE_REQUIRE', Include_::TYPE_REQUIRE_ONCE => 'TYPE_REQUIRE_ONCE', ]); } private function dumpUseType(int $type): string { return $this->dumpEnum($type, [ Use_::TYPE_UNKNOWN => 'TYPE_UNKNOWN', Use_::TYPE_NORMAL => 'TYPE_NORMAL', Use_::TYPE_FUNCTION => 'TYPE_FUNCTION', Use_::TYPE_CONSTANT => 'TYPE_CONSTANT', ]); } private function dumpIntKind(int $kind): string { return $this->dumpEnum($kind, [ Int_::KIND_BIN => 'KIND_BIN', Int_::KIND_OCT => 'KIND_OCT', Int_::KIND_DEC => 'KIND_DEC', Int_::KIND_HEX => 'KIND_HEX', ]); } private function dumpStringKind(int $kind): string { return $this->dumpEnum($kind, [ String_::KIND_SINGLE_QUOTED => 'KIND_SINGLE_QUOTED', String_::KIND_DOUBLE_QUOTED => 'KIND_DOUBLE_QUOTED', String_::KIND_HEREDOC => 'KIND_HEREDOC', String_::KIND_NOWDOC => 'KIND_NOWDOC', ]); } private function dumpArrayKind(int $kind): string { return $this->dumpEnum($kind, [ Array_::KIND_LONG => 'KIND_LONG', Array_::KIND_SHORT => 'KIND_SHORT', ]); } private function dumpListKind(int $kind): string { return $this->dumpEnum($kind, [ List_::KIND_LIST => 'KIND_LIST', List_::KIND_ARRAY => 'KIND_ARRAY', ]); } /** * Dump node position, if possible. * * @param Node $node Node for which to dump position * * @return string|null Dump of position, or null if position information not available */ protected function dumpPosition(Node $node): ?string { if (!$node->hasAttribute('startLine') || !$node->hasAttribute('endLine')) { return null; } $start = $node->getStartLine(); $end = $node->getEndLine(); if ($node->hasAttribute('startFilePos') && $node->hasAttribute('endFilePos') && null !== $this->code ) { $start .= ':' . $this->toColumn($this->code, $node->getStartFilePos()); $end .= ':' . $this->toColumn($this->code, $node->getEndFilePos()); } return "[$start - $end]"; } // Copied from Error class private function toColumn(string $code, int $pos): int { if ($pos > strlen($code)) { throw new \RuntimeException('Invalid position information'); } $lineStartPos = strrpos($code, "\n", $pos - strlen($code)); if (false === $lineStartPos) { $lineStartPos = -1; } return $pos - $lineStartPos; } } ================================================ FILE: lib/PhpParser/NodeFinder.php ================================================ traverse($nodes); return $visitor->getFoundNodes(); } /** * Find all nodes that are instances of a certain class. * @template TNode as Node * * @param Node|Node[] $nodes Single node or array of nodes to search in * @param class-string $class Class name * * @return TNode[] Found nodes (all instances of $class) */ public function findInstanceOf($nodes, string $class): array { return $this->find($nodes, function ($node) use ($class) { return $node instanceof $class; }); } /** * Find first node satisfying a filter callback. * * @param Node|Node[] $nodes Single node or array of nodes to search in * @param callable $filter Filter callback: function(Node $node) : bool * * @return null|Node Found node (or null if none found) */ public function findFirst($nodes, callable $filter): ?Node { if ($nodes === []) { return null; } if (!is_array($nodes)) { $nodes = [$nodes]; } $visitor = new FirstFindingVisitor($filter); $traverser = new NodeTraverser($visitor); $traverser->traverse($nodes); return $visitor->getFoundNode(); } /** * Find first node that is an instance of a certain class. * * @template TNode as Node * * @param Node|Node[] $nodes Single node or array of nodes to search in * @param class-string $class Class name * * @return null|TNode Found node, which is an instance of $class (or null if none found) */ public function findFirstInstanceOf($nodes, string $class): ?Node { return $this->findFirst($nodes, function ($node) use ($class) { return $node instanceof $class; }); } } ================================================ FILE: lib/PhpParser/NodeTraverser.php ================================================ Visitors */ protected array $visitors = []; /** @var bool Whether traversal should be stopped */ protected bool $stopTraversal; /** * Create a traverser with the given visitors. * * @param NodeVisitor ...$visitors Node visitors */ public function __construct(NodeVisitor ...$visitors) { $this->visitors = $visitors; } /** * Adds a visitor. * * @param NodeVisitor $visitor Visitor to add */ public function addVisitor(NodeVisitor $visitor): void { $this->visitors[] = $visitor; } /** * Removes an added visitor. */ public function removeVisitor(NodeVisitor $visitor): void { $index = array_search($visitor, $this->visitors); if ($index !== false) { array_splice($this->visitors, $index, 1, []); } } /** * Traverses an array of nodes using the registered visitors. * * @param Node[] $nodes Array of nodes * * @return Node[] Traversed array of nodes */ public function traverse(array $nodes): array { $this->stopTraversal = false; foreach ($this->visitors as $visitor) { if (null !== $return = $visitor->beforeTraverse($nodes)) { $nodes = $return; } } $nodes = $this->traverseArray($nodes); for ($i = \count($this->visitors) - 1; $i >= 0; --$i) { $visitor = $this->visitors[$i]; if (null !== $return = $visitor->afterTraverse($nodes)) { $nodes = $return; } } return $nodes; } /** * Recursively traverse a node. * * @param Node $node Node to traverse. */ protected function traverseNode(Node $node): void { foreach ($node->getSubNodeNames() as $name) { $subNode = $node->$name; if (\is_array($subNode)) { $node->$name = $this->traverseArray($subNode); if ($this->stopTraversal) { break; } continue; } if (!$subNode instanceof Node) { continue; } $traverseChildren = true; $visitorIndex = -1; foreach ($this->visitors as $visitorIndex => $visitor) { $return = $visitor->enterNode($subNode); if (null !== $return) { if ($return instanceof Node) { $this->ensureReplacementReasonable($subNode, $return); $subNode = $node->$name = $return; } elseif (NodeVisitor::DONT_TRAVERSE_CHILDREN === $return) { $traverseChildren = false; } elseif (NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) { $traverseChildren = false; break; } elseif (NodeVisitor::STOP_TRAVERSAL === $return) { $this->stopTraversal = true; break 2; } elseif (NodeVisitor::REPLACE_WITH_NULL === $return) { $node->$name = null; continue 2; } else { throw new \LogicException( 'enterNode() returned invalid value of type ' . gettype($return) ); } } } if ($traverseChildren) { $this->traverseNode($subNode); if ($this->stopTraversal) { break; } } for (; $visitorIndex >= 0; --$visitorIndex) { $visitor = $this->visitors[$visitorIndex]; $return = $visitor->leaveNode($subNode); if (null !== $return) { if ($return instanceof Node) { $this->ensureReplacementReasonable($subNode, $return); $subNode = $node->$name = $return; } elseif (NodeVisitor::STOP_TRAVERSAL === $return) { $this->stopTraversal = true; break 2; } elseif (NodeVisitor::REPLACE_WITH_NULL === $return) { $node->$name = null; break; } elseif (\is_array($return)) { throw new \LogicException( 'leaveNode() may only return an array ' . 'if the parent structure is an array' ); } else { throw new \LogicException( 'leaveNode() returned invalid value of type ' . gettype($return) ); } } } } } /** * Recursively traverse array (usually of nodes). * * @param Node[] $nodes Array to traverse * * @return Node[] Result of traversal (may be original array or changed one) */ protected function traverseArray(array $nodes): array { $doNodes = []; foreach ($nodes as $i => $node) { if (!$node instanceof Node) { if (\is_array($node)) { throw new \LogicException('Invalid node structure: Contains nested arrays'); } continue; } $traverseChildren = true; $visitorIndex = -1; foreach ($this->visitors as $visitorIndex => $visitor) { $return = $visitor->enterNode($node); if (null !== $return) { if ($return instanceof Node) { $this->ensureReplacementReasonable($node, $return); $nodes[$i] = $node = $return; } elseif (\is_array($return)) { $doNodes[] = [$i, $return]; continue 2; } elseif (NodeVisitor::REMOVE_NODE === $return) { $doNodes[] = [$i, []]; continue 2; } elseif (NodeVisitor::DONT_TRAVERSE_CHILDREN === $return) { $traverseChildren = false; } elseif (NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) { $traverseChildren = false; break; } elseif (NodeVisitor::STOP_TRAVERSAL === $return) { $this->stopTraversal = true; break 2; } elseif (NodeVisitor::REPLACE_WITH_NULL === $return) { throw new \LogicException( 'REPLACE_WITH_NULL can not be used if the parent structure is an array'); } else { throw new \LogicException( 'enterNode() returned invalid value of type ' . gettype($return) ); } } } if ($traverseChildren) { $this->traverseNode($node); if ($this->stopTraversal) { break; } } for (; $visitorIndex >= 0; --$visitorIndex) { $visitor = $this->visitors[$visitorIndex]; $return = $visitor->leaveNode($node); if (null !== $return) { if ($return instanceof Node) { $this->ensureReplacementReasonable($node, $return); $nodes[$i] = $node = $return; } elseif (\is_array($return)) { $doNodes[] = [$i, $return]; break; } elseif (NodeVisitor::REMOVE_NODE === $return) { $doNodes[] = [$i, []]; break; } elseif (NodeVisitor::STOP_TRAVERSAL === $return) { $this->stopTraversal = true; break 2; } elseif (NodeVisitor::REPLACE_WITH_NULL === $return) { throw new \LogicException( 'REPLACE_WITH_NULL can not be used if the parent structure is an array'); } else { throw new \LogicException( 'leaveNode() returned invalid value of type ' . gettype($return) ); } } } } if (!empty($doNodes)) { while (list($i, $replace) = array_pop($doNodes)) { array_splice($nodes, $i, 1, $replace); } } return $nodes; } private function ensureReplacementReasonable(Node $old, Node $new): void { if ($old instanceof Node\Stmt && $new instanceof Node\Expr) { throw new \LogicException( "Trying to replace statement ({$old->getType()}) " . "with expression ({$new->getType()}). Are you missing a " . "Stmt_Expression wrapper?" ); } if ($old instanceof Node\Expr && $new instanceof Node\Stmt) { throw new \LogicException( "Trying to replace expression ({$old->getType()}) " . "with statement ({$new->getType()})" ); } } } ================================================ FILE: lib/PhpParser/NodeTraverserInterface.php ================================================ setAttribute('origNode', $origNode); return $node; } } ================================================ FILE: lib/PhpParser/NodeVisitor/CommentAnnotatingVisitor.php ================================================ Token positions of comments */ private array $commentPositions = []; /** * Create a comment annotation visitor. * * @param Token[] $tokens Token array */ public function __construct(array $tokens) { $this->tokens = $tokens; // Collect positions of comments. We use this to avoid traversing parts of the AST where // there are no comments. foreach ($tokens as $i => $token) { if ($token->id === \T_COMMENT || $token->id === \T_DOC_COMMENT) { $this->commentPositions[] = $i; } } } public function enterNode(Node $node) { $nextCommentPos = current($this->commentPositions); if ($nextCommentPos === false) { // No more comments. return self::STOP_TRAVERSAL; } $oldPos = $this->pos; $this->pos = $pos = $node->getStartTokenPos(); if ($nextCommentPos > $oldPos && $nextCommentPos < $pos) { $comments = []; while (--$pos >= $oldPos) { $token = $this->tokens[$pos]; if ($token->id === \T_DOC_COMMENT) { $comments[] = new Comment\Doc( $token->text, $token->line, $token->pos, $pos, $token->getEndLine(), $token->getEndPos() - 1, $pos); continue; } if ($token->id === \T_COMMENT) { $comments[] = new Comment( $token->text, $token->line, $token->pos, $pos, $token->getEndLine(), $token->getEndPos() - 1, $pos); continue; } if ($token->id !== \T_WHITESPACE) { break; } } if (!empty($comments)) { $node->setAttribute('comments', array_reverse($comments)); } do { $nextCommentPos = next($this->commentPositions); } while ($nextCommentPos !== false && $nextCommentPos < $this->pos); } $endPos = $node->getEndTokenPos(); if ($nextCommentPos > $endPos) { // Skip children if there are no comments located inside this node. $this->pos = $endPos; return self::DONT_TRAVERSE_CHILDREN; } return null; } } ================================================ FILE: lib/PhpParser/NodeVisitor/FindingVisitor.php ================================================ Found nodes */ protected array $foundNodes; public function __construct(callable $filterCallback) { $this->filterCallback = $filterCallback; } /** * Get found nodes satisfying the filter callback. * * Nodes are returned in pre-order. * * @return list Found nodes */ public function getFoundNodes(): array { return $this->foundNodes; } public function beforeTraverse(array $nodes): ?array { $this->foundNodes = []; return null; } public function enterNode(Node $node) { $filterCallback = $this->filterCallback; if ($filterCallback($node)) { $this->foundNodes[] = $node; } return null; } } ================================================ FILE: lib/PhpParser/NodeVisitor/FirstFindingVisitor.php ================================================ filterCallback = $filterCallback; } /** * Get found node satisfying the filter callback. * * Returns null if no node satisfies the filter callback. * * @return null|Node Found node (or null if not found) */ public function getFoundNode(): ?Node { return $this->foundNode; } public function beforeTraverse(array $nodes): ?array { $this->foundNode = null; return null; } public function enterNode(Node $node) { $filterCallback = $this->filterCallback; if ($filterCallback($node)) { $this->foundNode = $node; return NodeVisitor::STOP_TRAVERSAL; } return null; } } ================================================ FILE: lib/PhpParser/NodeVisitor/NameResolver.php ================================================ nameContext = new NameContext($errorHandler ?? new ErrorHandler\Throwing()); $this->preserveOriginalNames = $options['preserveOriginalNames'] ?? false; $this->replaceNodes = $options['replaceNodes'] ?? true; } /** * Get name resolution context. */ public function getNameContext(): NameContext { return $this->nameContext; } public function beforeTraverse(array $nodes): ?array { $this->nameContext->startNamespace(); return null; } public function enterNode(Node $node) { if ($node instanceof Stmt\Namespace_) { $this->nameContext->startNamespace($node->name); } elseif ($node instanceof Stmt\Use_) { foreach ($node->uses as $use) { $this->addAlias($use, $node->type, null); } } elseif ($node instanceof Stmt\GroupUse) { foreach ($node->uses as $use) { $this->addAlias($use, $node->type, $node->prefix); } } elseif ($node instanceof Stmt\Class_) { if (null !== $node->extends) { $node->extends = $this->resolveClassName($node->extends); } foreach ($node->implements as &$interface) { $interface = $this->resolveClassName($interface); } $this->resolveAttrGroups($node); if (null !== $node->name) { $this->addNamespacedName($node); } else { $node->namespacedName = null; } } elseif ($node instanceof Stmt\Interface_) { foreach ($node->extends as &$interface) { $interface = $this->resolveClassName($interface); } $this->resolveAttrGroups($node); $this->addNamespacedName($node); } elseif ($node instanceof Stmt\Enum_) { foreach ($node->implements as &$interface) { $interface = $this->resolveClassName($interface); } $this->resolveAttrGroups($node); $this->addNamespacedName($node); } elseif ($node instanceof Stmt\Trait_) { $this->resolveAttrGroups($node); $this->addNamespacedName($node); } elseif ($node instanceof Stmt\Function_) { $this->resolveSignature($node); $this->resolveAttrGroups($node); $this->addNamespacedName($node); } elseif ($node instanceof Stmt\ClassMethod || $node instanceof Expr\Closure || $node instanceof Expr\ArrowFunction ) { $this->resolveSignature($node); $this->resolveAttrGroups($node); } elseif ($node instanceof Stmt\Property) { if (null !== $node->type) { $node->type = $this->resolveType($node->type); } $this->resolveAttrGroups($node); } elseif ($node instanceof Node\PropertyHook) { foreach ($node->params as $param) { $param->type = $this->resolveType($param->type); $this->resolveAttrGroups($param); } $this->resolveAttrGroups($node); } elseif ($node instanceof Stmt\Const_) { foreach ($node->consts as $const) { $this->addNamespacedName($const); } $this->resolveAttrGroups($node); } elseif ($node instanceof Stmt\ClassConst) { if (null !== $node->type) { $node->type = $this->resolveType($node->type); } $this->resolveAttrGroups($node); } elseif ($node instanceof Stmt\EnumCase) { $this->resolveAttrGroups($node); } elseif ($node instanceof Expr\StaticCall || $node instanceof Expr\StaticPropertyFetch || $node instanceof Expr\ClassConstFetch || $node instanceof Expr\New_ || $node instanceof Expr\Instanceof_ ) { if ($node->class instanceof Name) { $node->class = $this->resolveClassName($node->class); } } elseif ($node instanceof Stmt\Catch_) { foreach ($node->types as &$type) { $type = $this->resolveClassName($type); } } elseif ($node instanceof Expr\FuncCall) { if ($node->name instanceof Name) { $node->name = $this->resolveName($node->name, Stmt\Use_::TYPE_FUNCTION); } } elseif ($node instanceof Expr\ConstFetch) { $node->name = $this->resolveName($node->name, Stmt\Use_::TYPE_CONSTANT); } elseif ($node instanceof Stmt\TraitUse) { foreach ($node->traits as &$trait) { $trait = $this->resolveClassName($trait); } foreach ($node->adaptations as $adaptation) { if (null !== $adaptation->trait) { $adaptation->trait = $this->resolveClassName($adaptation->trait); } if ($adaptation instanceof Stmt\TraitUseAdaptation\Precedence) { foreach ($adaptation->insteadof as &$insteadof) { $insteadof = $this->resolveClassName($insteadof); } } } } return null; } /** @param Stmt\Use_::TYPE_* $type */ private function addAlias(Node\UseItem $use, int $type, ?Name $prefix = null): void { // Add prefix for group uses $name = $prefix ? Name::concat($prefix, $use->name) : $use->name; // Type is determined either by individual element or whole use declaration $type |= $use->type; $this->nameContext->addAlias( $name, (string) $use->getAlias(), $type, $use->getAttributes() ); } /** @param Stmt\Function_|Stmt\ClassMethod|Expr\Closure|Expr\ArrowFunction $node */ private function resolveSignature($node): void { foreach ($node->params as $param) { $param->type = $this->resolveType($param->type); $this->resolveAttrGroups($param); } $node->returnType = $this->resolveType($node->returnType); } /** * @template T of Node\Identifier|Name|Node\ComplexType|null * @param T $node * @return T */ private function resolveType(?Node $node): ?Node { if ($node instanceof Name) { return $this->resolveClassName($node); } if ($node instanceof Node\NullableType) { $node->type = $this->resolveType($node->type); return $node; } if ($node instanceof Node\UnionType || $node instanceof Node\IntersectionType) { foreach ($node->types as &$type) { $type = $this->resolveType($type); } return $node; } return $node; } /** * Resolve name, according to name resolver options. * * @param Name $name Function or constant name to resolve * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_* * * @return Name Resolved name, or original name with attribute */ protected function resolveName(Name $name, int $type): Name { if (!$this->replaceNodes) { $resolvedName = $this->nameContext->getResolvedName($name, $type); if (null !== $resolvedName) { $name->setAttribute('resolvedName', $resolvedName); } else { $name->setAttribute('namespacedName', FullyQualified::concat( $this->nameContext->getNamespace(), $name, $name->getAttributes())); } return $name; } if ($this->preserveOriginalNames) { // Save the original name $originalName = $name; $name = clone $originalName; $name->setAttribute('originalName', $originalName); } $resolvedName = $this->nameContext->getResolvedName($name, $type); if (null !== $resolvedName) { return $resolvedName; } // unqualified names inside a namespace cannot be resolved at compile-time // add the namespaced version of the name as an attribute $name->setAttribute('namespacedName', FullyQualified::concat( $this->nameContext->getNamespace(), $name, $name->getAttributes())); return $name; } protected function resolveClassName(Name $name): Name { return $this->resolveName($name, Stmt\Use_::TYPE_NORMAL); } protected function addNamespacedName(Node $node): void { $node->namespacedName = Name::concat( $this->nameContext->getNamespace(), (string) $node->name); } protected function resolveAttrGroups(Node $node): void { foreach ($node->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { $attr->name = $this->resolveClassName($attr->name); } } } } ================================================ FILE: lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php ================================================ $weakReferences=false on the child node, the parent node can be accessed through * $node->getAttribute('parent'), the previous * node can be accessed through $node->getAttribute('previous'), * and the next node can be accessed through $node->getAttribute('next'). * * With $weakReferences=true attribute names are prefixed by "weak_", e.g. "weak_parent". */ final class NodeConnectingVisitor extends NodeVisitorAbstract { /** * @var Node[] */ private array $stack = []; /** * @var ?Node */ private $previous; private bool $weakReferences; public function __construct(bool $weakReferences = false) { $this->weakReferences = $weakReferences; } public function beforeTraverse(array $nodes) { $this->stack = []; $this->previous = null; } public function enterNode(Node $node) { if (!empty($this->stack)) { $parent = $this->stack[count($this->stack) - 1]; if ($this->weakReferences) { $node->setAttribute('weak_parent', \WeakReference::create($parent)); } else { $node->setAttribute('parent', $parent); } } if ($this->previous !== null) { if ( $this->weakReferences ) { if ($this->previous->getAttribute('weak_parent') === $node->getAttribute('weak_parent')) { $node->setAttribute('weak_previous', \WeakReference::create($this->previous)); $this->previous->setAttribute('weak_next', \WeakReference::create($node)); } } elseif ($this->previous->getAttribute('parent') === $node->getAttribute('parent')) { $node->setAttribute('previous', $this->previous); $this->previous->setAttribute('next', $node); } } $this->stack[] = $node; } public function leaveNode(Node $node) { $this->previous = $node; array_pop($this->stack); } } ================================================ FILE: lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php ================================================ $weakReferences=false on the child node, the parent node can be accessed through * $node->getAttribute('parent'). * * With $weakReferences=true the attribute name is "weak_parent" instead. */ final class ParentConnectingVisitor extends NodeVisitorAbstract { /** * @var Node[] */ private array $stack = []; private bool $weakReferences; public function __construct(bool $weakReferences = false) { $this->weakReferences = $weakReferences; } public function beforeTraverse(array $nodes) { $this->stack = []; } public function enterNode(Node $node) { if (!empty($this->stack)) { $parent = $this->stack[count($this->stack) - 1]; if ($this->weakReferences) { $node->setAttribute('weak_parent', \WeakReference::create($parent)); } else { $node->setAttribute('parent', $parent); } } $this->stack[] = $node; } public function leaveNode(Node $node) { array_pop($this->stack); } } ================================================ FILE: lib/PhpParser/NodeVisitor.php ================================================ $node stays as-is * * array (of Nodes) * => The return value is merged into the parent array (at the position of the $node) * * NodeVisitor::REMOVE_NODE * => $node is removed from the parent array * * NodeVisitor::REPLACE_WITH_NULL * => $node is replaced with null * * NodeVisitor::DONT_TRAVERSE_CHILDREN * => Children of $node are not traversed. $node stays as-is * * NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN * => Further visitors for the current node are skipped, and its children are not * traversed. $node stays as-is. * * NodeVisitor::STOP_TRAVERSAL * => Traversal is aborted. $node stays as-is * * otherwise * => $node is set to the return value * * @param Node $node Node * * @return null|int|Node|Node[] Replacement node (or special return value) */ public function enterNode(Node $node); /** * Called when leaving a node. * * Return value semantics: * * null * => $node stays as-is * * NodeVisitor::REMOVE_NODE * => $node is removed from the parent array * * NodeVisitor::REPLACE_WITH_NULL * => $node is replaced with null * * NodeVisitor::STOP_TRAVERSAL * => Traversal is aborted. $node stays as-is * * array (of Nodes) * => The return value is merged into the parent array (at the position of the $node) * * otherwise * => $node is set to the return value * * @param Node $node Node * * @return null|int|Node|Node[] Replacement node (or special return value) */ public function leaveNode(Node $node); /** * Called once after traversal. * * Return value semantics: * * null: $nodes stays as-is * * otherwise: $nodes is set to the return value * * @param Node[] $nodes Array of nodes * * @return null|Node[] Array of nodes */ public function afterTraverse(array $nodes); } ================================================ FILE: lib/PhpParser/NodeVisitorAbstract.php ================================================ '", "T_IS_GREATER_OR_EQUAL", "T_SL", "T_SR", "'+'", "'-'", "'.'", "'*'", "'/'", "'%'", "'!'", "T_INSTANCEOF", "'~'", "T_INC", "T_DEC", "T_INT_CAST", "T_DOUBLE_CAST", "T_STRING_CAST", "T_ARRAY_CAST", "T_OBJECT_CAST", "T_BOOL_CAST", "T_UNSET_CAST", "'@'", "T_POW", "'['", "T_NEW", "T_CLONE", "T_EXIT", "T_IF", "T_ELSEIF", "T_ELSE", "T_ENDIF", "T_LNUMBER", "T_DNUMBER", "T_STRING", "T_STRING_VARNAME", "T_VARIABLE", "T_NUM_STRING", "T_INLINE_HTML", "T_ENCAPSED_AND_WHITESPACE", "T_CONSTANT_ENCAPSED_STRING", "T_ECHO", "T_DO", "T_WHILE", "T_ENDWHILE", "T_FOR", "T_ENDFOR", "T_FOREACH", "T_ENDFOREACH", "T_DECLARE", "T_ENDDECLARE", "T_AS", "T_SWITCH", "T_MATCH", "T_ENDSWITCH", "T_CASE", "T_DEFAULT", "T_BREAK", "T_CONTINUE", "T_GOTO", "T_FUNCTION", "T_FN", "T_CONST", "T_RETURN", "T_TRY", "T_CATCH", "T_FINALLY", "T_USE", "T_INSTEADOF", "T_GLOBAL", "T_STATIC", "T_ABSTRACT", "T_FINAL", "T_PRIVATE", "T_PROTECTED", "T_PUBLIC", "T_READONLY", "T_PUBLIC_SET", "T_PROTECTED_SET", "T_PRIVATE_SET", "T_VAR", "T_UNSET", "T_ISSET", "T_EMPTY", "T_HALT_COMPILER", "T_CLASS", "T_TRAIT", "T_INTERFACE", "T_ENUM", "T_EXTENDS", "T_IMPLEMENTS", "T_OBJECT_OPERATOR", "T_NULLSAFE_OBJECT_OPERATOR", "T_LIST", "T_ARRAY", "T_CALLABLE", "T_CLASS_C", "T_TRAIT_C", "T_METHOD_C", "T_FUNC_C", "T_PROPERTY_C", "T_LINE", "T_FILE", "T_START_HEREDOC", "T_END_HEREDOC", "T_DOLLAR_OPEN_CURLY_BRACES", "T_CURLY_OPEN", "T_PAAMAYIM_NEKUDOTAYIM", "T_NAMESPACE", "T_NS_C", "T_DIR", "T_NS_SEPARATOR", "T_ELLIPSIS", "T_NAME_FULLY_QUALIFIED", "T_NAME_QUALIFIED", "T_NAME_RELATIVE", "T_ATTRIBUTE", "';'", "']'", "'('", "')'", "'{'", "'}'", "'`'", "'\"'", "'$'" ); protected array $tokenToSymbol = array( 0, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 57, 171, 173, 172, 56, 173, 173, 166, 167, 54, 51, 9, 52, 53, 55, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 32, 164, 45, 17, 47, 31, 69, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 71, 173, 165, 37, 173, 170, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 168, 36, 169, 59, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 33, 34, 35, 38, 39, 40, 41, 42, 43, 44, 46, 48, 49, 50, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163 ); protected array $action = array( 133, 134, 135, 575, 136, 137, 1049, 766, 767, 768, 138, 41, 850, -341, 495, 1390,-32766,-32766,-32766, 1008, 841, 1145, 1146, 1147, 1141, 1140, 1139, 1148, 1142, 1143, 1144,-32766,-32766,-32766, -195, 760, 759,-32766, -194,-32766, -32766,-32766,-32766,-32766,-32766,-32766,-32767,-32767,-32767,-32767, -32767, 0,-32766, 3, 4, 769, 1145, 1146, 1147, 1141, 1140, 1139, 1148, 1142, 1143, 1144, 388, 389, 448, 272, 53, 391, 773, 774, 775, 776, 433, 5, 434, 571, 337, 39, 254, 29, 298, 830, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 806, 576, 807, 808, 809, 810, 798, 799, 353, 354, 801, 802, 787, 788, 789, 791, 792, 793, 364, 833, 834, 835, 836, 837, 577, -382, 306, -382, 794, 795, 578, 579, 244, 818, 816, 817, 829, 813, 814, 1313, 38, 580, 581, 812, 582, 583, 584, 585, 1325, 586, 587, 481, 482, -628, 496, 1009, 815, 588, 589, 140, 139, -628, 133, 134, 135, 575, 136, 137, 1085, 766, 767, 768, 138, 41, -32766, -341, 1046, 1041, 1040, 1039, 1045, 1042, 1043, 1044, -32766,-32766,-32766,-32767,-32767,-32767,-32767, 106, 107, 108, 109, 110, -195, 760, 759, 1058, -194,-32766,-32766,-32766, 149,-32766, 852,-32766,-32766,-32766,-32766,-32766,-32766,-32766, 936, 303, 257, 769,-32766,-32766,-32766, 850,-32766, 297, -32766,-32766,-32766,-32766,-32766, 1371, 1355, 272, 53, 391, 773, 774, 775, 776, -625,-32766, 434,-32766,-32766,-32766, -32766, 730, -625, 830, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 806, 576, 807, 808, 809, 810, 798, 799, 353, 354, 801, 802, 787, 788, 789, 791, 792, 793, 364, 833, 834, 835, 836, 837, 577, -579, -275, 317, 794, 795, 578, 579, -577, 818, 816, 817, 829, 813, 814, 957, 926, 580, 581, 812, 582, 583, 584, 585, 144, 586, 587, 841, 336,-32766,-32766,-32766, 815, 588, 589, -628, 139, -628, 133, 134, 135, 575, 136, 137, 1082, 766, 767, 768, 138, 41,-32766, 1375, -32766,-32766,-32766,-32766,-32766,-32766,-32766, 1374, 629, 388, 389,-32766,-32766,-32766,-32766,-32766, -579, -579, 1081, 433, 321, 760, 759, -577, -577,-32766, 1293,-32766,-32766, 111, 112, 113, -579, 282, 843, 851, 623, 1400, 936, -577, 1401, 769, 333, 938, -585, 114, -579, 725, 294, 298, 1119, -584, 349, -577, 752, 272, 53, 391, 773, 774, 775, 776, 145, 86, 434, 306, 336, 336, -625, 731, -625, 830, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 806, 576, 807, 808, 809, 810, 798, 799, 353, 354, 801, 802, 787, 788, 789, 791, 792, 793, 364, 833, 834, 835, 836, 837, 577, -576, 850, -578, 794, 795, 578, 579, 845, 818, 816, 817, 829, 813, 814, 727, 926, 580, 581, 812, 582, 583, 584, 585, 740, 586, 587, 243, 1055,-32766,-32766, -85, 815, 588, 589, 878, 152, 879, 133, 134, 135, 575, 136, 137, 1087, 766, 767, 768, 138, 41, 350, 961, 960, 1058, 1058, 1058,-32766,-32766,-32766, 841,-32766, 131, 977, 978, 400, 1055, 10, 979, -576, -576, -578, -578, 378, 760, 759, 936, 973, 290, 297, 297,-32766, 846, 936, 154, -576, 79, -578, 382, 849, 936, 1058, 336, 878, 769, 879, 938, -583, -85, -576, 725, -578, 959, 108, 109, 110, 1058, 732, 272, 53, 391, 773, 774, 775, 776, 290, 155, 434, 470, 471, 472, 735, 760, 759, 830, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 806, 576, 807, 808, 809, 810, 798, 799, 353, 354, 801, 802, 787, 788, 789, 791, 792, 793, 364, 833, 834, 835, 836, 837, 577, 926, 434, 847, 794, 795, 578, 579, 926, 818, 816, 817, 829, 813, 814, 926, 398, 580, 581, 812, 582, 583, 584, 585, 452, 586, 587, 157, 87, 88, 89, 453, 815, 588, 589, 454, 152, 790, 761, 762, 763, 764, 765, 158, 766, 767, 768, 803, 804, 40, 27, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 1134, 282, 1055, 455,-32766, 994, 1288, 1287, 1289, 725, 390, 389, 938, 114, 856, 1120, 725, 769, 159, 938, 433, 672, 23, 725, 1118, 691, 692, 1058,-32766, 153, 416, 770, 771, 772, 773, 774, 775, 776, -78, -619, 839, -619, -581, 386, 387, 392, 393, 830, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 806, 828, 807, 808, 809, 810, 798, 799, 800, 827, 801, 802, 787, 788, 789, 791, 792, 793, 832, 833, 834, 835, 836, 837, 838, 161, 663, 664, 794, 795, 796, 797, 36, 818, 816, 817, 829, 813, 814, -58, -57, 805, 811, 812, 819, 820, 822, 821, -87, 823, 824, -581, -581, 128, 129, 141, 815, 826, 825, 54, 55, 56, 57, 527, 58, 59, 142, -110, 148, 162, 60, 61, -110, 62, -110, 936, 163, 164, 165, 313, 166, -581, -110, -110, -110, -110, -110, -110, -110, -110, -110, -110, -110, 1293, -84, 953, -78, -73, -72, -71, -70, -69, -68, -67, -66, -65, 742, -46, 63, 64, -18, -575, 1286, 146, 65, 51, 66, 251, 252, 67, 68, 69, 70, 71, 72, 73, 74, 281, 31, 273, 47, 450, 528, 291, -357, 741, 1319, 1320, 529, 744, 850, 935, 151, 295, 1317, 45, 22, 530, 1284, 531, -309, 532, -305, 533, 286, 936, 534, 535, 287, 926, 292, 48, 49, 456, 385, 384, 293, 50, 536, 342, 296, 282, 1057, 376, 348, 850, 299, 300, -575, -575, 1279, 114, 307, 308, 701, 538, 539, 540, 150, 841,-32766, 1288, 1287, 1289, -575, 850, 294, 542, 543, 1402, 1305, 1306, 1307, 1308, 1310, 1302, 1303, 305, -575, 716, -110, -110, 130, 1309, 1304, -110, 593, 1288, 1287, 1289, 306, 13, 673, 75, -110, 1152, 678, 331, 332, 336, -154, -154, -154, -32766, 718, 694, -4, 936, 938, 926, 314, 478, 725, 506, 1324, -154, 705, -154, 679, -154, 695, -154, 974, 1326, -541, 306, 312, 311, 79, 849, 661, 383, 43, 320, 336, 37, 1252, 0, 0, 52, 0, 0, 977, 978, 0, 760, 759, 537,-32766, 0, 0, 0, 706, 0, 0, 912, 973, -110, -110, -110, 35, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, -531, 11, 707, 708, 31, 274, 30, 380, 955, 599, -613, 306, 627, 0, 938, 0, 850, 926, 725, -154, 1317, 1288, 1287, 1289, 44, -612, 749, 290, 750, 1194, 1196, 869, 309, 310, 917, 1018, 995, 1002, 992, 383, -575, 446, 1003, 915, 990, 1123, 304, 1126, 381, 1127, 977, 978, 1124, 1125, 1131, 537, 1279, 1314, 861, 330, 760, 759, 132, 541, 973, -110, -110, -110, 1341, 1359, 1393, 1293, 666, 542, 543, -611, 1305, 1306, 1307, 1308, 1310, 1302, 1303, -585, -584, -583, -582, 21, -525, 1309, 1304, 1, 32, 760, 759, 33, 938,-32766, -278, 77, 725, -4, -16, 1286, 332, 336, 42, -575, -575, 46,-32766,-32766,-32766, 76,-32766, 80,-32766, 81,-32766, 82, 83,-32766, 84, -575, 85, 147,-32766,-32766,-32766, 156,-32766, 160,-32766,-32766, 249, 379, 1286, -575,-32766, 430, 31, 273, 338,-32766,-32766,-32766, 365,-32766, 366, -32766,-32766,-32766, 850, 850,-32766, 367, 1317, 368, 369, -32766,-32766,-32766, 370, 371, 372,-32766,-32766, 373, 374, 375, 377,-32766, 430, 447, 570, 31, 274, -276, -275, 15, 16, 78, 17,-32766, 18, 20, 414, 850, -110, -110, 497, 1317, 1279, -110, 498, 505, 508, 509, 510, 511, 515, 516, -110, 517, 525, 604, 711, 1088, 1084, 1234, 543,-32766, 1305, 1306, 1307, 1308, 1310, 1302, 1303, 1315, 1086, 1083, -50, 1064, 1274, 1309, 1304, 1279, 1060, -280, -102, 14, 19, 306, 24, 77, 79, 415, 303, 413, 332, 336, 336, 618, 624, 543, 652, 1305, 1306, 1307, 1308, 1310, 1302, 1303, 717, 143, 1238, 1292, 1235, 1372, 1309, 1304, 726, 729, 733,-32766, 734, 736, 737, 738, 77, 1286, 419, 739, 743, 332, 336, 728,-32766, -32766,-32766, 746,-32766, 913,-32766, 1397,-32766, 1399, 872, -32766, 871, 967, 1010, 1398,-32766,-32766,-32766, 966,-32766, 964,-32766,-32766, 965, 968, 1286, 1267,-32766, 430, 946, 956, 944,-32766,-32766,-32766, 1000,-32766, 1001,-32766,-32766, -32766, 650, 1396,-32766, 1353, 1342, 1360, 1369,-32766,-32766, -32766, 1318,-32766, 336,-32766,-32766, 936, 0, 1286, 0, -32766, 430, 0, 0, 0,-32766,-32766,-32766, 0,-32766, 0,-32766,-32766,-32766, 0, 0,-32766, 0, 0, 936, 0,-32766,-32766,-32766, 0,-32766, 0,-32766,-32766, 0, 0, 1286, 0,-32766, 430, 0, 0, 0,-32766,-32766, -32766, 0,-32766, 0,-32766,-32766,-32766, 0, 0,-32766, 0, 0, 0, 501,-32766,-32766,-32766, 0,-32766, 0, -32766,-32766, 0, 0, 1286, 606,-32766, 430, 0, 0, 0,-32766,-32766,-32766, 0,-32766, 0,-32766,-32766,-32766, 926, 0,-32766, 2, 0, 0, 0,-32766,-32766,-32766, 0, 0, 0,-32766,-32766, 0, -253, -253, -253,-32766, 430, 0, 383, 926, 0, 0, 0, 0, 0, 0, 0,-32766, 0, 977, 978, 0, 0, 0, 537, -252, -252, -252, 0, 0, 0, 383, 912, 973, -110, -110, -110, 0, 0, 0, 0, 0, 977, 978, 0, 0, 0, 537, 0, 0, 0, 0, 0, 0, 0, 912, 973, -110, -110, -110,-32766, 0, 0, 0, 0, 938, 1286, 0, 0, 725, -253, 0, 0,-32766,-32766,-32766, 0,-32766, 0,-32766, 0,-32766, 0, 0,-32766, 0, 0, 0, 938,-32766,-32766,-32766, 725, -252, 0,-32766, -32766, 0, 0, 0, 0,-32766, 430, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-32766 ); protected array $actionCheck = array( 3, 4, 5, 6, 7, 8, 1, 10, 11, 12, 13, 14, 83, 9, 32, 86, 10, 11, 12, 32, 81, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 10, 11, 12, 9, 38, 39, 31, 9, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 0, 31, 9, 9, 58, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 107, 108, 109, 72, 73, 74, 75, 76, 77, 78, 117, 9, 81, 86, 71, 152, 153, 9, 31, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 107, 163, 109, 127, 128, 129, 130, 15, 132, 133, 134, 135, 136, 137, 1, 9, 140, 141, 142, 143, 144, 145, 146, 151, 148, 149, 138, 139, 1, 168, 164, 155, 156, 157, 9, 159, 9, 3, 4, 5, 6, 7, 8, 167, 10, 11, 12, 13, 14, 117, 167, 119, 120, 121, 122, 123, 124, 125, 126, 10, 11, 12, 45, 46, 47, 48, 49, 50, 51, 52, 53, 167, 38, 39, 142, 167, 10, 11, 12, 9, 31, 1, 33, 34, 35, 36, 37, 38, 39, 1, 167, 9, 58, 10, 11, 12, 83, 31, 166, 33, 34, 35, 36, 37, 1, 1, 72, 73, 74, 75, 76, 77, 78, 1, 31, 81, 33, 34, 35, 36, 32, 9, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 71, 167, 9, 127, 128, 129, 130, 71, 132, 133, 134, 135, 136, 137, 1, 85, 140, 141, 142, 143, 144, 145, 146, 168, 148, 149, 81, 172, 10, 11, 12, 155, 156, 157, 165, 159, 167, 3, 4, 5, 6, 7, 8, 167, 10, 11, 12, 13, 14, 31, 1, 33, 34, 35, 10, 10, 11, 12, 9, 52, 107, 108, 10, 11, 12, 10, 11, 138, 139, 1, 117, 9, 38, 39, 138, 139, 31, 1, 33, 34, 54, 55, 56, 154, 58, 81, 164, 1, 81, 1, 154, 84, 58, 9, 164, 166, 70, 168, 168, 31, 31, 164, 166, 9, 168, 168, 72, 73, 74, 75, 76, 77, 78, 168, 168, 81, 163, 172, 172, 165, 32, 167, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 71, 83, 71, 127, 128, 129, 130, 161, 132, 133, 134, 135, 136, 137, 168, 85, 140, 141, 142, 143, 144, 145, 146, 168, 148, 149, 98, 117, 117, 117, 32, 155, 156, 157, 107, 159, 109, 3, 4, 5, 6, 7, 8, 167, 10, 11, 12, 13, 14, 9, 73, 74, 142, 142, 142, 10, 11, 12, 81, 141, 15, 118, 119, 107, 117, 109, 123, 138, 139, 138, 139, 9, 38, 39, 1, 132, 166, 166, 166, 117, 81, 1, 15, 154, 166, 154, 9, 160, 1, 142, 172, 107, 58, 109, 164, 166, 98, 168, 168, 168, 123, 51, 52, 53, 142, 32, 72, 73, 74, 75, 76, 77, 78, 166, 15, 81, 133, 134, 135, 32, 38, 39, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 85, 81, 161, 127, 128, 129, 130, 85, 132, 133, 134, 135, 136, 137, 85, 9, 140, 141, 142, 143, 144, 145, 146, 9, 148, 149, 15, 10, 11, 12, 9, 155, 156, 157, 9, 159, 3, 4, 5, 6, 7, 8, 15, 10, 11, 12, 13, 14, 31, 102, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 127, 58, 117, 9, 117, 164, 160, 161, 162, 168, 107, 108, 164, 70, 9, 169, 168, 58, 15, 164, 117, 76, 77, 168, 1, 76, 77, 142, 141, 102, 103, 72, 73, 74, 75, 76, 77, 78, 17, 165, 81, 167, 71, 107, 108, 107, 108, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 15, 112, 113, 127, 128, 129, 130, 15, 132, 133, 134, 135, 136, 137, 17, 17, 140, 141, 142, 143, 144, 145, 146, 32, 148, 149, 138, 139, 17, 17, 17, 155, 156, 157, 2, 3, 4, 5, 6, 7, 8, 17, 102, 17, 17, 13, 14, 107, 16, 109, 1, 17, 17, 17, 114, 17, 168, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 1, 32, 39, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 51, 52, 32, 71, 81, 32, 57, 71, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 32, 71, 72, 73, 74, 75, 32, 169, 32, 79, 80, 81, 32, 83, 32, 32, 38, 87, 88, 89, 90, 117, 92, 36, 94, 36, 96, 36, 1, 99, 100, 36, 85, 36, 104, 105, 106, 107, 108, 36, 110, 111, 36, 38, 58, 141, 116, 117, 83, 38, 38, 138, 139, 123, 70, 138, 139, 78, 128, 129, 130, 71, 81, 86, 160, 161, 162, 154, 83, 31, 140, 141, 84, 143, 144, 145, 146, 147, 148, 149, 150, 168, 81, 118, 119, 168, 156, 157, 123, 90, 160, 161, 162, 163, 98, 91, 166, 132, 83, 97, 170, 171, 172, 76, 77, 78, 141, 93, 95, 0, 1, 164, 85, 115, 98, 168, 98, 151, 91, 81, 93, 101, 95, 101, 97, 132, 151, 154, 163, 137, 136, 166, 160, 114, 107, 164, 136, 172, 168, 170, -1, -1, 71, -1, -1, 118, 119, -1, 38, 39, 123, 141, -1, -1, -1, 117, -1, -1, 131, 132, 133, 134, 135, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 154, 154, 141, 142, 71, 72, 154, 154, 159, 158, 166, 163, 158, -1, 164, -1, 83, 85, 168, 169, 87, 160, 161, 162, 164, 166, 164, 166, 164, 60, 61, 164, 138, 139, 164, 164, 164, 164, 164, 107, 71, 109, 164, 164, 164, 164, 114, 164, 154, 164, 118, 119, 164, 164, 164, 123, 123, 165, 165, 168, 38, 39, 168, 131, 132, 133, 134, 135, 165, 165, 165, 1, 165, 140, 141, 166, 143, 144, 145, 146, 147, 148, 149, 166, 166, 166, 166, 155, 166, 156, 157, 166, 166, 38, 39, 166, 164, 75, 167, 166, 168, 169, 32, 81, 171, 172, 166, 138, 139, 166, 88, 89, 90, 166, 92, 166, 94, 166, 96, 166, 166, 99, 166, 154, 166, 166, 104, 105, 106, 166, 75, 166, 110, 111, 166, 168, 81, 168, 116, 117, 71, 72, 166, 88, 89, 90, 166, 92, 166, 94, 128, 96, 83, 83, 99, 166, 87, 166, 166, 104, 105, 106, 166, 166, 166, 110, 111, 166, 166, 166, 166, 116, 117, 166, 166, 71, 72, 167, 167, 167, 167, 159, 167, 128, 167, 167, 167, 83, 118, 119, 167, 87, 123, 123, 167, 167, 167, 167, 167, 167, 167, 167, 132, 167, 167, 167, 167, 167, 167, 167, 141, 141, 143, 144, 145, 146, 147, 148, 149, 167, 167, 167, 32, 167, 167, 156, 157, 123, 167, 167, 167, 167, 167, 163, 167, 166, 166, 169, 167, 167, 171, 172, 172, 167, 167, 141, 167, 143, 144, 145, 146, 147, 148, 149, 167, 32, 167, 167, 167, 167, 156, 157, 168, 168, 168, 75, 168, 168, 168, 168, 166, 81, 169, 168, 168, 171, 172, 168, 88, 89, 90, 169, 92, 169, 94, 169, 96, 169, 169, 99, 169, 169, 169, 169, 104, 105, 106, 169, 75, 169, 110, 111, 169, 169, 81, 169, 116, 117, 169, 169, 169, 88, 89, 90, 169, 92, 169, 94, 128, 96, 169, 169, 99, 169, 169, 169, 169, 104, 105, 106, 171, 75, 172, 110, 111, 1, -1, 81, -1, 116, 117, -1, -1, -1, 88, 89, 90, -1, 92, -1, 94, 128, 96, -1, -1, 99, -1, -1, 1, -1, 104, 105, 106, -1, 75, -1, 110, 111, -1, -1, 81, -1, 116, 117, -1, -1, -1, 88, 89, 90, -1, 92, -1, 94, 128, 96, -1, -1, 99, -1, -1, -1, 103, 104, 105, 106, -1, 75, -1, 110, 111, -1, -1, 81, 82, 116, 117, -1, -1, -1, 88, 89, 90, -1, 92, -1, 94, 128, 96, 85, -1, 99, 166, -1, -1, -1, 104, 105, 106, -1, -1, -1, 110, 111, -1, 101, 102, 103, 116, 117, -1, 107, 85, -1, -1, -1, -1, -1, -1, -1, 128, -1, 118, 119, -1, -1, -1, 123, 101, 102, 103, -1, -1, -1, 107, 131, 132, 133, 134, 135, -1, -1, -1, -1, -1, 118, 119, -1, -1, -1, 123, -1, -1, -1, -1, -1, -1, -1, 131, 132, 133, 134, 135, 75, -1, -1, -1, -1, 164, 81, -1, -1, 168, 169, -1, -1, 88, 89, 90, -1, 92, -1, 94, -1, 96, -1, -1, 99, -1, -1, -1, 164, 104, 105, 106, 168, 169, -1, 110, 111, -1, -1, -1, -1, 116, 117, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 128 ); protected array $actionBase = array( 0, 155, -3, 313, 471, 471, 881, 963, 1365, 1388, 892, 134, 515, -61, 367, 524, 524, 801, 524, 209, 510, 283, 517, 517, 517, 920, 855, 628, 628, 855, 628, 1053, 1053, 1053, 1053, 1086, 1086, 1320, 1320, 1353, 1254, 1221, 1449, 1449, 1449, 1449, 1449, 1287, 1449, 1449, 1449, 1449, 1449, 1287, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 201, -13, 44, 365, 744, 1102, 1120, 1107, 1121, 1096, 1095, 1103, 1108, 1122, 1183, 1185, 837, 1186, 1187, 1182, 1188, 1110, 938, 1098, 1118, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 323, 482, 334, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 331, 964, 964, 21, 21, 21, 324, 1135, 1100, 1135, 1135, 1135, 1135, 1135, 1135, 1135, 1135, 297, 204, 1000, 187, 170, 170, 6, 6, 6, 6, 6, 692, 53, 1101, 819, 819, 138, 138, 138, 138, 542, 14, 347, 355, -41, 348, 232, 384, 384, 487, 487, 554, 554, 349, 349, 554, 554, 554, 399, 399, 399, 399, 208, 215, 366, 364, -7, 864, 224, 224, 224, 224, 864, 864, 864, 864, 829, 1190, 864, 1011, 1027, 864, 864, 368, 767, 767, 925, 305, 305, 305, 767, 421, -71, -71, 421, 380, -71, 225, 286, 556, 847, 572, 543, 556, 640, 771, 233, 148, 826, 605, 826, 1094, 831, 831, 802, 792, 921, 1140, 1123, 874, 1176, 876, 1178, 420, 9, 791, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1191, 519, 1094, 436, 1191, 1191, 1191, 519, 519, 519, 519, 519, 519, 519, 519, 805, 519, 519, 641, 436, 614, 618, 436, 860, 519, 877, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, -18, 201, 201, -13, 292, 292, 201, 216, 5, 292, 292, 292, 292, 201, 201, 201, 201, 605, 840, 882, 607, 435, 885, 29, 840, 840, 840, 4, 113, 25, 841, 843, 393, 835, 835, 835, 869, 956, 956, 835, 839, 835, 869, 835, 835, 956, 956, 879, 956, 146, 609, 373, 514, 616, 956, 272, 835, 835, 835, 835, 854, 956, 45, 68, 620, 835, 203, 191, 835, 835, 854, 848, 828, 846, 956, 956, 956, 854, 499, 846, 846, 846, 893, 895, 873, 822, 363, 341, 674, 127, 783, 822, 822, 835, 601, 873, 822, 873, 822, 880, 822, 822, 822, 873, 822, 839, 477, 822, 779, 786, 663, 74, 822, 51, 978, 980, 743, 982, 971, 984, 1038, 985, 987, 1125, 953, 999, 974, 989, 1039, 960, 957, 836, 763, 764, 878, 827, 951, 838, 838, 838, 948, 949, 838, 838, 838, 838, 838, 838, 838, 838, 763, 923, 884, 853, 1013, 765, 776, 1069, 820, 1145, 823, 1011, 978, 987, 789, 974, 989, 960, 957, 800, 799, 797, 798, 796, 795, 793, 794, 808, 1071, 1072, 990, 825, 778, 1049, 1020, 1143, 922, 1022, 1023, 1050, 1073, 898, 1083, 1147, 844, 1149, 1150, 924, 1028, 1126, 838, 940, 875, 934, 1027, 950, 763, 935, 1084, 1085, 1043, 824, 1054, 1058, 998, 870, 842, 936, 1152, 1029, 1032, 1033, 1127, 1129, 891, 1044, 962, 1059, 872, 1099, 1060, 1061, 1062, 1063, 1130, 1153, 1131, 890, 1132, 901, 858, 1041, 856, 1154, 504, 851, 857, 866, 1035, 536, 1007, 1136, 1134, 1155, 1064, 1065, 1067, 1159, 1161, 994, 902, 1046, 867, 1048, 1042, 903, 904, 606, 865, 1087, 845, 849, 859, 622, 672, 1164, 1165, 1167, 996, 830, 833, 905, 909, 1088, 832, 1092, 1170, 737, 910, 1171, 1070, 787, 788, 690, 750, 749, 790, 868, 1137, 883, 852, 850, 1034, 788, 834, 911, 1172, 912, 914, 916, 1068, 919, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 784, 784, 784, 784, 784, 784, 784, 784, 784, 628, 628, 628, 628, 784, 784, 784, 784, 784, 784, 784, 628, 784, 784, 784, 628, 628, 0, 0, 628, 0, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 784, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 612, 758, 758, 612, 612, 612, 612, 758, 758, 758, 758, 758, 758, 758, 758, 758, 758, 612, 612, 0, 612, 612, 612, 612, 612, 612, 612, 612, 879, 758, 758, 758, 758, 305, 305, 305, 305, -96, -96, 758, 758, 380, 758, 380, 758, 758, 305, 305, 758, 758, 758, 758, 758, 758, 758, 758, 758, 758, 758, 0, 0, 0, 436, -71, 758, 839, 839, 839, 839, 758, 758, 758, 758, -71, -71, 758, 414, 414, 758, 758, 0, 0, 0, 0, 0, 0, 0, 0, 436, 0, 0, 436, 0, 0, 839, 839, 758, 380, 879, 328, 758, 0, 0, 0, 0, 436, 839, 436, 519, -71, -71, 519, 519, 292, 201, 328, 596, 596, 596, 596, 0, 0, 605, 879, 879, 879, 879, 879, 879, 879, 879, 879, 879, 879, 839, 0, 879, 0, 839, 839, 839, 0, 0, 0, 0, 0, 0, 0, 0, 956, 0, 0, 0, 0, 0, 0, 0, 839, 0, 956, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 839, 0, 0, 0, 0, 0, 0, 0, 0, 0, 838, 870, 0, 0, 870, 0, 838, 838, 838, 0, 0, 0, 865, 832 ); protected array $actionDefault = array( 3,32767,32767,32767, 102, 102,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767, 100, 32767, 631, 631, 631, 631,32767,32767, 257, 102,32767, 32767, 500, 415, 415, 415,32767,32767,32767, 573, 573, 573, 573, 573, 17,32767,32767,32767,32767,32767,32767, 32767, 500,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767, 36, 7, 8, 10, 11, 49, 338, 100,32767,32767,32767,32767,32767,32767,32767,32767, 102, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767, 624,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767, 403, 494, 504, 482, 483, 485, 486, 414, 574, 630, 344, 627, 342, 413, 146, 354, 343, 245, 261, 505, 262, 506, 509, 510, 218, 400, 150, 151, 446, 501, 448, 499, 503, 447, 420, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 418, 419, 502,32767,32767, 479, 478, 477, 444,32767, 32767,32767,32767,32767,32767,32767,32767, 102,32767, 445, 449, 417, 452, 450, 451, 468, 469, 466, 467, 470, 32767, 323,32767,32767,32767, 471, 472, 473, 474, 381, 379,32767,32767, 111, 323, 111,32767,32767, 459, 460, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767, 517, 567, 476,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767, 102,32767,32767, 32767, 100, 569, 441, 443, 537, 454, 455, 453, 421, 32767, 542,32767, 102,32767, 544,32767,32767,32767,32767, 32767,32767,32767, 568,32767, 575, 575,32767, 530, 100, 196,32767, 543, 196, 196,32767,32767,32767,32767,32767, 32767,32767,32767, 638, 530, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,32767, 196, 110,32767, 32767,32767, 100, 196, 196, 196, 196, 196, 196, 196, 196, 545, 196, 196, 191,32767, 271, 273, 102, 592, 196, 547,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 530, 464, 139,32767, 532, 139, 575, 456, 457, 458, 575, 575, 575, 319, 296,32767,32767,32767,32767,32767, 545, 545, 100, 100, 100, 100,32767,32767,32767,32767, 111, 516, 99, 99, 99, 99, 99, 103, 101,32767, 32767,32767,32767, 226,32767, 101, 101, 99,32767, 101, 101,32767,32767, 226, 228, 215, 230,32767, 596, 597, 226, 101, 230, 230, 230, 250, 250, 519, 325, 101, 99, 101, 101, 198, 325, 325,32767, 101, 519, 325, 519, 325, 200, 325, 325, 325, 519, 325,32767, 101, 325, 217, 403, 99, 99, 325,32767,32767,32767, 532, 32767,32767,32767,32767,32767,32767,32767, 225,32767,32767, 32767,32767,32767,32767,32767,32767, 562,32767, 580, 594, 462, 463, 465, 579, 577, 487, 488, 489, 490, 491, 492, 493, 496, 626,32767, 536,32767,32767,32767, 353, 32767, 636,32767,32767,32767, 9, 74, 525, 42, 43, 51, 57, 551, 552, 553, 554, 548, 549, 555, 550, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767, 637,32767, 575,32767, 32767,32767,32767, 461, 557, 602,32767,32767, 576, 629, 32767,32767,32767,32767,32767,32767,32767,32767, 139,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767, 562, 32767, 137,32767,32767,32767,32767,32767,32767,32767,32767, 558,32767,32767,32767, 575,32767,32767,32767,32767, 321, 318,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767, 575,32767,32767, 32767,32767,32767, 298,32767, 315,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767, 399, 532, 301, 303, 304,32767, 32767,32767,32767, 375,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767, 153, 153, 3, 3, 356, 153, 153, 153, 356, 356, 153, 356, 356, 356, 153, 153, 153, 153, 153, 153, 283, 186, 265, 268, 250, 250, 153, 367, 153 ); protected array $goto = array( 202, 169, 202, 202, 202, 1056, 842, 712, 359, 670, 671, 598, 688, 689, 690, 748, 653, 655, 591, 929, 675, 930, 1090, 721, 699, 702, 1028, 710, 719, 1024, 171, 171, 171, 171, 226, 203, 199, 199, 181, 183, 221, 199, 199, 199, 199, 199, 1180, 200, 200, 200, 200, 200, 1180, 193, 194, 195, 196, 197, 198, 223, 221, 224, 550, 551, 431, 552, 555, 556, 557, 558, 559, 560, 561, 562, 172, 173, 174, 201, 175, 176, 177, 170, 178, 179, 180, 182, 220, 222, 225, 245, 248, 259, 260, 262, 263, 264, 265, 266, 267, 268, 269, 275, 276, 277, 278, 288, 289, 326, 327, 328, 437, 438, 439, 613, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 184, 242, 185, 194, 195, 196, 197, 198, 223, 204, 205, 206, 207, 246, 186, 187, 208, 188, 209, 205, 189, 247, 204, 168, 210, 211, 190, 212, 213, 214, 191, 215, 216, 192, 217, 218, 219, 285, 283, 285, 285, 870, 1089, 1091, 1094, 615, 255, 255, 255, 255, 255, 441, 677, 614, 1130, 884, 867, 436, 329, 323, 324, 345, 608, 440, 346, 442, 654, 724, 492, 521, 715, 896, 1128, 993, 883, 494, 253, 253, 253, 253, 250, 256, 489, 1361, 1362, 1386, 1386, 925, 920, 921, 934, 876, 922, 873, 923, 924, 874, 877, 363, 928, 881, 480, 480, 868, 880, 1386, 848, 474, 363, 363, 480, 1117, 1112, 1113, 1114, 1229, 351, 362, 362, 362, 362, 1389, 1389, 429, 363, 363, 1017, 902, 363, 989, 1403, 747, 360, 361, 566, 1026, 1021, 1056, 1285, 1285, 1285, 569, 352, 351, 363, 363, 605, 1056, 1285, 848, 1056, 848, 1056, 1056, 1137, 1138, 1056, 1056, 1056, 1056, 1056, 1056, 1056, 1056, 1056, 1056, 1056, 357, 1261, 962, 637, 674, 1285, 1262, 1265, 963, 1266, 1285, 1285, 1285, 1285, 1376, 435, 1285, 628, 402, 1285, 1285, 1368, 1368, 1368, 1368, 1347, 574, 567, 1062, 1061, 1059, 1059, 958, 958, 697, 970, 1014, 942, 1051, 1067, 1068, 943, 565, 565, 565, 603, 513, 522, 514, 863, 676, 863, 565, 709, 520, 1176, 318, 567, 574, 600, 601, 319, 611, 617, 844, 633, 634, 1080, 8, 709, 9, 449, 709, 28, 1065, 1066, 467, 335, 316, 569, 698, 987, 987, 987, 987, 1363, 1364, 467, 639, 639, 981, 988, 609, 631, 1316, 1316, 1316, 1316, 1316, 1316, 1316, 1316, 1316, 1316, 1335, 1335, 863, 469, 682, 469, 1335, 1335, 1335, 1335, 1335, 1335, 1335, 1335, 1335, 1335, 347, 258, 258, 626, 640, 643, 644, 645, 646, 667, 668, 669, 723, 632, 460, 860, 460, 460, 460, 1358, 1358, 1358, 553, 553, 1278, 985, 420, 720, 553, 1358, 553, 553, 553, 553, 553, 553, 553, 553, 451, 889, 568, 595, 568, 647, 649, 651, 568, 976, 595, 411, 405, 473, 886, 1276, 1370, 1370, 1370, 1370, 909, 866, 909, 909, 1036, 483, 612, 484, 485, 751, 563, 563, 563, 563, 894, 619, 1101, 1394, 1395, 412, 1332, 1332, 898, 490, 1151, 1354, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 279, 1105, 334, 334, 334, 998, 892, 0, 1280, 1047, 0, 0, 863, 0, 0, 460, 460, 460, 460, 460, 460, 460, 460, 460, 460, 460, 0, 0, 460, 1103, 554, 554, 0, 1356, 1356, 1103, 554, 554, 554, 554, 554, 554, 554, 554, 554, 554, 621, 622, 417, 418, 947, 1166, 0, 686, 0, 687, 0, 422, 423, 424, 0, 700, 1033, 0, 425, 1281, 1282, 0, 1268, 355, 888, 0, 680, 1012, 858, 0, 0, 0, 882, 443, 0, 1268, 0, 897, 885, 1100, 1104, 0, 0, 0, 1275, 0, 443, 0, 1283, 1344, 1345, 996, 0, 0, 1063, 1063, 0, 0, 0, 681, 1074, 1070, 1071, 404, 407, 616, 620, 0, 0, 0, 0, 0, 0, 0, 986, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1149, 901, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1031, 1031 ); protected array $gotoCheck = array( 42, 42, 42, 42, 42, 73, 6, 73, 97, 86, 86, 48, 86, 86, 86, 48, 48, 48, 127, 65, 48, 65, 131, 9, 48, 48, 48, 48, 48, 48, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 23, 23, 23, 23, 15, 130, 130, 130, 134, 5, 5, 5, 5, 5, 66, 66, 8, 8, 35, 26, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 8, 84, 8, 8, 35, 8, 49, 35, 84, 5, 5, 5, 5, 5, 5, 185, 185, 185, 191, 191, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 15, 15, 157, 157, 27, 15, 191, 12, 159, 14, 14, 157, 15, 15, 15, 15, 159, 177, 24, 24, 24, 24, 191, 191, 43, 14, 14, 50, 45, 14, 50, 14, 50, 97, 97, 50, 50, 50, 73, 73, 73, 73, 14, 177, 177, 14, 14, 181, 73, 73, 12, 73, 12, 73, 73, 148, 148, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 188, 79, 79, 56, 56, 73, 79, 79, 79, 79, 73, 73, 73, 73, 190, 13, 73, 13, 62, 73, 73, 9, 9, 9, 9, 14, 76, 76, 119, 119, 89, 89, 9, 9, 89, 89, 103, 73, 89, 89, 89, 73, 19, 19, 19, 104, 163, 14, 163, 22, 64, 22, 19, 7, 163, 158, 76, 76, 76, 76, 76, 76, 76, 76, 7, 76, 76, 115, 46, 7, 46, 113, 7, 76, 120, 120, 19, 178, 178, 14, 117, 19, 19, 19, 19, 187, 187, 19, 108, 108, 19, 19, 2, 2, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 179, 179, 22, 83, 121, 83, 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, 29, 5, 5, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 80, 23, 18, 23, 23, 23, 134, 134, 134, 165, 165, 14, 93, 93, 93, 165, 134, 165, 165, 165, 165, 165, 165, 165, 165, 83, 39, 9, 9, 9, 85, 85, 85, 9, 92, 9, 28, 9, 9, 37, 169, 134, 134, 134, 134, 25, 25, 25, 25, 110, 9, 9, 9, 9, 99, 107, 107, 107, 107, 9, 107, 133, 9, 9, 31, 180, 180, 41, 160, 151, 134, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 24, 136, 24, 24, 24, 96, 9, -1, 20, 114, -1, -1, 22, -1, -1, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, -1, -1, 23, 134, 182, 182, -1, 134, 134, 134, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 17, 17, 82, 82, 17, 17, -1, 82, -1, 82, -1, 82, 82, 82, -1, 82, 17, -1, 82, 20, 20, -1, 20, 82, 17, -1, 17, 17, 20, -1, -1, -1, 17, 118, -1, 20, -1, 16, 16, 16, 16, -1, -1, -1, 17, -1, 118, -1, 20, 20, 20, 16, -1, -1, 118, 118, -1, -1, -1, 118, 118, 118, 118, 59, 59, 59, 59, -1, -1, -1, -1, -1, -1, -1, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 16, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 107, 107 ); protected array $gotoBase = array( 0, 0, -339, 0, 0, 174, -7, 339, 171, 10, 0, 0, -69, -36, -78, -186, 130, 81, 114, 66, 117, 0, 62, 160, 240, 468, 178, 225, 118, 112, 0, 45, 0, 0, 0, -195, 0, 119, 0, 122, 0, 44, -1, 226, 0, 227, -387, 0, -715, 182, 241, 0, 0, 0, 0, 0, 256, 0, 0, 570, 0, 0, 269, 0, 102, 3, -63, 0, 0, 0, 0, 0, 0, -5, 0, 0, -31, 0, 0, -120, 110, 53, 54, 120, -286, -33, -724, 0, 0, 40, 0, 0, 124, 129, 0, 0, 61, -488, 0, 67, 0, 0, 0, 294, 295, 0, 0, 453, 141, 0, 100, 0, 0, 83, -3, 82, 0, 86, 318, 38, 78, 107, 0, 0, 0, 0, 0, 16, 0, 0, 168, 20, 0, 108, 163, 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 43, 0, 0, 0, 0, 0, 193, 101, -38, 46, 0, 0, -166, 0, 195, 0, 0, 0, 92, 0, 0, 0, 0, 0, 0, 0, -60, 42, 157, 251, 243, 297, 0, 0, -97, 0, 1, 263, 0, 276, -101, 0, 0 ); protected array $gotoDefault = array( -32768, 526, 755, 7, 756, 951, 831, 840, 590, 544, 722, 356, 641, 432, 1352, 927, 1165, 610, 859, 1294, 1300, 468, 862, 340, 745, 939, 910, 911, 408, 395, 875, 406, 665, 642, 507, 895, 464, 887, 499, 890, 463, 899, 167, 428, 524, 903, 6, 906, 572, 937, 991, 396, 914, 397, 693, 916, 594, 918, 919, 403, 409, 410, 1170, 602, 638, 931, 261, 596, 932, 394, 933, 941, 399, 401, 703, 479, 518, 512, 421, 1132, 597, 625, 662, 457, 486, 636, 648, 635, 493, 444, 426, 339, 975, 983, 500, 477, 997, 358, 1005, 753, 1178, 656, 502, 1013, 657, 1020, 1023, 545, 546, 491, 1035, 271, 1038, 503, 1048, 26, 683, 1053, 1054, 684, 658, 1076, 659, 685, 660, 1078, 476, 592, 1179, 475, 1093, 1099, 465, 1102, 1340, 466, 1106, 270, 1109, 284, 427, 445, 1115, 1116, 12, 1122, 713, 714, 25, 280, 523, 1150, 704,-32768,-32768,-32768,-32768, 462, 1177, 461, 1249, 1251, 573, 504, 1269, 301, 1272, 696, 519, 1277, 458, 1343, 459, 547, 487, 325, 548, 1387, 315, 343, 322, 564, 302, 344, 549, 488, 1349, 1357, 341, 34, 1377, 1388, 607, 630 ); protected array $ruleToNonTerminal = array( 0, 1, 3, 3, 2, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 9, 10, 11, 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 16, 17, 17, 18, 18, 21, 21, 22, 23, 23, 24, 24, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 29, 29, 30, 30, 32, 34, 34, 28, 36, 36, 33, 38, 38, 35, 35, 37, 37, 39, 39, 31, 40, 40, 41, 43, 44, 44, 45, 45, 46, 46, 48, 47, 47, 47, 47, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 25, 25, 50, 69, 69, 72, 72, 71, 70, 70, 63, 75, 75, 76, 76, 77, 77, 78, 78, 79, 79, 80, 80, 80, 80, 26, 26, 27, 27, 27, 27, 27, 88, 88, 90, 90, 83, 83, 91, 91, 92, 92, 92, 84, 84, 87, 87, 85, 85, 93, 94, 94, 57, 57, 65, 65, 68, 68, 68, 67, 95, 95, 96, 58, 58, 58, 58, 97, 97, 98, 98, 99, 99, 100, 101, 101, 102, 102, 103, 103, 55, 55, 51, 51, 105, 53, 53, 106, 52, 52, 54, 54, 64, 64, 64, 64, 81, 81, 109, 109, 111, 111, 112, 112, 112, 112, 112, 112, 112, 112, 110, 110, 110, 115, 115, 115, 115, 89, 89, 118, 118, 118, 119, 119, 116, 116, 120, 120, 122, 122, 123, 123, 117, 124, 124, 121, 125, 125, 125, 125, 113, 113, 82, 82, 82, 20, 20, 20, 128, 128, 128, 128, 129, 129, 129, 127, 126, 126, 131, 131, 131, 130, 130, 60, 132, 132, 133, 61, 135, 135, 136, 136, 137, 137, 86, 138, 138, 138, 138, 138, 138, 138, 143, 143, 144, 144, 145, 145, 145, 145, 145, 146, 147, 147, 142, 142, 139, 139, 141, 141, 149, 149, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 140, 150, 150, 152, 151, 151, 153, 153, 114, 154, 154, 156, 156, 156, 155, 155, 62, 104, 157, 157, 56, 56, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 164, 165, 165, 166, 158, 158, 163, 163, 167, 168, 168, 169, 170, 171, 171, 171, 171, 19, 19, 73, 73, 73, 73, 159, 159, 159, 159, 173, 173, 162, 162, 162, 160, 160, 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, 180, 180, 180, 108, 182, 182, 182, 182, 161, 161, 161, 161, 161, 161, 161, 161, 59, 59, 176, 176, 176, 176, 176, 183, 183, 172, 172, 172, 172, 184, 184, 184, 184, 184, 184, 74, 74, 66, 66, 66, 66, 134, 134, 134, 134, 187, 186, 175, 175, 175, 175, 175, 175, 175, 174, 174, 174, 185, 185, 185, 185, 107, 181, 189, 189, 188, 188, 190, 190, 190, 190, 190, 190, 190, 190, 178, 178, 178, 178, 177, 192, 191, 191, 191, 191, 191, 191, 191, 191, 193, 193, 193, 193 ); protected array $ruleToLength = array( 1, 1, 2, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 2, 1, 3, 4, 1, 2, 0, 1, 1, 1, 1, 4, 3, 5, 4, 3, 4, 1, 3, 4, 1, 1, 8, 7, 2, 3, 1, 2, 3, 1, 2, 3, 1, 1, 3, 1, 3, 1, 2, 2, 3, 1, 3, 2, 3, 1, 3, 3, 2, 0, 1, 1, 1, 1, 1, 3, 7, 10, 5, 7, 9, 5, 3, 3, 3, 3, 3, 3, 1, 2, 5, 7, 9, 6, 5, 6, 3, 2, 1, 1, 1, 1, 0, 2, 1, 3, 8, 0, 4, 2, 1, 3, 0, 1, 0, 1, 0, 1, 3, 1, 1, 1, 1, 1, 8, 9, 7, 8, 7, 6, 8, 0, 2, 0, 2, 1, 2, 1, 2, 1, 1, 1, 0, 2, 0, 2, 0, 2, 2, 1, 3, 1, 4, 1, 4, 1, 1, 4, 2, 1, 3, 3, 3, 4, 4, 5, 0, 2, 4, 3, 1, 1, 7, 0, 2, 1, 3, 3, 4, 1, 4, 0, 2, 5, 0, 2, 6, 0, 2, 0, 3, 1, 2, 1, 1, 2, 0, 1, 3, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 7, 9, 6, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 3, 3, 3, 3, 3, 1, 3, 3, 1, 1, 2, 1, 1, 0, 1, 0, 2, 2, 2, 4, 3, 2, 4, 4, 3, 3, 1, 3, 1, 1, 3, 2, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 3, 2, 0, 1, 5, 5, 6, 10, 3, 5, 1, 1, 3, 0, 2, 4, 5, 4, 4, 4, 3, 1, 1, 1, 1, 1, 1, 0, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3, 1, 1, 3, 0, 2, 0, 5, 8, 1, 3, 3, 0, 2, 2, 2, 3, 1, 0, 1, 1, 3, 3, 3, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 3, 4, 4, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 3, 2, 1, 2, 4, 2, 2, 8, 9, 8, 9, 9, 10, 9, 10, 8, 3, 2, 2, 1, 1, 0, 4, 2, 1, 3, 2, 1, 2, 2, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 5, 3, 3, 4, 1, 1, 3, 1, 1, 1, 1, 1, 3, 2, 3, 0, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 4, 4, 1, 4, 4, 0, 1, 1, 1, 3, 3, 1, 4, 2, 2, 1, 3, 1, 4, 4, 3, 3, 3, 3, 1, 3, 1, 1, 3, 1, 1, 4, 1, 1, 1, 3, 1, 1, 2, 1, 3, 4, 3, 2, 0, 2, 2, 1, 2, 1, 1, 1, 4, 3, 3, 3, 3, 6, 3, 1, 1, 2, 1 ); protected function initReduceCallbacks(): void { $this->reduceCallbacks = [ 0 => null, 1 => static function ($self, $stackPos) { $self->semValue = $self->handleNamespaces($self->semStack[$stackPos-(1-1)]); }, 2 => static function ($self, $stackPos) { if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; } $self->semValue = $self->semStack[$stackPos-(2-1)];; }, 3 => static function ($self, $stackPos) { $self->semValue = array(); }, 4 => static function ($self, $stackPos) { $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 5 => null, 6 => null, 7 => null, 8 => null, 9 => null, 10 => null, 11 => null, 12 => null, 13 => null, 14 => null, 15 => null, 16 => null, 17 => null, 18 => null, 19 => null, 20 => null, 21 => null, 22 => null, 23 => null, 24 => null, 25 => null, 26 => null, 27 => null, 28 => null, 29 => null, 30 => null, 31 => null, 32 => null, 33 => null, 34 => null, 35 => null, 36 => null, 37 => null, 38 => null, 39 => null, 40 => null, 41 => null, 42 => null, 43 => null, 44 => null, 45 => null, 46 => null, 47 => null, 48 => null, 49 => null, 50 => null, 51 => null, 52 => null, 53 => null, 54 => null, 55 => null, 56 => null, 57 => null, 58 => null, 59 => null, 60 => null, 61 => null, 62 => null, 63 => null, 64 => null, 65 => null, 66 => null, 67 => null, 68 => null, 69 => null, 70 => null, 71 => null, 72 => null, 73 => null, 74 => null, 75 => null, 76 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; if ($self->semValue === "emitError(new Error('Cannot use "getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]))); }, 77 => null, 78 => null, 79 => null, 80 => null, 81 => null, 82 => null, 83 => null, 84 => null, 85 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 86 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 87 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 88 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 89 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 90 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 91 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 92 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 93 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 94 => null, 95 => static function ($self, $stackPos) { $self->semValue = new Name(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 96 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 97 => static function ($self, $stackPos) { /* nothing */ }, 98 => static function ($self, $stackPos) { /* nothing */ }, 99 => static function ($self, $stackPos) { /* nothing */ }, 100 => static function ($self, $stackPos) { $self->emitError(new Error('A trailing comma is not allowed here', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]))); }, 101 => null, 102 => null, 103 => static function ($self, $stackPos) { $self->semValue = new Node\Attribute($self->semStack[$stackPos-(1-1)], [], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 104 => static function ($self, $stackPos) { $self->semValue = new Node\Attribute($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 105 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 106 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 107 => static function ($self, $stackPos) { $self->semValue = new Node\AttributeGroup($self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 108 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 109 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 110 => static function ($self, $stackPos) { $self->semValue = []; }, 111 => null, 112 => null, 113 => null, 114 => null, 115 => static function ($self, $stackPos) { $self->semValue = new Stmt\HaltCompiler($self->handleHaltCompiler(), $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 116 => static function ($self, $stackPos) { $self->semValue = new Stmt\Namespace_($self->semStack[$stackPos-(3-2)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON); $self->checkNamespace($self->semValue); }, 117 => static function ($self, $stackPos) { $self->semValue = new Stmt\Namespace_($self->semStack[$stackPos-(5-2)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); $self->checkNamespace($self->semValue); }, 118 => static function ($self, $stackPos) { $self->semValue = new Stmt\Namespace_(null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); $self->checkNamespace($self->semValue); }, 119 => static function ($self, $stackPos) { $self->semValue = new Stmt\Use_($self->semStack[$stackPos-(3-2)], Stmt\Use_::TYPE_NORMAL, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 120 => static function ($self, $stackPos) { $self->semValue = new Stmt\Use_($self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 121 => null, 122 => static function ($self, $stackPos) { $self->semValue = new Stmt\Const_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), []); }, 123 => static function ($self, $stackPos) { $self->semValue = new Stmt\Const_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(4-1)]); $self->checkConstantAttributes($self->semValue); }, 124 => static function ($self, $stackPos) { $self->semValue = Stmt\Use_::TYPE_FUNCTION; }, 125 => static function ($self, $stackPos) { $self->semValue = Stmt\Use_::TYPE_CONSTANT; }, 126 => static function ($self, $stackPos) { $self->semValue = new Stmt\GroupUse($self->semStack[$stackPos-(8-3)], $self->semStack[$stackPos-(8-6)], $self->semStack[$stackPos-(8-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, 127 => static function ($self, $stackPos) { $self->semValue = new Stmt\GroupUse($self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-5)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, 128 => null, 129 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 130 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 131 => null, 132 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 133 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 134 => null, 135 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 136 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 137 => static function ($self, $stackPos) { $self->semValue = new Node\UseItem($self->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(1-1)); }, 138 => static function ($self, $stackPos) { $self->semValue = new Node\UseItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(3-3)); }, 139 => static function ($self, $stackPos) { $self->semValue = new Node\UseItem($self->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(1-1)); }, 140 => static function ($self, $stackPos) { $self->semValue = new Node\UseItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(3-3)); }, 141 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; $self->semValue->type = Stmt\Use_::TYPE_NORMAL; }, 142 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; $self->semValue->type = $self->semStack[$stackPos-(2-1)]; }, 143 => null, 144 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 145 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 146 => static function ($self, $stackPos) { $self->semValue = new Node\Const_($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 147 => null, 148 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 149 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 150 => static function ($self, $stackPos) { $self->semValue = new Node\Const_(new Node\Identifier($self->semStack[$stackPos-(3-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 151 => static function ($self, $stackPos) { $self->semValue = new Node\Const_(new Node\Identifier($self->semStack[$stackPos-(3-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 152 => static function ($self, $stackPos) { if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; } $self->semValue = $self->semStack[$stackPos-(2-1)];; }, 153 => static function ($self, $stackPos) { $self->semValue = array(); }, 154 => static function ($self, $stackPos) { $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 155 => null, 156 => null, 157 => null, 158 => static function ($self, $stackPos) { throw new Error('__HALT_COMPILER() can only be used from the outermost scope', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 159 => static function ($self, $stackPos) { $self->semValue = new Stmt\Block($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 160 => static function ($self, $stackPos) { $self->semValue = new Stmt\If_($self->semStack[$stackPos-(7-3)], ['stmts' => $self->semStack[$stackPos-(7-5)], 'elseifs' => $self->semStack[$stackPos-(7-6)], 'else' => $self->semStack[$stackPos-(7-7)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, 161 => static function ($self, $stackPos) { $self->semValue = new Stmt\If_($self->semStack[$stackPos-(10-3)], ['stmts' => $self->semStack[$stackPos-(10-6)], 'elseifs' => $self->semStack[$stackPos-(10-7)], 'else' => $self->semStack[$stackPos-(10-8)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); }, 162 => static function ($self, $stackPos) { $self->semValue = new Stmt\While_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 163 => static function ($self, $stackPos) { $self->semValue = new Stmt\Do_($self->semStack[$stackPos-(7-5)], $self->semStack[$stackPos-(7-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, 164 => static function ($self, $stackPos) { $self->semValue = new Stmt\For_(['init' => $self->semStack[$stackPos-(9-3)], 'cond' => $self->semStack[$stackPos-(9-5)], 'loop' => $self->semStack[$stackPos-(9-7)], 'stmts' => $self->semStack[$stackPos-(9-9)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 165 => static function ($self, $stackPos) { $self->semValue = new Stmt\Switch_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 166 => static function ($self, $stackPos) { $self->semValue = new Stmt\Break_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 167 => static function ($self, $stackPos) { $self->semValue = new Stmt\Continue_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 168 => static function ($self, $stackPos) { $self->semValue = new Stmt\Return_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 169 => static function ($self, $stackPos) { $self->semValue = new Stmt\Global_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 170 => static function ($self, $stackPos) { $self->semValue = new Stmt\Static_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 171 => static function ($self, $stackPos) { $self->semValue = new Stmt\Echo_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 172 => static function ($self, $stackPos) { $self->semValue = new Stmt\InlineHTML($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('hasLeadingNewline', $self->inlineHtmlHasLeadingNewline($stackPos-(1-1))); }, 173 => static function ($self, $stackPos) { $self->semValue = new Stmt\Expression($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 174 => static function ($self, $stackPos) { $self->semValue = new Stmt\Unset_($self->semStack[$stackPos-(5-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 175 => static function ($self, $stackPos) { $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-5)][0], ['keyVar' => null, 'byRef' => $self->semStack[$stackPos-(7-5)][1], 'stmts' => $self->semStack[$stackPos-(7-7)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, 176 => static function ($self, $stackPos) { $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(9-3)], $self->semStack[$stackPos-(9-7)][0], ['keyVar' => $self->semStack[$stackPos-(9-5)], 'byRef' => $self->semStack[$stackPos-(9-7)][1], 'stmts' => $self->semStack[$stackPos-(9-9)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 177 => static function ($self, $stackPos) { $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(6-3)], new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(6-4)], $self->tokenEndStack[$stackPos-(6-4)])), ['stmts' => $self->semStack[$stackPos-(6-6)]], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); }, 178 => static function ($self, $stackPos) { $self->semValue = new Stmt\Declare_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 179 => static function ($self, $stackPos) { $self->semValue = new Stmt\TryCatch($self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-5)], $self->semStack[$stackPos-(6-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); $self->checkTryCatch($self->semValue); }, 180 => static function ($self, $stackPos) { $self->semValue = new Stmt\Goto_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 181 => static function ($self, $stackPos) { $self->semValue = new Stmt\Label($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 182 => static function ($self, $stackPos) { $self->semValue = null; /* means: no statement */ }, 183 => null, 184 => static function ($self, $stackPos) { $self->semValue = $self->maybeCreateNop($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]); }, 185 => static function ($self, $stackPos) { if ($self->semStack[$stackPos-(1-1)] instanceof Stmt\Block) { $self->semValue = $self->semStack[$stackPos-(1-1)]->stmts; } else if ($self->semStack[$stackPos-(1-1)] === null) { $self->semValue = []; } else { $self->semValue = [$self->semStack[$stackPos-(1-1)]]; }; }, 186 => static function ($self, $stackPos) { $self->semValue = array(); }, 187 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 188 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 189 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 190 => static function ($self, $stackPos) { $self->semValue = new Stmt\Catch_($self->semStack[$stackPos-(8-3)], $self->semStack[$stackPos-(8-4)], $self->semStack[$stackPos-(8-7)], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, 191 => static function ($self, $stackPos) { $self->semValue = null; }, 192 => static function ($self, $stackPos) { $self->semValue = new Stmt\Finally_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 193 => null, 194 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 195 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 196 => static function ($self, $stackPos) { $self->semValue = false; }, 197 => static function ($self, $stackPos) { $self->semValue = true; }, 198 => static function ($self, $stackPos) { $self->semValue = false; }, 199 => static function ($self, $stackPos) { $self->semValue = true; }, 200 => static function ($self, $stackPos) { $self->semValue = false; }, 201 => static function ($self, $stackPos) { $self->semValue = true; }, 202 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 203 => static function ($self, $stackPos) { $self->semValue = []; }, 204 => null, 205 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 206 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 207 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 208 => static function ($self, $stackPos) { $self->semValue = new Stmt\Function_($self->semStack[$stackPos-(8-3)], ['byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-5)], 'returnType' => $self->semStack[$stackPos-(8-7)], 'stmts' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, 209 => static function ($self, $stackPos) { $self->semValue = new Stmt\Function_($self->semStack[$stackPos-(9-4)], ['byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-6)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 210 => static function ($self, $stackPos) { $self->semValue = new Stmt\Class_($self->semStack[$stackPos-(7-2)], ['type' => $self->semStack[$stackPos-(7-1)], 'extends' => $self->semStack[$stackPos-(7-3)], 'implements' => $self->semStack[$stackPos-(7-4)], 'stmts' => $self->semStack[$stackPos-(7-6)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); $self->checkClass($self->semValue, $stackPos-(7-2)); }, 211 => static function ($self, $stackPos) { $self->semValue = new Stmt\Class_($self->semStack[$stackPos-(8-3)], ['type' => $self->semStack[$stackPos-(8-2)], 'extends' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); $self->checkClass($self->semValue, $stackPos-(8-3)); }, 212 => static function ($self, $stackPos) { $self->semValue = new Stmt\Interface_($self->semStack[$stackPos-(7-3)], ['extends' => $self->semStack[$stackPos-(7-4)], 'stmts' => $self->semStack[$stackPos-(7-6)], 'attrGroups' => $self->semStack[$stackPos-(7-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); $self->checkInterface($self->semValue, $stackPos-(7-3)); }, 213 => static function ($self, $stackPos) { $self->semValue = new Stmt\Trait_($self->semStack[$stackPos-(6-3)], ['stmts' => $self->semStack[$stackPos-(6-5)], 'attrGroups' => $self->semStack[$stackPos-(6-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); }, 214 => static function ($self, $stackPos) { $self->semValue = new Stmt\Enum_($self->semStack[$stackPos-(8-3)], ['scalarType' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); $self->checkEnum($self->semValue, $stackPos-(8-3)); }, 215 => static function ($self, $stackPos) { $self->semValue = null; }, 216 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 217 => static function ($self, $stackPos) { $self->semValue = null; }, 218 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 219 => static function ($self, $stackPos) { $self->semValue = 0; }, 220 => null, 221 => null, 222 => static function ($self, $stackPos) { $self->checkClassModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, 223 => static function ($self, $stackPos) { $self->semValue = Modifiers::ABSTRACT; }, 224 => static function ($self, $stackPos) { $self->semValue = Modifiers::FINAL; }, 225 => static function ($self, $stackPos) { $self->semValue = Modifiers::READONLY; }, 226 => static function ($self, $stackPos) { $self->semValue = null; }, 227 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 228 => static function ($self, $stackPos) { $self->semValue = array(); }, 229 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 230 => static function ($self, $stackPos) { $self->semValue = array(); }, 231 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 232 => null, 233 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 234 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 235 => null, 236 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 237 => null, 238 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 239 => static function ($self, $stackPos) { if ($self->semStack[$stackPos-(1-1)] instanceof Stmt\Block) { $self->semValue = $self->semStack[$stackPos-(1-1)]->stmts; } else if ($self->semStack[$stackPos-(1-1)] === null) { $self->semValue = []; } else { $self->semValue = [$self->semStack[$stackPos-(1-1)]]; }; }, 240 => static function ($self, $stackPos) { $self->semValue = null; }, 241 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 242 => null, 243 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 244 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 245 => static function ($self, $stackPos) { $self->semValue = new Node\DeclareItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 246 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 247 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-3)]; }, 248 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 249 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(5-3)]; }, 250 => static function ($self, $stackPos) { $self->semValue = array(); }, 251 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 252 => static function ($self, $stackPos) { $self->semValue = new Stmt\Case_($self->semStack[$stackPos-(4-2)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 253 => static function ($self, $stackPos) { $self->semValue = new Stmt\Case_(null, $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 254 => null, 255 => null, 256 => static function ($self, $stackPos) { $self->semValue = new Expr\Match_($self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, 257 => static function ($self, $stackPos) { $self->semValue = []; }, 258 => null, 259 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 260 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 261 => static function ($self, $stackPos) { $self->semValue = new Node\MatchArm($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 262 => static function ($self, $stackPos) { $self->semValue = new Node\MatchArm(null, $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 263 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 264 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 265 => static function ($self, $stackPos) { $self->semValue = array(); }, 266 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 267 => static function ($self, $stackPos) { $self->semValue = new Stmt\ElseIf_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 268 => static function ($self, $stackPos) { $self->semValue = array(); }, 269 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 270 => static function ($self, $stackPos) { $self->semValue = new Stmt\ElseIf_($self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); $self->fixupAlternativeElse($self->semValue); }, 271 => static function ($self, $stackPos) { $self->semValue = null; }, 272 => static function ($self, $stackPos) { $self->semValue = new Stmt\Else_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 273 => static function ($self, $stackPos) { $self->semValue = null; }, 274 => static function ($self, $stackPos) { $self->semValue = new Stmt\Else_($self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->fixupAlternativeElse($self->semValue); }, 275 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)], false); }, 276 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(2-2)], true); }, 277 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)], false); }, 278 => static function ($self, $stackPos) { $self->semValue = array($self->fixupArrayDestructuring($self->semStack[$stackPos-(1-1)]), false); }, 279 => null, 280 => static function ($self, $stackPos) { $self->semValue = array(); }, 281 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 282 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 283 => static function ($self, $stackPos) { $self->semValue = 0; }, 284 => static function ($self, $stackPos) { $self->checkModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, 285 => static function ($self, $stackPos) { $self->semValue = Modifiers::PUBLIC; }, 286 => static function ($self, $stackPos) { $self->semValue = Modifiers::PROTECTED; }, 287 => static function ($self, $stackPos) { $self->semValue = Modifiers::PRIVATE; }, 288 => static function ($self, $stackPos) { $self->semValue = Modifiers::PUBLIC_SET; }, 289 => static function ($self, $stackPos) { $self->semValue = Modifiers::PROTECTED_SET; }, 290 => static function ($self, $stackPos) { $self->semValue = Modifiers::PRIVATE_SET; }, 291 => static function ($self, $stackPos) { $self->semValue = Modifiers::READONLY; }, 292 => static function ($self, $stackPos) { $self->semValue = Modifiers::FINAL; }, 293 => static function ($self, $stackPos) { $self->semValue = new Node\Param($self->semStack[$stackPos-(7-6)], null, $self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-4)], $self->semStack[$stackPos-(7-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-1)], $self->semStack[$stackPos-(7-7)]); $self->checkParam($self->semValue); $self->addPropertyNameToHooks($self->semValue); }, 294 => static function ($self, $stackPos) { $self->semValue = new Node\Param($self->semStack[$stackPos-(9-6)], $self->semStack[$stackPos-(9-8)], $self->semStack[$stackPos-(9-3)], $self->semStack[$stackPos-(9-4)], $self->semStack[$stackPos-(9-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(9-2)], $self->semStack[$stackPos-(9-1)], $self->semStack[$stackPos-(9-9)]); $self->checkParam($self->semValue); $self->addPropertyNameToHooks($self->semValue); }, 295 => static function ($self, $stackPos) { $self->semValue = new Node\Param(new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])), null, $self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-4)], $self->semStack[$stackPos-(6-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(6-2)], $self->semStack[$stackPos-(6-1)]); }, 296 => null, 297 => static function ($self, $stackPos) { $self->semValue = new Node\NullableType($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 298 => static function ($self, $stackPos) { $self->semValue = new Node\UnionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 299 => null, 300 => null, 301 => static function ($self, $stackPos) { $self->semValue = new Node\Name('static', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 302 => static function ($self, $stackPos) { $self->semValue = $self->handleBuiltinTypes($self->semStack[$stackPos-(1-1)]); }, 303 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier('array', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 304 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier('callable', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 305 => null, 306 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 307 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, 308 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 309 => null, 310 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 311 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, 312 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 313 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, 314 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 315 => static function ($self, $stackPos) { $self->semValue = new Node\IntersectionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 316 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, 317 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 318 => static function ($self, $stackPos) { $self->semValue = new Node\IntersectionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 319 => null, 320 => static function ($self, $stackPos) { $self->semValue = new Node\NullableType($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 321 => static function ($self, $stackPos) { $self->semValue = new Node\UnionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 322 => null, 323 => static function ($self, $stackPos) { $self->semValue = null; }, 324 => null, 325 => static function ($self, $stackPos) { $self->semValue = null; }, 326 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 327 => static function ($self, $stackPos) { $self->semValue = null; }, 328 => static function ($self, $stackPos) { $self->semValue = array(); }, 329 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 330 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-2)]); }, 331 => static function ($self, $stackPos) { $self->semValue = array(); }, 332 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 333 => static function ($self, $stackPos) { $self->semValue = array(new Node\Arg($self->semStack[$stackPos-(4-2)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]))); }, 334 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-2)]); }, 335 => static function ($self, $stackPos) { $self->semValue = array(new Node\Arg($self->semStack[$stackPos-(3-1)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)]); }, 336 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 337 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 338 => static function ($self, $stackPos) { $self->semValue = new Node\VariadicPlaceholder($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 339 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 340 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 341 => static function ($self, $stackPos) { $self->semValue = new Node\Arg($self->semStack[$stackPos-(2-2)], true, false, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 342 => static function ($self, $stackPos) { $self->semValue = new Node\Arg($self->semStack[$stackPos-(2-2)], false, true, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 343 => static function ($self, $stackPos) { $self->semValue = new Node\Arg($self->semStack[$stackPos-(3-3)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(3-1)]); }, 344 => static function ($self, $stackPos) { $self->semValue = new Node\Arg($self->semStack[$stackPos-(1-1)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 345 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 346 => null, 347 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 348 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 349 => null, 350 => null, 351 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 352 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 353 => static function ($self, $stackPos) { $self->semValue = new Node\StaticVar($self->semStack[$stackPos-(1-1)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 354 => static function ($self, $stackPos) { $self->semValue = new Node\StaticVar($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 355 => static function ($self, $stackPos) { if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; } else { $self->semValue = $self->semStack[$stackPos-(2-1)]; } }, 356 => static function ($self, $stackPos) { $self->semValue = array(); }, 357 => static function ($self, $stackPos) { $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 358 => static function ($self, $stackPos) { $self->semValue = new Stmt\Property($self->semStack[$stackPos-(5-2)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-1)]); }, 359 => static function ($self, $stackPos) { $self->semValue = new Stmt\ClassConst($self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(5-1)]); $self->checkClassConst($self->semValue, $stackPos-(5-2)); }, 360 => static function ($self, $stackPos) { $self->semValue = new Stmt\ClassConst($self->semStack[$stackPos-(6-5)], $self->semStack[$stackPos-(6-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(6-1)], $self->semStack[$stackPos-(6-4)]); $self->checkClassConst($self->semValue, $stackPos-(6-2)); }, 361 => static function ($self, $stackPos) { $self->semValue = new Stmt\ClassMethod($self->semStack[$stackPos-(10-5)], ['type' => $self->semStack[$stackPos-(10-2)], 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-7)], 'returnType' => $self->semStack[$stackPos-(10-9)], 'stmts' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); $self->checkClassMethod($self->semValue, $stackPos-(10-2)); }, 362 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUse($self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 363 => static function ($self, $stackPos) { $self->semValue = new Stmt\EnumCase($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 364 => static function ($self, $stackPos) { $self->semValue = null; /* will be skipped */ }, 365 => static function ($self, $stackPos) { $self->semValue = array(); }, 366 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 367 => static function ($self, $stackPos) { $self->semValue = array(); }, 368 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 369 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUseAdaptation\Precedence($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 370 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(5-1)][0], $self->semStack[$stackPos-(5-1)][1], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 371 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 372 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 373 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 374 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, 375 => null, 376 => static function ($self, $stackPos) { $self->semValue = array(null, $self->semStack[$stackPos-(1-1)]); }, 377 => static function ($self, $stackPos) { $self->semValue = null; }, 378 => null, 379 => null, 380 => static function ($self, $stackPos) { $self->semValue = 0; }, 381 => static function ($self, $stackPos) { $self->semValue = 0; }, 382 => null, 383 => null, 384 => static function ($self, $stackPos) { $self->checkModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, 385 => static function ($self, $stackPos) { $self->semValue = Modifiers::PUBLIC; }, 386 => static function ($self, $stackPos) { $self->semValue = Modifiers::PROTECTED; }, 387 => static function ($self, $stackPos) { $self->semValue = Modifiers::PRIVATE; }, 388 => static function ($self, $stackPos) { $self->semValue = Modifiers::PUBLIC_SET; }, 389 => static function ($self, $stackPos) { $self->semValue = Modifiers::PROTECTED_SET; }, 390 => static function ($self, $stackPos) { $self->semValue = Modifiers::PRIVATE_SET; }, 391 => static function ($self, $stackPos) { $self->semValue = Modifiers::STATIC; }, 392 => static function ($self, $stackPos) { $self->semValue = Modifiers::ABSTRACT; }, 393 => static function ($self, $stackPos) { $self->semValue = Modifiers::FINAL; }, 394 => static function ($self, $stackPos) { $self->semValue = Modifiers::READONLY; }, 395 => null, 396 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 397 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 398 => static function ($self, $stackPos) { $self->semValue = new Node\VarLikeIdentifier(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 399 => static function ($self, $stackPos) { $self->semValue = new Node\PropertyItem($self->semStack[$stackPos-(1-1)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 400 => static function ($self, $stackPos) { $self->semValue = new Node\PropertyItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 401 => static function ($self, $stackPos) { $self->semValue = []; }, 402 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 403 => static function ($self, $stackPos) { $self->semValue = []; }, 404 => static function ($self, $stackPos) { $self->semValue = new Node\PropertyHook($self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-5)], ['flags' => $self->semStack[$stackPos-(5-2)], 'byRef' => $self->semStack[$stackPos-(5-3)], 'params' => [], 'attrGroups' => $self->semStack[$stackPos-(5-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); $self->checkPropertyHook($self->semValue, null); }, 405 => static function ($self, $stackPos) { $self->semValue = new Node\PropertyHook($self->semStack[$stackPos-(8-4)], $self->semStack[$stackPos-(8-8)], ['flags' => $self->semStack[$stackPos-(8-2)], 'byRef' => $self->semStack[$stackPos-(8-3)], 'params' => $self->semStack[$stackPos-(8-6)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); $self->checkPropertyHook($self->semValue, $stackPos-(8-5)); }, 406 => static function ($self, $stackPos) { $self->semValue = null; }, 407 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 408 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 409 => static function ($self, $stackPos) { $self->semValue = 0; }, 410 => static function ($self, $stackPos) { $self->checkPropertyHookModifiers($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, 411 => null, 412 => null, 413 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 414 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 415 => static function ($self, $stackPos) { $self->semValue = array(); }, 416 => null, 417 => null, 418 => static function ($self, $stackPos) { $self->semValue = new Expr\Assign($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 419 => static function ($self, $stackPos) { $self->semValue = new Expr\Assign($self->fixupArrayDestructuring($self->semStack[$stackPos-(3-1)]), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 420 => static function ($self, $stackPos) { $self->semValue = new Expr\Assign($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 421 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignRef($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 422 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignRef($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); if (!$self->phpVersion->allowsAssignNewByReference()) { $self->emitError(new Error('Cannot assign new by reference', $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]))); } }, 423 => null, 424 => null, 425 => static function ($self, $stackPos) { $self->semValue = new Expr\FuncCall(new Node\Name($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos-(2-1)])), $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 426 => static function ($self, $stackPos) { $self->semValue = new Expr\Clone_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 427 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Plus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 428 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Minus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 429 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Mul($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 430 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Div($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 431 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Concat($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 432 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Mod($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 433 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 434 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\BitwiseOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 435 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\BitwiseXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 436 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\ShiftLeft($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 437 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\ShiftRight($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 438 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Pow($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 439 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Coalesce($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 440 => static function ($self, $stackPos) { $self->semValue = new Expr\PostInc($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 441 => static function ($self, $stackPos) { $self->semValue = new Expr\PreInc($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 442 => static function ($self, $stackPos) { $self->semValue = new Expr\PostDec($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 443 => static function ($self, $stackPos) { $self->semValue = new Expr\PreDec($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 444 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BooleanOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 445 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BooleanAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 446 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\LogicalOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 447 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\LogicalAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 448 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\LogicalXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 449 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BitwiseOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 450 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 451 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 452 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BitwiseXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 453 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Concat($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 454 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Plus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 455 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Minus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 456 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Mul($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 457 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Div($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 458 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Mod($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 459 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\ShiftLeft($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 460 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\ShiftRight($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 461 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Pow($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 462 => static function ($self, $stackPos) { $self->semValue = new Expr\UnaryPlus($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 463 => static function ($self, $stackPos) { $self->semValue = new Expr\UnaryMinus($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 464 => static function ($self, $stackPos) { $self->semValue = new Expr\BooleanNot($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 465 => static function ($self, $stackPos) { $self->semValue = new Expr\BitwiseNot($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 466 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Identical($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 467 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\NotIdentical($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 468 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Equal($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 469 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\NotEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 470 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Spaceship($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 471 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Smaller($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 472 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\SmallerOrEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 473 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Greater($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 474 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\GreaterOrEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 475 => static function ($self, $stackPos) { $self->semValue = new Expr\Instanceof_($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 476 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; if ($self->semValue instanceof Expr\ArrowFunction) { $self->parenthesizedArrowFunctions->offsetSet($self->semValue); } }, 477 => static function ($self, $stackPos) { $self->semValue = new Expr\Ternary($self->semStack[$stackPos-(5-1)], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 478 => static function ($self, $stackPos) { $self->semValue = new Expr\Ternary($self->semStack[$stackPos-(4-1)], null, $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 479 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Coalesce($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 480 => static function ($self, $stackPos) { $self->semValue = new Expr\Isset_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 481 => static function ($self, $stackPos) { $self->semValue = new Expr\Empty_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 482 => static function ($self, $stackPos) { $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 483 => static function ($self, $stackPos) { $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE_ONCE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 484 => static function ($self, $stackPos) { $self->semValue = new Expr\Eval_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 485 => static function ($self, $stackPos) { $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 486 => static function ($self, $stackPos) { $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE_ONCE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 487 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = $self->getIntCastKind($self->semStack[$stackPos-(2-1)]); $self->semValue = new Expr\Cast\Int_($self->semStack[$stackPos-(2-2)], $attrs); }, 488 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = $self->getFloatCastKind($self->semStack[$stackPos-(2-1)]); $self->semValue = new Expr\Cast\Double($self->semStack[$stackPos-(2-2)], $attrs); }, 489 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = $self->getStringCastKind($self->semStack[$stackPos-(2-1)]); $self->semValue = new Expr\Cast\String_($self->semStack[$stackPos-(2-2)], $attrs); }, 490 => static function ($self, $stackPos) { $self->semValue = new Expr\Cast\Array_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 491 => static function ($self, $stackPos) { $self->semValue = new Expr\Cast\Object_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 492 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = $self->getBoolCastKind($self->semStack[$stackPos-(2-1)]); $self->semValue = new Expr\Cast\Bool_($self->semStack[$stackPos-(2-2)], $attrs); }, 493 => static function ($self, $stackPos) { $self->semValue = new Expr\Cast\Unset_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 494 => static function ($self, $stackPos) { $self->semValue = new Expr\Cast\Void_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 495 => static function ($self, $stackPos) { $self->semValue = $self->createExitExpr($self->semStack[$stackPos-(2-1)], $stackPos-(2-1), $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 496 => static function ($self, $stackPos) { $self->semValue = new Expr\ErrorSuppress($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 497 => null, 498 => static function ($self, $stackPos) { $self->semValue = new Expr\ShellExec($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 499 => static function ($self, $stackPos) { $self->semValue = new Expr\Print_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 500 => static function ($self, $stackPos) { $self->semValue = new Expr\Yield_(null, null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 501 => static function ($self, $stackPos) { $self->semValue = new Expr\Yield_($self->semStack[$stackPos-(2-2)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 502 => static function ($self, $stackPos) { $self->semValue = new Expr\Yield_($self->semStack[$stackPos-(4-4)], $self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 503 => static function ($self, $stackPos) { $self->semValue = new Expr\YieldFrom($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 504 => static function ($self, $stackPos) { $self->semValue = new Expr\Throw_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 505 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrowFunction(['static' => false, 'byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-4)], 'returnType' => $self->semStack[$stackPos-(8-6)], 'expr' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, 506 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrowFunction(['static' => true, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'returnType' => $self->semStack[$stackPos-(9-7)], 'expr' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 507 => static function ($self, $stackPos) { $self->semValue = new Expr\Closure(['static' => false, 'byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-4)], 'uses' => $self->semStack[$stackPos-(8-6)], 'returnType' => $self->semStack[$stackPos-(8-7)], 'stmts' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, 508 => static function ($self, $stackPos) { $self->semValue = new Expr\Closure(['static' => true, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'uses' => $self->semStack[$stackPos-(9-7)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 509 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrowFunction(['static' => false, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'returnType' => $self->semStack[$stackPos-(9-7)], 'expr' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 510 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrowFunction(['static' => true, 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-6)], 'returnType' => $self->semStack[$stackPos-(10-8)], 'expr' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); }, 511 => static function ($self, $stackPos) { $self->semValue = new Expr\Closure(['static' => false, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'uses' => $self->semStack[$stackPos-(9-7)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 512 => static function ($self, $stackPos) { $self->semValue = new Expr\Closure(['static' => true, 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-6)], 'uses' => $self->semStack[$stackPos-(10-8)], 'returnType' => $self->semStack[$stackPos-(10-9)], 'stmts' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); }, 513 => static function ($self, $stackPos) { $self->semValue = array(new Stmt\Class_(null, ['type' => $self->semStack[$stackPos-(8-2)], 'extends' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])), $self->semStack[$stackPos-(8-3)]); $self->checkClass($self->semValue[0], -1); }, 514 => static function ($self, $stackPos) { $self->semValue = new Expr\New_($self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 515 => static function ($self, $stackPos) { list($class, $ctorArgs) = $self->semStack[$stackPos-(2-2)]; $self->semValue = new Expr\New_($class, $ctorArgs, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 516 => static function ($self, $stackPos) { $self->semValue = new Expr\New_($self->semStack[$stackPos-(2-2)], [], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 517 => null, 518 => null, 519 => static function ($self, $stackPos) { $self->semValue = array(); }, 520 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-3)]; }, 521 => null, 522 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 523 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 524 => static function ($self, $stackPos) { $self->semValue = new Node\ClosureUse($self->semStack[$stackPos-(2-2)], $self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 525 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 526 => static function ($self, $stackPos) { $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 527 => static function ($self, $stackPos) { $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 528 => static function ($self, $stackPos) { $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 529 => static function ($self, $stackPos) { $self->semValue = new Expr\StaticCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 530 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 531 => null, 532 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 533 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 534 => static function ($self, $stackPos) { $self->semValue = new Name\FullyQualified(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 535 => static function ($self, $stackPos) { $self->semValue = new Name\Relative(substr($self->semStack[$stackPos-(1-1)], 10), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 536 => null, 537 => null, 538 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 539 => static function ($self, $stackPos) { $self->semValue = new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, 540 => null, 541 => null, 542 => static function ($self, $stackPos) { $self->semValue = array(); }, 543 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); foreach ($self->semValue as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '`', $self->phpVersion->supportsUnicodeEscapes()); } }; }, 544 => static function ($self, $stackPos) { foreach ($self->semStack[$stackPos-(1-1)] as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '`', $self->phpVersion->supportsUnicodeEscapes()); } }; $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 545 => static function ($self, $stackPos) { $self->semValue = array(); }, 546 => null, 547 => static function ($self, $stackPos) { $self->semValue = new Expr\ConstFetch($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 548 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Line($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 549 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\File($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 550 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Dir($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 551 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Class_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 552 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Trait_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 553 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Method($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 554 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Function_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 555 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Namespace_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 556 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Property($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 557 => static function ($self, $stackPos) { $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 558 => static function ($self, $stackPos) { $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(5-1)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 559 => static function ($self, $stackPos) { $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(3-1)], new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)])), $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, 560 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Expr\Array_::KIND_SHORT; $self->semValue = new Expr\Array_($self->semStack[$stackPos-(3-2)], $attrs); }, 561 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Expr\Array_::KIND_LONG; $self->semValue = new Expr\Array_($self->semStack[$stackPos-(4-3)], $attrs); $self->createdArrays->offsetSet($self->semValue); }, 562 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; $self->createdArrays->offsetSet($self->semValue); }, 563 => static function ($self, $stackPos) { $self->semValue = Scalar\String_::fromString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]), $self->phpVersion->supportsUnicodeEscapes()); }, 564 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED; foreach ($self->semStack[$stackPos-(3-2)] as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '"', $self->phpVersion->supportsUnicodeEscapes()); } }; $self->semValue = new Scalar\InterpolatedString($self->semStack[$stackPos-(3-2)], $attrs); }, 565 => static function ($self, $stackPos) { $self->semValue = $self->parseLNumber($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]), $self->phpVersion->allowsInvalidOctals()); }, 566 => static function ($self, $stackPos) { $self->semValue = Scalar\Float_::fromString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 567 => null, 568 => null, 569 => null, 570 => static function ($self, $stackPos) { $self->semValue = $self->parseDocString($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)]), true); }, 571 => static function ($self, $stackPos) { $self->semValue = $self->parseDocString($self->semStack[$stackPos-(2-1)], '', $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(2-2)], $self->tokenEndStack[$stackPos-(2-2)]), true); }, 572 => static function ($self, $stackPos) { $self->semValue = $self->parseDocString($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)]), true); }, 573 => static function ($self, $stackPos) { $self->semValue = null; }, 574 => null, 575 => null, 576 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 577 => null, 578 => null, 579 => null, 580 => null, 581 => null, 582 => null, 583 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 584 => null, 585 => null, 586 => null, 587 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 588 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 589 => null, 590 => static function ($self, $stackPos) { $self->semValue = new Expr\MethodCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 591 => static function ($self, $stackPos) { $self->semValue = new Expr\NullsafeMethodCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 592 => static function ($self, $stackPos) { $self->semValue = null; }, 593 => null, 594 => null, 595 => null, 596 => static function ($self, $stackPos) { $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 597 => static function ($self, $stackPos) { $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 598 => null, 599 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 600 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 601 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable(new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])), $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, 602 => static function ($self, $stackPos) { $var = $self->semStack[$stackPos-(1-1)]->name; $self->semValue = \is_string($var) ? new Node\VarLikeIdentifier($var, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])) : $var; }, 603 => static function ($self, $stackPos) { $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 604 => null, 605 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 606 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 607 => static function ($self, $stackPos) { $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 608 => static function ($self, $stackPos) { $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 609 => static function ($self, $stackPos) { $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 610 => static function ($self, $stackPos) { $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 611 => null, 612 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 613 => null, 614 => null, 615 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 616 => null, 617 => static function ($self, $stackPos) { $self->semValue = new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, 618 => static function ($self, $stackPos) { $self->semValue = new Expr\List_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('kind', Expr\List_::KIND_LIST); $self->postprocessList($self->semValue); }, 619 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; $end = count($self->semValue)-1; if ($self->semValue[$end]->value instanceof Expr\Error) array_pop($self->semValue); }, 620 => null, 621 => static function ($self, $stackPos) { /* do nothing -- prevent default action of $$=$self->semStack[$1]. See $551. */ }, 622 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 623 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 624 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(1-1)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 625 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(2-2)], null, true, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 626 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(1-1)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 627 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(3-3)], $self->semStack[$stackPos-(3-1)], false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 628 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(4-4)], $self->semStack[$stackPos-(4-1)], true, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 629 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(3-3)], $self->semStack[$stackPos-(3-1)], false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 630 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(2-2)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]), true); }, 631 => static function ($self, $stackPos) { /* Create an Error node now to remember the position. We'll later either report an error, or convert this into a null element, depending on whether this is a creation or destructuring context. */ $attrs = $self->createEmptyElemAttributes($self->tokenPos); $self->semValue = new Node\ArrayItem(new Expr\Error($attrs), null, false, $attrs); }, 632 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 633 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 634 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 635 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)]); }, 636 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]); $attrs['rawValue'] = $self->semStack[$stackPos-(1-1)]; $self->semValue = new Node\InterpolatedStringPart($self->semStack[$stackPos-(1-1)], $attrs); }, 637 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 638 => null, 639 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 640 => static function ($self, $stackPos) { $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 641 => static function ($self, $stackPos) { $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 642 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 643 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 644 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(6-2)], $self->semStack[$stackPos-(6-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); }, 645 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 646 => static function ($self, $stackPos) { $self->semValue = new Scalar\String_($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 647 => static function ($self, $stackPos) { $self->semValue = $self->parseNumString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 648 => static function ($self, $stackPos) { $self->semValue = $self->parseNumString('-' . $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 649 => null, ]; } } ================================================ FILE: lib/PhpParser/Parser/Php8.php ================================================ '", "T_IS_GREATER_OR_EQUAL", "T_PIPE", "'.'", "T_SL", "T_SR", "'+'", "'-'", "'*'", "'/'", "'%'", "'!'", "T_INSTANCEOF", "'~'", "T_INC", "T_DEC", "T_INT_CAST", "T_DOUBLE_CAST", "T_STRING_CAST", "T_ARRAY_CAST", "T_OBJECT_CAST", "T_BOOL_CAST", "T_UNSET_CAST", "'@'", "T_POW", "'['", "T_NEW", "T_CLONE", "T_EXIT", "T_IF", "T_ELSEIF", "T_ELSE", "T_ENDIF", "T_LNUMBER", "T_DNUMBER", "T_STRING", "T_STRING_VARNAME", "T_VARIABLE", "T_NUM_STRING", "T_INLINE_HTML", "T_ENCAPSED_AND_WHITESPACE", "T_CONSTANT_ENCAPSED_STRING", "T_ECHO", "T_DO", "T_WHILE", "T_ENDWHILE", "T_FOR", "T_ENDFOR", "T_FOREACH", "T_ENDFOREACH", "T_DECLARE", "T_ENDDECLARE", "T_AS", "T_SWITCH", "T_MATCH", "T_ENDSWITCH", "T_CASE", "T_DEFAULT", "T_BREAK", "T_CONTINUE", "T_GOTO", "T_FUNCTION", "T_FN", "T_CONST", "T_RETURN", "T_TRY", "T_CATCH", "T_FINALLY", "T_USE", "T_INSTEADOF", "T_GLOBAL", "T_STATIC", "T_ABSTRACT", "T_FINAL", "T_PRIVATE", "T_PROTECTED", "T_PUBLIC", "T_READONLY", "T_PUBLIC_SET", "T_PROTECTED_SET", "T_PRIVATE_SET", "T_VAR", "T_UNSET", "T_ISSET", "T_EMPTY", "T_HALT_COMPILER", "T_CLASS", "T_TRAIT", "T_INTERFACE", "T_ENUM", "T_EXTENDS", "T_IMPLEMENTS", "T_OBJECT_OPERATOR", "T_NULLSAFE_OBJECT_OPERATOR", "T_LIST", "T_ARRAY", "T_CALLABLE", "T_CLASS_C", "T_TRAIT_C", "T_METHOD_C", "T_FUNC_C", "T_PROPERTY_C", "T_LINE", "T_FILE", "T_START_HEREDOC", "T_END_HEREDOC", "T_DOLLAR_OPEN_CURLY_BRACES", "T_CURLY_OPEN", "T_PAAMAYIM_NEKUDOTAYIM", "T_NAMESPACE", "T_NS_C", "T_DIR", "T_NS_SEPARATOR", "T_ELLIPSIS", "T_NAME_FULLY_QUALIFIED", "T_NAME_QUALIFIED", "T_NAME_RELATIVE", "T_ATTRIBUTE", "';'", "']'", "'('", "')'", "'{'", "'}'", "'`'", "'\"'", "'$'" ); protected array $tokenToSymbol = array( 0, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 58, 172, 174, 173, 57, 174, 174, 167, 168, 55, 53, 9, 54, 50, 56, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 32, 165, 45, 17, 47, 31, 70, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 72, 174, 166, 37, 174, 171, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 169, 36, 170, 60, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 33, 34, 35, 38, 39, 40, 41, 42, 43, 44, 46, 48, 49, 51, 52, 59, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164 ); protected array $action = array( 132, 133, 134, 582, 135, 136, 162, 779, 780, 781, 137, 41, 863,-32766, 970, 1404, -584, 974, 973, 1302, 0, 395, 396, 455, 246, 854,-32766,-32766,-32766,-32766, -32766, 440,-32766, 27,-32766, 773, 772,-32766,-32766,-32766, -32766, 508,-32766,-32766,-32766,-32766,-32766,-32766,-32766,-32766, 131,-32766,-32766,-32766,-32766, 437, 782, 859, 1148,-32766, 949,-32766,-32766,-32766,-32766,-32766,-32766, 972, 1385, 300, 271, 53, 398, 786, 787, 788, 789, 305, 865, 441, -341, 39, 254, -584, -584, -195, 843, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 819, 583, 820, 821, 822, 823, 811, 812, 353, 354, 814, 815, 800, 801, 802, 804, 805, 806, 368, 846, 847, 848, 849, 850, 584, 1062, -194, 856, 807, 808, 585, 586, 3, 831, 829, 830, 842, 826, 827, 4, 860, 587, 588, 825, 589, 590, 591, 592, 939, 593, 594, 5, 854, -32766,-32766,-32766, 828, 595, 596,-32766, 138, 764, 132, 133, 134, 582, 135, 136, 1098, 779, 780, 781, 137, 41,-32766,-32766,-32766,-32766,-32766,-32766, -275, 1302, 613, 153, 1071, 749, 990, 991,-32766,-32766,-32766, 992,-32766, 891,-32766, 892,-32766, 773, 772,-32766, 986, 1309, 397, 396,-32766,-32766,-32766, 858, 299, 630,-32766,-32766, 440, 502, 736,-32766,-32766, 437, 782,-32767,-32767,-32767,-32767, 106, 107, 108, 109, 951,-32766, 1021, 29, 734, 271, 53, 398, 786, 787, 788, 789, 144, 1071, 441, -341, 332, 38, 864, 862, -195, 843, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 819, 583, 820, 821, 822, 823, 811, 812, 353, 354, 814, 815, 800, 801, 802, 804, 805, 806, 368, 846, 847, 848, 849, 850, 584, 863, -194, 139, 807, 808, 585, 586, 323, 831, 829, 830, 842, 826, 827, 1370, 148, 587, 588, 825, 589, 590, 591, 592, 245, 593, 594, 395, 396,-32766, -32766,-32766, 828, 595, 596, -85, 138, 440, 132, 133, 134, 582, 135, 136, 1095, 779, 780, 781, 137, 41, -32766,-32766,-32766,-32766,-32766, 51, 578, 1302, 257,-32766, 636, 107, 108, 109,-32766,-32766,-32766, 503,-32766, 316, -32766,-32766,-32766, 773, 772,-32766, -383, 166, -383, 1022, -32766,-32766,-32766, 305, 79, 1133,-32766,-32766, 1414, 762, 332, 1415,-32766, 437, 782,-32766, 1071, 110, 111, 112, 113, 114, -85, 283,-32766, 477, 478, 479, 271, 53, 398, 786, 787, 788, 789, 115, 407, 441, 10,-32766, 299, 1341, 306, 307, 843, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 819, 583, 820, 821, 822, 823, 811, 812, 353, 354, 814, 815, 800, 801, 802, 804, 805, 806, 368, 846, 847, 848, 849, 850, 584, 320, 1068, -582, 807, 808, 585, 586, 1389, 831, 829, 830, 842, 826, 827, 329, 1388, 587, 588, 825, 589, 590, 591, 592, 86, 593, 594, 1071, 332,-32766,-32766, -32766, 828, 595, 596, 349, 151, -581, 132, 133, 134, 582, 135, 136, 1100, 779, 780, 781, 137, 41,-32766, 290,-32766,-32766,-32766,-32766,-32766,-32766,-32766,-32767,-32767, -32767,-32767,-32767,-32766,-32766,-32766, 891, 1175, 892, -582, -582, 754, 773, 772, 1159, 1160, 1161, 1155, 1154, 1153, 1162, 1156, 1157, 1158,-32766, -582,-32766,-32766,-32766,-32766, -32766,-32766,-32766, 782,-32766,-32766,-32766, -588, -78,-32766, -32766,-32766, 350, -581, -581,-32766,-32766, 271, 53, 398, 786, 787, 788, 789, 383,-32766, 441,-32766,-32766, -581, -32766, 773, 772, 843, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 819, 583, 820, 821, 822, 823, 811, 812, 353, 354, 814, 815, 800, 801, 802, 804, 805, 806, 368, 846, 847, 848, 849, 850, 584, -620, 1068, -620, 807, 808, 585, 586, 389, 831, 829, 830, 842, 826, 827, 441, 405, 587, 588, 825, 589, 590, 591, 592, 333, 593, 594, 1071, 87, 88, 89, 459, 828, 595, 596, 460, 151, 803, 774, 775, 776, 777, 778, 854, 779, 780, 781, 816, 817, 40, 461, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 462, 283, 1329, 1159, 1160, 1161, 1155, 1154, 1153, 1162, 1156, 1157, 1158, 115, 869, 488, 489, 782, 1304, 1303, 1305, 108, 109, 1132, 154,-32766, -32766, 1134, 679, 23, 156, 783, 784, 785, 786, 787, 788, 789, 698, 699, 852, 152, 423, -580, 393, 394, 157, 843, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 819, 841, 820, 821, 822, 823, 811, 812, 813, 840, 814, 815, 800, 801, 802, 804, 805, 806, 845, 846, 847, 848, 849, 850, 851, 1094, -578, 863, 807, 808, 809, 810, -58, 831, 829, 830, 842, 826, 827, 399, 400, 818, 824, 825, 832, 833, 835, 834, 294, 836, 837, 158, -580, -580, 160, 294, 828, 839, 838, 54, 55, 56, 57, 534, 58, 59, 36, -110, -580, -57, 60, 61, -110, 62, -110, 670, 671, 129, 130, 312, -587, 140, -110, -110, -110, -110, -110, -110, -110, -110, -110, -110, -110, -578, -578, 141, 147, 949, 161, 712, -87, 163, 164, 165, -84, 949, -78, -73, -72, -578, 63, 64, 143, -309, -71, 65, 332, 66, 251, 252, 67, 68, 69, 70, 71, 72, 73, 74, 739, 31, 276, 47, 457, 535, -357, 713, 740, 1335, 1336, 536, -70, 863, 1068, -69, -68, 1333, 45, 22, 537, 949, 538, -67, 539, -66, 540, 52, -65, 541, 542, 714, 715, -46, 48, 49, 463, 392, 391, 1071, 50, 543, -18, 145, 281, 1302, 381, 348, 291, 750, 1304, 1303, 1305, 1295, 939, 753, 290, 948, 545, 546, 547, 150, 939, 290, -305, 295, 288, 289, 292, 293, 549, 550, 338, 1321, 1322, 1323, 1324, 1326, 1318, 1319, 304, 1300, 296, 301, 302, 283, 1325, 1320, 773, 772, 1304, 1303, 1305, 305, 308, 309, 75, -154, -154, -154, 327, 328, 332, 966, 854, 1070, 939, 149, 115, 1416, 388, 680, -154, 708, -154, 725, -154, 13, -154, 668, 723, 313, 31, 277, 1304, 1303, 1305, 863, 390,-32766, 600, 1166, 987, 951, 863, 310, 701, 734, 1333, 990, 991, 951,-32766, 686, 544, 734, 949, 685, 606, 1340, 485, 513, 925, 986, -110, -110, -110, 35, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 702, 949, 634, 1295, 773, 772, 741, -579, 305, -614, 1334, 0, 0, 0, 951, 311, 949, 0, 734, -154, 549, 550, 319, 1321, 1322, 1323, 1324, 1326, 1318, 1319, 1209, 1211, 744, 0, 1342, 0, 1325, 1320, -544, -534, 0, -578,-32766, -4, 949, 11, 77, 751, 1302, 30, 387, 328, 332, 862, 43,-32766,-32766,-32766, -613, -32766, 939,-32766, 968,-32766, 44, 759,-32766, 1330, 773, 772, 760,-32766,-32766,-32766, -579, -579, 882,-32766,-32766, 930, 1031, 1008, 1015,-32766, 437, 1005, 939, 1016, 928, 1003, -579, 1137, 1140, 1141, 1138,-32766, 1177, 1139, 1145, 37, 874, 939, -586, 1357, 1374, 1407,-32766, 673, -578, -578, -612, -588, 1302, -587, -586, -585, 31, 276, -528, -32766,-32766,-32766, 1,-32766, -578,-32766, 78,-32766, 863, 939,-32766, 32, 1333, -278, 33,-32766,-32766,-32766, 42, 1007, 46,-32766,-32766, 734, 76, 80, 81,-32766, 437, 82, 83, 390, 84, 453, 31, 277, 85, 146, 303, -32766, 155, 159, 990, 991, 249, 951, 863, 544, 1295, 734, 1333, 334, 369, 370, 371, 548, 986, -110, -110, -110, 951, 372, 326, 373, 734, 374, 550, 375, 1321, 1322, 1323, 1324, 1326, 1318, 1319, 376, 377, 422, 378, 21, -50, 1325, 1320, 379, 382, 454, 1295, 577, 951, 380, 384, 77, 734, -4, -276, -275, 328, 332, 15, 16, 17, 18, 20, 363, 550, 421, 1321, 1322, 1323, 1324, 1326, 1318, 1319, 142, 504, 505, 512, 515, 516, 1325, 1320, 949, 517, 518,-32766, 522, 523, 524, 531, 77, 1302, 611, 718, 1101, 328, 332, 1097,-32766,-32766, -32766, 1250,-32766, 1331,-32766, 949,-32766, 1099, 1096,-32766, 1077, 1290, 1309, 1073,-32766,-32766,-32766, -280,-32766, -102, -32766,-32766, 14, 19, 1302, 24,-32766, 437, 323, 420, 625,-32766,-32766,-32766, 631,-32766, 659,-32766,-32766,-32766, 724, 1254,-32766, -16, 1308, 1251, 1386,-32766,-32766,-32766, 735,-32766, 738,-32766,-32766, 742, 743, 1302, 745,-32766, 437, 746, 747, 748,-32766,-32766,-32766, 939,-32766, 300, -32766,-32766,-32766, 752, 1309,-32766, 764, 737, 332, 765, -32766,-32766,-32766, -253, -253, -253,-32766,-32766, 426, 390, 939, 756,-32766, 437, 926, 863, 1411, 1413, 885, 884, 990, 991, 980, 1023,-32766, 544, -252, -252, -252, 1412, 979, 977, 390, 925, 986, -110, -110, -110, 978, 981, 1283, 959, 969, 990, 991, 957, 1176, 1172, 544, 1126, -110, -110, 1013, 1014, 657, -110, 925, 986, -110, -110, -110, 1410, 2, 1368, -110, 1268, 951, 1383, 0, 0, 734, -253, 0,-32766, 0, 0,-32766, 863, 1059, 1054, 1053, 1052, 1058, 1055, 1056, 1057, 0, 0, 0, 951, 0, 0, 0, 734, -252, 305, 0, 0, 79, 0, 0, 1071, 0, 0, 332, 0, 0, 0, 0, 0, 0, 0, -110, -110, 0, 0, 0, -110, 0, 0, 0, 0, 0, 0, 0, 299, -110, 0, 0, 0, 0, 0, 0, 0, 0,-32766, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305, 0, 0, 79, 0, 0, 0, 0, 0, 332 ); protected array $actionCheck = array( 3, 4, 5, 6, 7, 8, 17, 10, 11, 12, 13, 14, 84, 76, 1, 87, 72, 74, 75, 82, 0, 108, 109, 110, 15, 82, 89, 90, 91, 10, 93, 118, 95, 103, 97, 38, 39, 100, 10, 11, 12, 104, 105, 106, 107, 10, 11, 12, 111, 112, 15, 10, 11, 12, 117, 118, 59, 82, 128, 31, 1, 33, 34, 35, 36, 37, 129, 124, 1, 31, 73, 74, 75, 76, 77, 78, 79, 164, 1, 82, 9, 153, 154, 139, 140, 9, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 1, 9, 82, 128, 129, 130, 131, 9, 133, 134, 135, 136, 137, 138, 9, 162, 141, 142, 143, 144, 145, 146, 147, 86, 149, 150, 9, 82, 10, 11, 12, 156, 157, 158, 118, 160, 169, 3, 4, 5, 6, 7, 8, 168, 10, 11, 12, 13, 14, 31, 76, 33, 34, 35, 36, 168, 82, 83, 15, 143, 169, 119, 120, 89, 90, 91, 124, 93, 108, 95, 110, 97, 38, 39, 100, 133, 1, 108, 109, 105, 106, 107, 162, 167, 1, 111, 112, 118, 32, 169, 118, 117, 118, 59, 45, 46, 47, 48, 49, 50, 51, 52, 165, 129, 32, 9, 169, 73, 74, 75, 76, 77, 78, 79, 169, 143, 82, 168, 173, 9, 165, 161, 168, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 84, 168, 9, 128, 129, 130, 131, 168, 133, 134, 135, 136, 137, 138, 1, 9, 141, 142, 143, 144, 145, 146, 147, 99, 149, 150, 108, 109, 10, 11, 12, 156, 157, 158, 32, 160, 118, 3, 4, 5, 6, 7, 8, 168, 10, 11, 12, 13, 14, 31, 76, 33, 34, 35, 72, 87, 82, 9, 142, 54, 50, 51, 52, 89, 90, 91, 169, 93, 9, 95, 118, 97, 38, 39, 100, 108, 15, 110, 165, 105, 106, 107, 164, 167, 165, 111, 112, 82, 169, 173, 85, 117, 118, 59, 118, 143, 53, 54, 55, 56, 57, 99, 59, 129, 134, 135, 136, 73, 74, 75, 76, 77, 78, 79, 71, 108, 82, 110, 142, 167, 152, 139, 140, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 9, 118, 72, 128, 129, 130, 131, 1, 133, 134, 135, 136, 137, 138, 9, 9, 141, 142, 143, 144, 145, 146, 147, 169, 149, 150, 143, 173, 10, 11, 12, 156, 157, 158, 9, 160, 72, 3, 4, 5, 6, 7, 8, 168, 10, 11, 12, 13, 14, 31, 167, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 10, 11, 12, 108, 165, 110, 139, 140, 169, 38, 39, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 31, 155, 33, 34, 35, 36, 37, 38, 39, 59, 10, 11, 12, 167, 17, 10, 11, 12, 9, 139, 140, 10, 11, 73, 74, 75, 76, 77, 78, 79, 9, 31, 82, 33, 34, 155, 31, 38, 39, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 166, 118, 168, 128, 129, 130, 131, 9, 133, 134, 135, 136, 137, 138, 82, 9, 141, 142, 143, 144, 145, 146, 147, 72, 149, 150, 143, 10, 11, 12, 9, 156, 157, 158, 9, 160, 3, 4, 5, 6, 7, 8, 82, 10, 11, 12, 13, 14, 31, 9, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 9, 59, 1, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 71, 9, 139, 140, 59, 161, 162, 163, 51, 52, 1, 15, 53, 54, 170, 77, 78, 15, 73, 74, 75, 76, 77, 78, 79, 77, 78, 82, 103, 104, 72, 108, 109, 15, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 1, 72, 84, 128, 129, 130, 131, 17, 133, 134, 135, 136, 137, 138, 108, 109, 141, 142, 143, 144, 145, 146, 147, 31, 149, 150, 15, 139, 140, 15, 31, 156, 157, 158, 2, 3, 4, 5, 6, 7, 8, 15, 103, 155, 17, 13, 14, 108, 16, 110, 113, 114, 17, 17, 115, 167, 17, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 139, 140, 17, 17, 1, 17, 82, 32, 17, 17, 17, 32, 1, 32, 32, 32, 155, 53, 54, 169, 36, 32, 58, 173, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 32, 72, 73, 74, 75, 76, 170, 118, 32, 80, 81, 82, 32, 84, 118, 32, 32, 88, 89, 90, 91, 1, 93, 32, 95, 32, 97, 72, 32, 100, 101, 142, 143, 32, 105, 106, 107, 108, 109, 143, 111, 112, 32, 32, 32, 82, 117, 118, 32, 32, 161, 162, 163, 124, 86, 32, 167, 32, 129, 130, 131, 32, 86, 167, 36, 38, 36, 36, 36, 36, 141, 142, 36, 144, 145, 146, 147, 148, 149, 150, 151, 118, 38, 38, 38, 59, 157, 158, 38, 39, 161, 162, 163, 164, 139, 140, 167, 77, 78, 79, 171, 172, 173, 39, 82, 142, 86, 72, 71, 85, 155, 92, 92, 79, 94, 94, 96, 99, 98, 115, 82, 116, 72, 73, 161, 162, 163, 84, 108, 87, 91, 84, 133, 165, 84, 137, 96, 169, 88, 119, 120, 165, 142, 102, 124, 169, 1, 98, 159, 152, 99, 99, 132, 133, 134, 135, 136, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 102, 1, 159, 124, 38, 39, 32, 72, 164, 167, 172, -1, -1, -1, 165, 138, 1, -1, 169, 170, 141, 142, 137, 144, 145, 146, 147, 148, 149, 150, 61, 62, 32, -1, 152, -1, 157, 158, 155, 155, -1, 72, 76, 0, 1, 155, 167, 32, 82, 155, 155, 172, 173, 161, 165, 89, 90, 91, 167, 93, 86, 95, 160, 97, 165, 165, 100, 166, 38, 39, 165, 105, 106, 107, 139, 140, 165, 111, 112, 165, 165, 165, 165, 117, 118, 165, 86, 165, 165, 165, 155, 165, 165, 165, 165, 129, 165, 165, 165, 169, 166, 86, 167, 166, 166, 166, 76, 166, 139, 140, 167, 167, 82, 167, 167, 167, 72, 73, 167, 89, 90, 91, 167, 93, 155, 95, 160, 97, 84, 86, 100, 167, 88, 168, 167, 105, 106, 107, 167, 165, 167, 111, 112, 169, 167, 167, 167, 117, 118, 167, 167, 108, 167, 110, 72, 73, 167, 167, 115, 129, 167, 167, 119, 120, 167, 165, 84, 124, 124, 169, 88, 167, 167, 167, 167, 132, 133, 134, 135, 136, 165, 167, 169, 167, 169, 167, 142, 167, 144, 145, 146, 147, 148, 149, 150, 167, 167, 170, 167, 156, 32, 157, 158, 167, 167, 167, 124, 167, 165, 167, 169, 167, 169, 170, 168, 168, 172, 173, 168, 168, 168, 168, 168, 168, 142, 168, 144, 145, 146, 147, 148, 149, 150, 32, 168, 168, 168, 168, 168, 157, 158, 1, 168, 168, 76, 168, 168, 168, 168, 167, 82, 168, 168, 168, 172, 173, 168, 89, 90, 91, 168, 93, 168, 95, 1, 97, 168, 168, 100, 168, 168, 1, 168, 105, 106, 107, 168, 76, 168, 111, 112, 168, 168, 82, 168, 117, 118, 168, 168, 168, 89, 90, 91, 168, 93, 168, 95, 129, 97, 168, 168, 100, 32, 168, 168, 168, 105, 106, 107, 169, 76, 169, 111, 112, 169, 169, 82, 169, 117, 118, 169, 169, 169, 89, 90, 91, 86, 93, 31, 95, 129, 97, 169, 1, 100, 169, 169, 173, 169, 105, 106, 107, 102, 103, 104, 111, 112, 170, 108, 86, 170, 117, 118, 170, 84, 170, 170, 170, 170, 119, 120, 170, 170, 129, 124, 102, 103, 104, 170, 170, 170, 108, 132, 133, 134, 135, 136, 170, 170, 170, 170, 170, 119, 120, 170, 170, 170, 124, 170, 119, 120, 170, 170, 170, 124, 132, 133, 134, 135, 136, 170, 167, 170, 133, 171, 165, 170, -1, -1, 169, 170, -1, 142, -1, -1, 118, 84, 120, 121, 122, 123, 124, 125, 126, 127, -1, -1, -1, 165, -1, -1, -1, 169, 170, 164, -1, -1, 167, -1, -1, 143, -1, -1, 173, -1, -1, -1, -1, -1, -1, -1, 119, 120, -1, -1, -1, 124, -1, -1, -1, -1, -1, -1, -1, 167, 133, -1, -1, -1, -1, -1, -1, -1, -1, 142, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 164, -1, -1, 167, -1, -1, -1, -1, -1, 173 ); protected array $actionBase = array( 0, 156, -3, 315, 474, 474, 880, 1074, 1271, 1294, 749, 675, 531, 559, 836, 1031, 1031, 1046, 1031, 828, 1005, 42, 59, 59, 59, 963, 898, 632, 632, 898, 632, 997, 997, 997, 997, 1061, 1061, -63, -63, 96, 1232, 1199, 255, 255, 255, 255, 255, 1265, 255, 255, 255, 255, 255, 1265, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 77, 194, 120, 205, 1197, 783, 1150, 1163, 1152, 1166, 1145, 1144, 1151, 1156, 1167, 1261, 1263, 889, 1254, 1267, 1158, 972, 1147, 1162, 962, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 19, 35, 535, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 529, 529, 529, 910, 910, 524, 299, 1113, 1075, 1113, 1113, 1113, 1113, 1113, 1113, 1113, 1113, 140, 28, 1000, 493, 493, 458, 458, 458, 458, 458, 696, 1328, 1301, 171, 171, 171, 171, 1363, 1363, -70, 523, 248, 756, 291, 197, -87, 644, 38, 199, 323, 323, 482, 482, 233, 233, 482, 482, 482, 324, 324, 94, 94, 94, 94, 82, 249, 860, 67, 67, 67, 67, 860, 860, 860, 860, 913, 869, 860, 1036, 1049, 860, 860, 370, 645, 966, 646, 646, 398, -72, -72, 398, 64, -72, 294, 286, 257, 859, 91, 433, 257, 1073, 404, 686, 686, 815, 686, 686, 686, 923, 610, 923, 1141, 902, 902, 861, 807, 964, 1198, 1168, 901, 1252, 929, 1253, 1200, 342, 251, -56, 263, 550, 806, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1195, 523, 1141, -25, 1247, 1249, 1195, 1195, 1195, 523, 523, 523, 523, 523, 523, 523, 523, 870, 523, 523, 694, -25, 625, 635, -25, 896, 523, 915, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 178, 77, 77, 194, 13, 13, 77, 200, 121, 13, 13, 13, -11, 13, 77, 77, 77, 610, 886, 849, 663, 283, 874, 114, 886, 886, 886, 71, 9, 76, 809, 888, 288, 882, 882, 882, 907, 986, 986, 882, 903, 882, 907, 882, 882, 986, 986, 875, 986, 274, 620, 465, 597, 624, 986, 340, 882, 882, 882, 882, 916, 986, 127, 139, 639, 882, 329, 287, 882, 882, 916, 858, 876, 908, 986, 986, 986, 916, 545, 908, 908, 908, 931, 936, 864, 872, 445, 431, 679, 232, 924, 872, 872, 882, 605, 864, 872, 864, 872, 933, 872, 872, 872, 864, 872, 903, 533, 872, 813, 665, 218, 872, 882, 20, 1008, 1009, 800, 1010, 1002, 1013, 1069, 1014, 1016, 1171, 982, 1028, 1004, 1020, 1071, 998, 995, 885, 792, 793, 921, 914, 979, 897, 897, 897, 975, 977, 897, 897, 897, 897, 897, 897, 897, 897, 792, 932, 926, 899, 1037, 796, 810, 1114, 857, 1214, 1264, 1036, 1008, 1016, 804, 1004, 1020, 998, 995, 856, 853, 844, 851, 843, 840, 808, 814, 871, 1116, 1119, 1021, 920, 811, 1085, 1038, 1211, 1044, 1045, 1047, 1088, 1123, 942, 1125, 1216, 895, 1217, 1218, 965, 1051, 1173, 897, 974, 873, 968, 1049, 978, 792, 969, 1129, 1130, 1081, 961, 1097, 1098, 1072, 911, 884, 970, 1219, 1059, 1060, 1062, 1176, 1177, 930, 1082, 996, 1099, 912, 1058, 1100, 1101, 1105, 1106, 1179, 1222, 1182, 922, 1183, 945, 879, 1077, 909, 1223, 165, 892, 893, 906, 1068, 683, 1035, 1184, 1208, 1229, 1108, 1109, 1110, 1230, 1231, 1024, 946, 1083, 900, 1084, 1078, 947, 948, 689, 905, 1132, 890, 891, 904, 705, 768, 1238, 1239, 1240, 1025, 877, 894, 951, 953, 1133, 887, 1135, 1241, 771, 954, 1242, 1115, 816, 817, 521, 784, 747, 818, 881, 1194, 925, 865, 878, 1067, 817, 883, 955, 1245, 957, 958, 959, 1111, 960, 1086, 1246, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 789, 789, 789, 789, 789, 789, 789, 789, 789, 632, 632, 632, 632, 789, 789, 789, 789, 789, 789, 789, 632, 789, 789, 789, 632, 632, 0, 0, 632, 0, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 823, 823, 616, 616, 823, 823, 823, 823, 823, 823, 823, 823, 823, 823, 616, 616, 0, 616, 616, 616, 616, 616, 616, 616, 875, 823, 823, 324, 324, 324, 324, 823, 823, 396, 396, 396, 823, 324, 823, 64, 324, 823, 64, 823, 823, 823, 823, 823, 823, 823, 823, 823, 0, 0, 823, 823, 823, 823, -25, -72, 823, 903, 903, 903, 903, 823, 823, 823, 823, -72, -72, 823, -57, -57, 823, 823, 0, 0, 0, 324, 324, -25, 0, 0, -25, 0, 0, 903, 903, 823, 64, 875, 446, 823, 342, 0, 0, 0, 0, 0, 0, 0, -25, 903, -25, 523, -72, -72, 523, 523, 13, 77, 446, 612, 612, 612, 612, 77, 0, 0, 0, 0, 0, 610, 875, 875, 875, 875, 875, 875, 875, 875, 875, 875, 875, 875, 903, 0, 875, 0, 875, 875, 903, 903, 903, 0, 0, 0, 0, 0, 0, 0, 0, 986, 0, 0, 0, 0, 0, 0, 0, 903, 0, 986, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 903, 0, 0, 0, 0, 0, 0, 0, 0, 0, 897, 911, 0, 0, 911, 0, 897, 897, 897, 0, 0, 0, 905, 887 ); protected array $actionDefault = array( 3,32767,32767,32767, 102, 102,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767, 100, 32767, 632, 632, 632, 632,32767,32767, 257, 102,32767, 32767, 503, 417, 417, 417,32767,32767,32767, 576, 576, 576, 576, 576, 17,32767,32767,32767,32767,32767,32767, 32767, 503,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767, 36, 7, 8, 10, 11, 49, 338, 100, 32767,32767,32767,32767,32767,32767,32767,32767, 102,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767, 404, 625,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767, 497, 507, 485, 486, 488, 489, 416, 577, 631, 344, 628, 342, 415, 146, 354, 343, 245, 261, 508, 262, 509, 512, 513, 218, 401, 150, 151, 448, 504, 450, 502, 506, 449, 422, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 420, 421, 505, 482, 481, 480,32767,32767, 446, 447,32767, 32767,32767,32767,32767,32767,32767,32767, 102,32767, 451, 454, 419, 452, 453, 470, 471, 468, 469, 472,32767, 323,32767, 473, 474, 475, 476,32767,32767, 382, 196, 380,32767, 477,32767, 111, 455, 323, 111,32767,32767, 32767,32767,32767,32767,32767,32767,32767, 461, 462,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767, 102,32767,32767,32767, 100, 520, 570, 479, 456, 457,32767, 545,32767, 102, 32767, 547,32767,32767,32767,32767,32767,32767,32767,32767, 572, 443, 445, 540, 626, 423, 629,32767, 533, 100, 196,32767, 546, 196, 196,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767, 571,32767, 639, 533, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,32767, 196, 110,32767, 110, 110,32767,32767, 100, 196, 196, 196, 196, 196, 196, 196, 196, 548, 196, 196, 191,32767, 271, 273, 102, 594, 196, 550,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767, 404,32767,32767,32767,32767, 533, 466, 139, 32767, 535, 139, 578, 458, 459, 460, 578, 578, 578, 319, 296,32767,32767,32767,32767,32767, 548, 548, 100, 100, 100, 100,32767,32767,32767,32767, 111, 519, 99, 99, 99, 99, 99, 103, 101,32767,32767,32767,32767, 226,32767, 101, 101, 99,32767, 101, 101,32767,32767, 226, 228, 215, 230,32767, 598, 599, 226, 101, 230, 230, 230, 250, 250, 522, 325, 101, 99, 101, 101, 198, 325, 325,32767, 101, 522, 325, 522, 325, 200, 325, 325, 325, 522, 325,32767, 101, 325, 217, 99, 99, 325,32767,32767,32767,32767, 535,32767,32767,32767, 32767,32767,32767,32767, 225,32767,32767,32767,32767,32767, 32767,32767,32767, 565,32767, 583, 596, 464, 465, 467, 582, 580, 490, 491, 492, 493, 494, 495, 496, 499, 627,32767, 539,32767,32767,32767, 353,32767, 637,32767, 32767,32767, 9, 74, 528, 42, 43, 51, 57, 554, 555, 556, 557, 551, 552, 558, 553,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767, 638,32767, 578,32767,32767,32767,32767, 463, 560, 604,32767,32767, 579, 630,32767,32767,32767, 32767,32767,32767,32767,32767, 139,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767, 565,32767, 137,32767, 32767,32767,32767,32767,32767,32767,32767, 561,32767,32767, 32767, 578,32767,32767,32767,32767, 321, 318,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767, 578,32767,32767,32767,32767,32767, 298,32767, 315,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767, 400, 535, 301, 303, 304,32767,32767,32767,32767, 376,32767,32767,32767,32767,32767,32767,32767,32767,32767, 32767,32767,32767,32767, 153, 153, 3, 3, 356, 153, 153, 153, 356, 356, 153, 356, 356, 356, 153, 153, 153, 153, 153, 153, 153, 283, 186, 265, 268, 250, 250, 153, 368, 153, 402, 402, 411 ); protected array $goto = array( 201, 169, 201, 201, 201, 1069, 598, 719, 448, 684, 644, 681, 443, 345, 341, 342, 344, 615, 447, 346, 449, 661, 481, 728, 570, 570, 570, 570, 1245, 626, 172, 172, 172, 172, 225, 202, 198, 198, 182, 184, 220, 198, 198, 198, 198, 198, 1195, 199, 199, 199, 199, 199, 1195, 192, 193, 194, 195, 196, 197, 222, 220, 223, 557, 558, 438, 559, 562, 563, 564, 565, 566, 567, 568, 569, 173, 174, 175, 200, 176, 177, 178, 170, 179, 180, 181, 183, 219, 221, 224, 242, 247, 248, 259, 260, 262, 263, 264, 265, 266, 267, 268, 272, 273, 274, 275, 282, 285, 297, 298, 324, 325, 444, 445, 446, 620, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 193, 194, 195, 196, 197, 222, 203, 204, 205, 206, 243, 185, 186, 207, 187, 208, 204, 188, 244, 203, 168, 209, 210, 189, 211, 212, 213, 190, 214, 215, 171, 216, 217, 218, 191, 287, 284, 287, 287, 883, 255, 255, 255, 255, 255, 1125, 605, 487, 487, 622, 758, 660, 662, 1103, 359, 682, 487, 1075, 1074, 706, 709, 1041, 717, 726, 1037, 733, 922, 879, 922, 922, 253, 253, 253, 253, 250, 256, 646, 646, 1078, 1079, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 880, 351, 938, 933, 934, 947, 889, 935, 886, 936, 937, 887, 890, 476, 941, 894, 476, 1044, 1044, 893, 364, 364, 364, 364, 352, 351, 532, 1131, 1127, 1128, 1351, 1351, 331, 315, 1351, 1351, 1351, 1351, 1351, 1351, 1351, 1351, 1351, 1351, 1069, 1301, 1072, 1072, 704, 983, 1301, 1301, 1064, 1080, 1081, 1069, 942, 1301, 943, 458, 1069, 881, 1069, 1069, 1069, 1069, 1069, 1069, 1069, 1069, 1069, 897, 855, 1069, 1069, 1069, 1069, 677, 678, 1301, 695, 696, 697, 1006, 1301, 1301, 1301, 1301, 450, 909, 1301, 436, 896, 1301, 1301, 1382, 1382, 1382, 1382, 915, 581, 574, 499, 612, 450, 367, 971, 971, 955, 501, 1076, 1076, 956, 1400, 1400, 367, 367, 688, 1087, 1083, 1084, 572, 411, 414, 623, 627, 572, 572, 367, 367, 1400, 357, 367, 572, 1417, 1377, 1378, 317, 574, 581, 607, 608, 318, 618, 624, 1390, 640, 641, 1027, 576, 1403, 1403, 367, 367, 28, 474, 520, 442, 521, 635, 1000, 1000, 1000, 1000, 527, 409, 474, 1348, 1348, 994, 1001, 1348, 1348, 1348, 1348, 1348, 1348, 1348, 1348, 1348, 1348, 633, 647, 650, 651, 652, 653, 674, 675, 676, 730, 732, 561, 561, 258, 258, 561, 561, 561, 561, 561, 561, 561, 561, 561, 561, 610, 1362, 467, 683, 467, 876, 616, 638, 876, 467, 467, 1191, 861, 1373, 360, 361, 1093, 456, 1373, 1373, 560, 560, 705, 432, 560, 1373, 560, 560, 560, 560, 560, 560, 560, 560, 1277, 975, 575, 602, 575, 1278, 1281, 976, 575, 1282, 602, 689, 412, 480, 1384, 1384, 1384, 1384, 347, 873, 716, 576, 861, 876, 861, 490, 619, 491, 492, 639, 8, 857, 9, 902, 907, 989, 716, 1408, 1409, 716, 1369, 418, 1296, 278, 899, 330, 1174, 424, 425, 1292, 330, 330, 693, 1049, 694, 1114, 429, 430, 431, 761, 707, 1060, 905, 433, 1102, 1104, 1107, 355, 467, 467, 467, 467, 467, 467, 467, 467, 467, 467, 467, 467, 419, 339, 467, 911, 467, 467, 1294, 628, 629, 1116, 497, 960, 1181, 621, 1144, 1371, 1371, 1116, 1118, 1297, 1298, 1011, 1284, 1046, 1151, 1179, 1152, 731, 871, 528, 722, 901, 1142, 687, 1025, 1284, 496, 1375, 1376, 895, 910, 898, 1113, 1117, 998, 427, 727, 1165, 1299, 1359, 1360, 1291, 1030, 386, 1009, 1002, 0, 757, 0, 0, 573, 1039, 1034, 654, 656, 658, 0, 0, 0, 0, 0, 0, 0, 0, 876, 0, 0, 999, 0, 766, 766, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1163, 914 ); protected array $gotoCheck = array( 42, 42, 42, 42, 42, 73, 127, 73, 66, 66, 56, 56, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 159, 9, 107, 107, 107, 107, 159, 107, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 23, 23, 23, 23, 15, 5, 5, 5, 5, 5, 15, 48, 157, 157, 134, 48, 48, 48, 131, 97, 48, 157, 119, 119, 48, 48, 48, 48, 48, 48, 48, 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, 108, 108, 120, 120, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 26, 177, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 83, 15, 15, 83, 107, 107, 15, 24, 24, 24, 24, 177, 177, 76, 15, 15, 15, 179, 179, 178, 178, 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, 73, 73, 89, 89, 89, 89, 73, 73, 89, 89, 89, 73, 65, 73, 65, 83, 73, 27, 73, 73, 73, 73, 73, 73, 73, 73, 73, 35, 6, 73, 73, 73, 73, 86, 86, 73, 86, 86, 86, 49, 73, 73, 73, 73, 118, 35, 73, 43, 35, 73, 73, 9, 9, 9, 9, 45, 76, 76, 84, 181, 118, 14, 9, 9, 73, 84, 118, 118, 73, 191, 191, 14, 14, 118, 118, 118, 118, 19, 59, 59, 59, 59, 19, 19, 14, 14, 191, 188, 14, 19, 14, 187, 187, 76, 76, 76, 76, 76, 76, 76, 76, 190, 76, 76, 103, 14, 191, 191, 14, 14, 76, 19, 163, 13, 163, 13, 19, 19, 19, 19, 163, 62, 19, 180, 180, 19, 19, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 182, 182, 5, 5, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 104, 14, 23, 64, 23, 22, 2, 2, 22, 23, 23, 158, 12, 134, 97, 97, 115, 113, 134, 134, 165, 165, 117, 14, 165, 134, 165, 165, 165, 165, 165, 165, 165, 165, 79, 79, 9, 9, 9, 79, 79, 79, 9, 79, 9, 121, 9, 9, 134, 134, 134, 134, 29, 18, 7, 14, 12, 22, 12, 9, 9, 9, 9, 80, 46, 7, 46, 39, 9, 92, 7, 9, 9, 7, 134, 28, 20, 24, 37, 24, 156, 82, 82, 169, 24, 24, 82, 110, 82, 133, 82, 82, 82, 99, 82, 114, 9, 82, 130, 130, 130, 82, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 31, 9, 23, 41, 23, 23, 14, 17, 17, 134, 160, 17, 17, 8, 8, 134, 134, 134, 136, 20, 20, 96, 20, 17, 149, 149, 149, 8, 20, 8, 8, 17, 8, 17, 17, 20, 185, 185, 185, 17, 16, 16, 16, 16, 93, 93, 93, 152, 20, 20, 20, 17, 50, 141, 16, 50, -1, 50, -1, -1, 50, 50, 50, 85, 85, 85, -1, -1, -1, -1, -1, -1, -1, -1, 22, -1, -1, 16, -1, 24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 16, 16 ); protected array $gotoBase = array( 0, 0, -303, 0, 0, 170, 280, 471, 543, 10, 0, 0, 136, 31, 22, -186, 111, 66, 164, 71, 95, 0, 148, 160, 235, 191, 214, 275, 155, 176, 0, 86, 0, 0, 0, -92, 0, 156, 0, 165, 0, 85, -1, 286, 0, 291, -270, 0, -558, 284, 579, 0, 0, 0, 0, 0, -33, 0, 0, 294, 0, 0, 341, 0, 184, 261, -237, 0, 0, 0, 0, 0, 0, -5, 0, 0, -32, 0, 0, 37, 172, 32, -3, -50, -167, 105, -444, 0, 0, -21, 0, 0, 161, 274, 0, 0, 101, -318, 0, 97, 0, 0, 0, 331, 381, 0, 0, -7, -38, 0, 131, 0, 0, 158, 90, 162, 0, 159, 39, -100, -83, 173, 0, 0, 0, 0, 0, 4, 0, 0, 522, 182, 0, 127, 169, 0, 99, 0, 0, 0, 0, -171, 0, 0, 0, 0, 0, 0, 0, 287, 0, 0, 126, 0, 0, 0, 144, 141, 188, -255, 93, 0, 0, -138, 0, 202, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, -82, -74, 6, 143, 292, 168, 0, 0, 270, 0, -31, 319, 0, 332, 20, 0, 0 ); protected array $gotoDefault = array( -32768, 533, 768, 7, 769, 964, 844, 853, 597, 551, 729, 356, 648, 439, 1367, 940, 1180, 617, 872, 1310, 1316, 475, 875, 336, 755, 952, 923, 924, 415, 402, 888, 413, 672, 649, 514, 908, 471, 900, 506, 903, 470, 912, 167, 435, 530, 916, 6, 919, 579, 950, 1004, 403, 927, 404, 700, 929, 601, 931, 932, 410, 416, 417, 1185, 609, 645, 944, 261, 603, 945, 401, 946, 954, 406, 408, 710, 486, 525, 519, 428, 1146, 604, 632, 669, 464, 493, 643, 655, 642, 500, 451, 434, 335, 988, 996, 507, 484, 1010, 358, 1018, 763, 1193, 663, 509, 1026, 664, 1033, 1036, 552, 553, 498, 1048, 270, 1051, 510, 1061, 26, 690, 1066, 1067, 691, 665, 1089, 666, 692, 667, 1091, 483, 599, 1194, 482, 1106, 1112, 472, 1115, 1356, 473, 1119, 269, 1122, 286, 362, 385, 452, 1129, 1130, 12, 1136, 720, 721, 25, 280, 529, 1164, 711, 1170, 279, 1173, 469, 1192, 468, 1265, 1267, 580, 511, 1285, 321, 1288, 703, 526, 1293, 465, 1358, 466, 554, 494, 343, 555, 1401, 314, 365, 340, 571, 322, 366, 556, 495, 1364, 1372, 337, 34, 1391, 1402, 614, 637 ); protected array $ruleToNonTerminal = array( 0, 1, 3, 3, 2, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 9, 10, 11, 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 16, 17, 17, 18, 18, 21, 21, 22, 23, 23, 24, 24, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 29, 29, 30, 30, 32, 34, 34, 28, 36, 36, 33, 38, 38, 35, 35, 37, 37, 39, 39, 31, 40, 40, 41, 43, 44, 44, 45, 45, 46, 46, 48, 47, 47, 47, 47, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 25, 25, 50, 69, 69, 72, 72, 71, 70, 70, 63, 75, 75, 76, 76, 77, 77, 78, 78, 79, 79, 80, 80, 80, 80, 26, 26, 27, 27, 27, 27, 27, 88, 88, 90, 90, 83, 83, 91, 91, 92, 92, 92, 84, 84, 87, 87, 85, 85, 93, 94, 94, 57, 57, 65, 65, 68, 68, 68, 67, 95, 95, 96, 58, 58, 58, 58, 97, 97, 98, 98, 99, 99, 100, 101, 101, 102, 102, 103, 103, 55, 55, 51, 51, 105, 53, 53, 106, 52, 52, 54, 54, 64, 64, 64, 64, 81, 81, 109, 109, 111, 111, 112, 112, 112, 112, 112, 112, 112, 112, 110, 110, 110, 115, 115, 115, 115, 89, 89, 118, 118, 118, 119, 119, 116, 116, 120, 120, 122, 122, 123, 123, 117, 124, 124, 121, 125, 125, 125, 125, 113, 113, 82, 82, 82, 20, 20, 20, 128, 128, 128, 128, 129, 129, 129, 127, 126, 126, 131, 131, 131, 130, 130, 60, 132, 132, 133, 61, 135, 135, 136, 136, 137, 137, 86, 138, 138, 138, 138, 138, 138, 138, 138, 144, 144, 145, 145, 146, 146, 146, 146, 146, 147, 148, 148, 143, 143, 139, 139, 142, 142, 150, 150, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 140, 151, 151, 153, 152, 152, 141, 141, 114, 114, 154, 154, 156, 156, 156, 155, 155, 62, 104, 157, 157, 56, 56, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 164, 165, 165, 166, 158, 158, 163, 163, 167, 168, 168, 169, 170, 171, 171, 171, 171, 19, 19, 73, 73, 73, 73, 159, 159, 159, 159, 173, 173, 162, 162, 162, 160, 160, 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, 180, 180, 180, 108, 182, 182, 182, 182, 161, 161, 161, 161, 161, 161, 161, 161, 59, 59, 176, 176, 176, 176, 176, 183, 183, 172, 172, 172, 172, 184, 184, 184, 184, 184, 74, 74, 66, 66, 66, 66, 134, 134, 134, 134, 187, 186, 175, 175, 175, 175, 175, 175, 174, 174, 174, 185, 185, 185, 185, 107, 181, 189, 189, 188, 188, 190, 190, 190, 190, 190, 190, 190, 190, 178, 178, 178, 178, 177, 192, 191, 191, 191, 191, 191, 191, 191, 191, 193, 193, 193, 193 ); protected array $ruleToLength = array( 1, 1, 2, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 2, 1, 3, 4, 1, 2, 0, 1, 1, 1, 1, 4, 3, 5, 4, 3, 4, 1, 3, 4, 1, 1, 8, 7, 2, 3, 1, 2, 3, 1, 2, 3, 1, 1, 3, 1, 3, 1, 2, 2, 3, 1, 3, 2, 3, 1, 3, 3, 2, 0, 1, 1, 1, 1, 1, 3, 7, 10, 5, 7, 9, 5, 3, 3, 3, 3, 3, 3, 1, 2, 5, 7, 9, 6, 5, 6, 3, 2, 1, 1, 1, 1, 0, 2, 1, 3, 8, 0, 4, 2, 1, 3, 0, 1, 0, 1, 0, 1, 3, 1, 1, 1, 1, 1, 8, 9, 7, 8, 7, 6, 8, 0, 2, 0, 2, 1, 2, 1, 2, 1, 1, 1, 0, 2, 0, 2, 0, 2, 2, 1, 3, 1, 4, 1, 4, 1, 1, 4, 2, 1, 3, 3, 3, 4, 4, 5, 0, 2, 4, 3, 1, 1, 7, 0, 2, 1, 3, 3, 4, 1, 4, 0, 2, 5, 0, 2, 6, 0, 2, 0, 3, 1, 2, 1, 1, 2, 0, 1, 3, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 7, 9, 6, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 3, 3, 3, 3, 3, 1, 3, 3, 1, 1, 2, 1, 1, 0, 1, 0, 2, 2, 2, 4, 3, 2, 4, 4, 3, 3, 1, 3, 1, 1, 3, 2, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 3, 2, 0, 1, 5, 7, 5, 6, 10, 3, 5, 1, 1, 3, 0, 2, 4, 5, 4, 4, 4, 3, 1, 1, 1, 1, 1, 1, 0, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3, 1, 1, 3, 0, 2, 0, 3, 5, 8, 1, 3, 3, 0, 2, 2, 2, 3, 1, 0, 1, 1, 3, 3, 3, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 3, 4, 4, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 3, 2, 1, 2, 4, 2, 2, 8, 9, 8, 9, 9, 10, 9, 10, 8, 3, 2, 2, 1, 1, 0, 4, 2, 1, 3, 2, 1, 2, 2, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 5, 3, 3, 4, 1, 1, 3, 1, 1, 1, 1, 1, 3, 2, 3, 0, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 4, 1, 4, 4, 0, 1, 1, 1, 3, 3, 1, 4, 2, 2, 1, 3, 1, 4, 3, 3, 3, 3, 1, 3, 1, 1, 3, 1, 1, 4, 1, 1, 1, 3, 1, 1, 2, 1, 3, 4, 3, 2, 0, 2, 2, 1, 2, 1, 1, 1, 4, 3, 3, 3, 3, 6, 3, 1, 1, 2, 1 ); protected function initReduceCallbacks(): void { $this->reduceCallbacks = [ 0 => null, 1 => static function ($self, $stackPos) { $self->semValue = $self->handleNamespaces($self->semStack[$stackPos-(1-1)]); }, 2 => static function ($self, $stackPos) { if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; } $self->semValue = $self->semStack[$stackPos-(2-1)];; }, 3 => static function ($self, $stackPos) { $self->semValue = array(); }, 4 => static function ($self, $stackPos) { $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 5 => null, 6 => null, 7 => null, 8 => null, 9 => null, 10 => null, 11 => null, 12 => null, 13 => null, 14 => null, 15 => null, 16 => null, 17 => null, 18 => null, 19 => null, 20 => null, 21 => null, 22 => null, 23 => null, 24 => null, 25 => null, 26 => null, 27 => null, 28 => null, 29 => null, 30 => null, 31 => null, 32 => null, 33 => null, 34 => null, 35 => null, 36 => null, 37 => null, 38 => null, 39 => null, 40 => null, 41 => null, 42 => null, 43 => null, 44 => null, 45 => null, 46 => null, 47 => null, 48 => null, 49 => null, 50 => null, 51 => null, 52 => null, 53 => null, 54 => null, 55 => null, 56 => null, 57 => null, 58 => null, 59 => null, 60 => null, 61 => null, 62 => null, 63 => null, 64 => null, 65 => null, 66 => null, 67 => null, 68 => null, 69 => null, 70 => null, 71 => null, 72 => null, 73 => null, 74 => null, 75 => null, 76 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; if ($self->semValue === "emitError(new Error('Cannot use "getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]))); }, 77 => null, 78 => null, 79 => null, 80 => null, 81 => null, 82 => null, 83 => null, 84 => null, 85 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 86 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 87 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 88 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 89 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 90 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 91 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 92 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 93 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 94 => null, 95 => static function ($self, $stackPos) { $self->semValue = new Name(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 96 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 97 => static function ($self, $stackPos) { /* nothing */ }, 98 => static function ($self, $stackPos) { /* nothing */ }, 99 => static function ($self, $stackPos) { /* nothing */ }, 100 => static function ($self, $stackPos) { $self->emitError(new Error('A trailing comma is not allowed here', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]))); }, 101 => null, 102 => null, 103 => static function ($self, $stackPos) { $self->semValue = new Node\Attribute($self->semStack[$stackPos-(1-1)], [], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 104 => static function ($self, $stackPos) { $self->semValue = new Node\Attribute($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 105 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 106 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 107 => static function ($self, $stackPos) { $self->semValue = new Node\AttributeGroup($self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 108 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 109 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 110 => static function ($self, $stackPos) { $self->semValue = []; }, 111 => null, 112 => null, 113 => null, 114 => null, 115 => static function ($self, $stackPos) { $self->semValue = new Stmt\HaltCompiler($self->handleHaltCompiler(), $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 116 => static function ($self, $stackPos) { $self->semValue = new Stmt\Namespace_($self->semStack[$stackPos-(3-2)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON); $self->checkNamespace($self->semValue); }, 117 => static function ($self, $stackPos) { $self->semValue = new Stmt\Namespace_($self->semStack[$stackPos-(5-2)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); $self->checkNamespace($self->semValue); }, 118 => static function ($self, $stackPos) { $self->semValue = new Stmt\Namespace_(null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); $self->checkNamespace($self->semValue); }, 119 => static function ($self, $stackPos) { $self->semValue = new Stmt\Use_($self->semStack[$stackPos-(3-2)], Stmt\Use_::TYPE_NORMAL, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 120 => static function ($self, $stackPos) { $self->semValue = new Stmt\Use_($self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 121 => null, 122 => static function ($self, $stackPos) { $self->semValue = new Stmt\Const_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), []); }, 123 => static function ($self, $stackPos) { $self->semValue = new Stmt\Const_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(4-1)]); $self->checkConstantAttributes($self->semValue); }, 124 => static function ($self, $stackPos) { $self->semValue = Stmt\Use_::TYPE_FUNCTION; }, 125 => static function ($self, $stackPos) { $self->semValue = Stmt\Use_::TYPE_CONSTANT; }, 126 => static function ($self, $stackPos) { $self->semValue = new Stmt\GroupUse($self->semStack[$stackPos-(8-3)], $self->semStack[$stackPos-(8-6)], $self->semStack[$stackPos-(8-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, 127 => static function ($self, $stackPos) { $self->semValue = new Stmt\GroupUse($self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-5)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, 128 => null, 129 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 130 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 131 => null, 132 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 133 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 134 => null, 135 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 136 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 137 => static function ($self, $stackPos) { $self->semValue = new Node\UseItem($self->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(1-1)); }, 138 => static function ($self, $stackPos) { $self->semValue = new Node\UseItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(3-3)); }, 139 => static function ($self, $stackPos) { $self->semValue = new Node\UseItem($self->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(1-1)); }, 140 => static function ($self, $stackPos) { $self->semValue = new Node\UseItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(3-3)); }, 141 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; $self->semValue->type = Stmt\Use_::TYPE_NORMAL; }, 142 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; $self->semValue->type = $self->semStack[$stackPos-(2-1)]; }, 143 => null, 144 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 145 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 146 => static function ($self, $stackPos) { $self->semValue = new Node\Const_($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 147 => null, 148 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 149 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 150 => static function ($self, $stackPos) { $self->semValue = new Node\Const_(new Node\Identifier($self->semStack[$stackPos-(3-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 151 => static function ($self, $stackPos) { $self->semValue = new Node\Const_(new Node\Identifier($self->semStack[$stackPos-(3-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 152 => static function ($self, $stackPos) { if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; } $self->semValue = $self->semStack[$stackPos-(2-1)];; }, 153 => static function ($self, $stackPos) { $self->semValue = array(); }, 154 => static function ($self, $stackPos) { $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 155 => null, 156 => null, 157 => null, 158 => static function ($self, $stackPos) { throw new Error('__HALT_COMPILER() can only be used from the outermost scope', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 159 => static function ($self, $stackPos) { $self->semValue = new Stmt\Block($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 160 => static function ($self, $stackPos) { $self->semValue = new Stmt\If_($self->semStack[$stackPos-(7-3)], ['stmts' => $self->semStack[$stackPos-(7-5)], 'elseifs' => $self->semStack[$stackPos-(7-6)], 'else' => $self->semStack[$stackPos-(7-7)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, 161 => static function ($self, $stackPos) { $self->semValue = new Stmt\If_($self->semStack[$stackPos-(10-3)], ['stmts' => $self->semStack[$stackPos-(10-6)], 'elseifs' => $self->semStack[$stackPos-(10-7)], 'else' => $self->semStack[$stackPos-(10-8)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); }, 162 => static function ($self, $stackPos) { $self->semValue = new Stmt\While_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 163 => static function ($self, $stackPos) { $self->semValue = new Stmt\Do_($self->semStack[$stackPos-(7-5)], $self->semStack[$stackPos-(7-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, 164 => static function ($self, $stackPos) { $self->semValue = new Stmt\For_(['init' => $self->semStack[$stackPos-(9-3)], 'cond' => $self->semStack[$stackPos-(9-5)], 'loop' => $self->semStack[$stackPos-(9-7)], 'stmts' => $self->semStack[$stackPos-(9-9)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 165 => static function ($self, $stackPos) { $self->semValue = new Stmt\Switch_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 166 => static function ($self, $stackPos) { $self->semValue = new Stmt\Break_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 167 => static function ($self, $stackPos) { $self->semValue = new Stmt\Continue_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 168 => static function ($self, $stackPos) { $self->semValue = new Stmt\Return_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 169 => static function ($self, $stackPos) { $self->semValue = new Stmt\Global_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 170 => static function ($self, $stackPos) { $self->semValue = new Stmt\Static_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 171 => static function ($self, $stackPos) { $self->semValue = new Stmt\Echo_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 172 => static function ($self, $stackPos) { $self->semValue = new Stmt\InlineHTML($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('hasLeadingNewline', $self->inlineHtmlHasLeadingNewline($stackPos-(1-1))); }, 173 => static function ($self, $stackPos) { $self->semValue = new Stmt\Expression($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 174 => static function ($self, $stackPos) { $self->semValue = new Stmt\Unset_($self->semStack[$stackPos-(5-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 175 => static function ($self, $stackPos) { $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-5)][0], ['keyVar' => null, 'byRef' => $self->semStack[$stackPos-(7-5)][1], 'stmts' => $self->semStack[$stackPos-(7-7)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, 176 => static function ($self, $stackPos) { $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(9-3)], $self->semStack[$stackPos-(9-7)][0], ['keyVar' => $self->semStack[$stackPos-(9-5)], 'byRef' => $self->semStack[$stackPos-(9-7)][1], 'stmts' => $self->semStack[$stackPos-(9-9)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 177 => static function ($self, $stackPos) { $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(6-3)], new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(6-4)], $self->tokenEndStack[$stackPos-(6-4)])), ['stmts' => $self->semStack[$stackPos-(6-6)]], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); }, 178 => static function ($self, $stackPos) { $self->semValue = new Stmt\Declare_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 179 => static function ($self, $stackPos) { $self->semValue = new Stmt\TryCatch($self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-5)], $self->semStack[$stackPos-(6-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); $self->checkTryCatch($self->semValue); }, 180 => static function ($self, $stackPos) { $self->semValue = new Stmt\Goto_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 181 => static function ($self, $stackPos) { $self->semValue = new Stmt\Label($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 182 => static function ($self, $stackPos) { $self->semValue = null; /* means: no statement */ }, 183 => null, 184 => static function ($self, $stackPos) { $self->semValue = $self->maybeCreateNop($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]); }, 185 => static function ($self, $stackPos) { if ($self->semStack[$stackPos-(1-1)] instanceof Stmt\Block) { $self->semValue = $self->semStack[$stackPos-(1-1)]->stmts; } else if ($self->semStack[$stackPos-(1-1)] === null) { $self->semValue = []; } else { $self->semValue = [$self->semStack[$stackPos-(1-1)]]; }; }, 186 => static function ($self, $stackPos) { $self->semValue = array(); }, 187 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 188 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 189 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 190 => static function ($self, $stackPos) { $self->semValue = new Stmt\Catch_($self->semStack[$stackPos-(8-3)], $self->semStack[$stackPos-(8-4)], $self->semStack[$stackPos-(8-7)], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, 191 => static function ($self, $stackPos) { $self->semValue = null; }, 192 => static function ($self, $stackPos) { $self->semValue = new Stmt\Finally_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 193 => null, 194 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 195 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 196 => static function ($self, $stackPos) { $self->semValue = false; }, 197 => static function ($self, $stackPos) { $self->semValue = true; }, 198 => static function ($self, $stackPos) { $self->semValue = false; }, 199 => static function ($self, $stackPos) { $self->semValue = true; }, 200 => static function ($self, $stackPos) { $self->semValue = false; }, 201 => static function ($self, $stackPos) { $self->semValue = true; }, 202 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 203 => static function ($self, $stackPos) { $self->semValue = []; }, 204 => null, 205 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 206 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 207 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 208 => static function ($self, $stackPos) { $self->semValue = new Stmt\Function_($self->semStack[$stackPos-(8-3)], ['byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-5)], 'returnType' => $self->semStack[$stackPos-(8-7)], 'stmts' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, 209 => static function ($self, $stackPos) { $self->semValue = new Stmt\Function_($self->semStack[$stackPos-(9-4)], ['byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-6)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 210 => static function ($self, $stackPos) { $self->semValue = new Stmt\Class_($self->semStack[$stackPos-(7-2)], ['type' => $self->semStack[$stackPos-(7-1)], 'extends' => $self->semStack[$stackPos-(7-3)], 'implements' => $self->semStack[$stackPos-(7-4)], 'stmts' => $self->semStack[$stackPos-(7-6)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); $self->checkClass($self->semValue, $stackPos-(7-2)); }, 211 => static function ($self, $stackPos) { $self->semValue = new Stmt\Class_($self->semStack[$stackPos-(8-3)], ['type' => $self->semStack[$stackPos-(8-2)], 'extends' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); $self->checkClass($self->semValue, $stackPos-(8-3)); }, 212 => static function ($self, $stackPos) { $self->semValue = new Stmt\Interface_($self->semStack[$stackPos-(7-3)], ['extends' => $self->semStack[$stackPos-(7-4)], 'stmts' => $self->semStack[$stackPos-(7-6)], 'attrGroups' => $self->semStack[$stackPos-(7-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); $self->checkInterface($self->semValue, $stackPos-(7-3)); }, 213 => static function ($self, $stackPos) { $self->semValue = new Stmt\Trait_($self->semStack[$stackPos-(6-3)], ['stmts' => $self->semStack[$stackPos-(6-5)], 'attrGroups' => $self->semStack[$stackPos-(6-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); }, 214 => static function ($self, $stackPos) { $self->semValue = new Stmt\Enum_($self->semStack[$stackPos-(8-3)], ['scalarType' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); $self->checkEnum($self->semValue, $stackPos-(8-3)); }, 215 => static function ($self, $stackPos) { $self->semValue = null; }, 216 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 217 => static function ($self, $stackPos) { $self->semValue = null; }, 218 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 219 => static function ($self, $stackPos) { $self->semValue = 0; }, 220 => null, 221 => null, 222 => static function ($self, $stackPos) { $self->checkClassModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, 223 => static function ($self, $stackPos) { $self->semValue = Modifiers::ABSTRACT; }, 224 => static function ($self, $stackPos) { $self->semValue = Modifiers::FINAL; }, 225 => static function ($self, $stackPos) { $self->semValue = Modifiers::READONLY; }, 226 => static function ($self, $stackPos) { $self->semValue = null; }, 227 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 228 => static function ($self, $stackPos) { $self->semValue = array(); }, 229 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 230 => static function ($self, $stackPos) { $self->semValue = array(); }, 231 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 232 => null, 233 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 234 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 235 => null, 236 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 237 => null, 238 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 239 => static function ($self, $stackPos) { if ($self->semStack[$stackPos-(1-1)] instanceof Stmt\Block) { $self->semValue = $self->semStack[$stackPos-(1-1)]->stmts; } else if ($self->semStack[$stackPos-(1-1)] === null) { $self->semValue = []; } else { $self->semValue = [$self->semStack[$stackPos-(1-1)]]; }; }, 240 => static function ($self, $stackPos) { $self->semValue = null; }, 241 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 242 => null, 243 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 244 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 245 => static function ($self, $stackPos) { $self->semValue = new Node\DeclareItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 246 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 247 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-3)]; }, 248 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 249 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(5-3)]; }, 250 => static function ($self, $stackPos) { $self->semValue = array(); }, 251 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 252 => static function ($self, $stackPos) { $self->semValue = new Stmt\Case_($self->semStack[$stackPos-(4-2)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 253 => static function ($self, $stackPos) { $self->semValue = new Stmt\Case_(null, $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 254 => null, 255 => null, 256 => static function ($self, $stackPos) { $self->semValue = new Expr\Match_($self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, 257 => static function ($self, $stackPos) { $self->semValue = []; }, 258 => null, 259 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 260 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 261 => static function ($self, $stackPos) { $self->semValue = new Node\MatchArm($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 262 => static function ($self, $stackPos) { $self->semValue = new Node\MatchArm(null, $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 263 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 264 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 265 => static function ($self, $stackPos) { $self->semValue = array(); }, 266 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 267 => static function ($self, $stackPos) { $self->semValue = new Stmt\ElseIf_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 268 => static function ($self, $stackPos) { $self->semValue = array(); }, 269 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 270 => static function ($self, $stackPos) { $self->semValue = new Stmt\ElseIf_($self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); $self->fixupAlternativeElse($self->semValue); }, 271 => static function ($self, $stackPos) { $self->semValue = null; }, 272 => static function ($self, $stackPos) { $self->semValue = new Stmt\Else_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 273 => static function ($self, $stackPos) { $self->semValue = null; }, 274 => static function ($self, $stackPos) { $self->semValue = new Stmt\Else_($self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->fixupAlternativeElse($self->semValue); }, 275 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)], false); }, 276 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(2-2)], true); }, 277 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)], false); }, 278 => static function ($self, $stackPos) { $self->semValue = array($self->fixupArrayDestructuring($self->semStack[$stackPos-(1-1)]), false); }, 279 => null, 280 => static function ($self, $stackPos) { $self->semValue = array(); }, 281 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 282 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 283 => static function ($self, $stackPos) { $self->semValue = 0; }, 284 => static function ($self, $stackPos) { $self->checkModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, 285 => static function ($self, $stackPos) { $self->semValue = Modifiers::PUBLIC; }, 286 => static function ($self, $stackPos) { $self->semValue = Modifiers::PROTECTED; }, 287 => static function ($self, $stackPos) { $self->semValue = Modifiers::PRIVATE; }, 288 => static function ($self, $stackPos) { $self->semValue = Modifiers::PUBLIC_SET; }, 289 => static function ($self, $stackPos) { $self->semValue = Modifiers::PROTECTED_SET; }, 290 => static function ($self, $stackPos) { $self->semValue = Modifiers::PRIVATE_SET; }, 291 => static function ($self, $stackPos) { $self->semValue = Modifiers::READONLY; }, 292 => static function ($self, $stackPos) { $self->semValue = Modifiers::FINAL; }, 293 => static function ($self, $stackPos) { $self->semValue = new Node\Param($self->semStack[$stackPos-(7-6)], null, $self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-4)], $self->semStack[$stackPos-(7-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-1)], $self->semStack[$stackPos-(7-7)]); $self->checkParam($self->semValue); $self->addPropertyNameToHooks($self->semValue); }, 294 => static function ($self, $stackPos) { $self->semValue = new Node\Param($self->semStack[$stackPos-(9-6)], $self->semStack[$stackPos-(9-8)], $self->semStack[$stackPos-(9-3)], $self->semStack[$stackPos-(9-4)], $self->semStack[$stackPos-(9-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(9-2)], $self->semStack[$stackPos-(9-1)], $self->semStack[$stackPos-(9-9)]); $self->checkParam($self->semValue); $self->addPropertyNameToHooks($self->semValue); }, 295 => static function ($self, $stackPos) { $self->semValue = new Node\Param(new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])), null, $self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-4)], $self->semStack[$stackPos-(6-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(6-2)], $self->semStack[$stackPos-(6-1)]); }, 296 => null, 297 => static function ($self, $stackPos) { $self->semValue = new Node\NullableType($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 298 => static function ($self, $stackPos) { $self->semValue = new Node\UnionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 299 => null, 300 => null, 301 => static function ($self, $stackPos) { $self->semValue = new Node\Name('static', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 302 => static function ($self, $stackPos) { $self->semValue = $self->handleBuiltinTypes($self->semStack[$stackPos-(1-1)]); }, 303 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier('array', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 304 => static function ($self, $stackPos) { $self->semValue = new Node\Identifier('callable', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 305 => null, 306 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 307 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, 308 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 309 => null, 310 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 311 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, 312 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 313 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, 314 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 315 => static function ($self, $stackPos) { $self->semValue = new Node\IntersectionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 316 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, 317 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 318 => static function ($self, $stackPos) { $self->semValue = new Node\IntersectionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 319 => null, 320 => static function ($self, $stackPos) { $self->semValue = new Node\NullableType($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 321 => static function ($self, $stackPos) { $self->semValue = new Node\UnionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 322 => null, 323 => static function ($self, $stackPos) { $self->semValue = null; }, 324 => null, 325 => static function ($self, $stackPos) { $self->semValue = null; }, 326 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(2-2)]; }, 327 => static function ($self, $stackPos) { $self->semValue = null; }, 328 => static function ($self, $stackPos) { $self->semValue = array(); }, 329 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 330 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-2)]); }, 331 => static function ($self, $stackPos) { $self->semValue = array(); }, 332 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-2)]; }, 333 => static function ($self, $stackPos) { $self->semValue = array(new Node\Arg($self->semStack[$stackPos-(4-2)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]))); }, 334 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-2)]); }, 335 => static function ($self, $stackPos) { $self->semValue = array(new Node\Arg($self->semStack[$stackPos-(3-1)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)]); }, 336 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 337 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 338 => static function ($self, $stackPos) { $self->semValue = new Node\VariadicPlaceholder($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 339 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 340 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 341 => static function ($self, $stackPos) { $self->semValue = new Node\Arg($self->semStack[$stackPos-(2-2)], true, false, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 342 => static function ($self, $stackPos) { $self->semValue = new Node\Arg($self->semStack[$stackPos-(2-2)], false, true, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 343 => static function ($self, $stackPos) { $self->semValue = new Node\Arg($self->semStack[$stackPos-(3-3)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(3-1)]); }, 344 => static function ($self, $stackPos) { $self->semValue = new Node\Arg($self->semStack[$stackPos-(1-1)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 345 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 346 => null, 347 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 348 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 349 => null, 350 => null, 351 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 352 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 353 => static function ($self, $stackPos) { $self->semValue = new Node\StaticVar($self->semStack[$stackPos-(1-1)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 354 => static function ($self, $stackPos) { $self->semValue = new Node\StaticVar($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 355 => static function ($self, $stackPos) { if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; } else { $self->semValue = $self->semStack[$stackPos-(2-1)]; } }, 356 => static function ($self, $stackPos) { $self->semValue = array(); }, 357 => static function ($self, $stackPos) { $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 358 => static function ($self, $stackPos) { $self->semValue = new Stmt\Property($self->semStack[$stackPos-(5-2)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-1)]); }, 359 => static function ($self, $stackPos) { $self->semValue = new Stmt\Property($self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-1)], $self->semStack[$stackPos-(7-6)]); $self->checkPropertyHooksForMultiProperty($self->semValue, $stackPos-(7-5)); $self->checkEmptyPropertyHookList($self->semStack[$stackPos-(7-6)], $stackPos-(7-5)); $self->addPropertyNameToHooks($self->semValue); }, 360 => static function ($self, $stackPos) { $self->semValue = new Stmt\ClassConst($self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(5-1)]); $self->checkClassConst($self->semValue, $stackPos-(5-2)); }, 361 => static function ($self, $stackPos) { $self->semValue = new Stmt\ClassConst($self->semStack[$stackPos-(6-5)], $self->semStack[$stackPos-(6-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(6-1)], $self->semStack[$stackPos-(6-4)]); $self->checkClassConst($self->semValue, $stackPos-(6-2)); }, 362 => static function ($self, $stackPos) { $self->semValue = new Stmt\ClassMethod($self->semStack[$stackPos-(10-5)], ['type' => $self->semStack[$stackPos-(10-2)], 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-7)], 'returnType' => $self->semStack[$stackPos-(10-9)], 'stmts' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); $self->checkClassMethod($self->semValue, $stackPos-(10-2)); }, 363 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUse($self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 364 => static function ($self, $stackPos) { $self->semValue = new Stmt\EnumCase($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 365 => static function ($self, $stackPos) { $self->semValue = null; /* will be skipped */ }, 366 => static function ($self, $stackPos) { $self->semValue = array(); }, 367 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 368 => static function ($self, $stackPos) { $self->semValue = array(); }, 369 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 370 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUseAdaptation\Precedence($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 371 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(5-1)][0], $self->semStack[$stackPos-(5-1)][1], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 372 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 373 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 374 => static function ($self, $stackPos) { $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 375 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, 376 => null, 377 => static function ($self, $stackPos) { $self->semValue = array(null, $self->semStack[$stackPos-(1-1)]); }, 378 => static function ($self, $stackPos) { $self->semValue = null; }, 379 => null, 380 => null, 381 => static function ($self, $stackPos) { $self->semValue = 0; }, 382 => static function ($self, $stackPos) { $self->semValue = 0; }, 383 => null, 384 => null, 385 => static function ($self, $stackPos) { $self->checkModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, 386 => static function ($self, $stackPos) { $self->semValue = Modifiers::PUBLIC; }, 387 => static function ($self, $stackPos) { $self->semValue = Modifiers::PROTECTED; }, 388 => static function ($self, $stackPos) { $self->semValue = Modifiers::PRIVATE; }, 389 => static function ($self, $stackPos) { $self->semValue = Modifiers::PUBLIC_SET; }, 390 => static function ($self, $stackPos) { $self->semValue = Modifiers::PROTECTED_SET; }, 391 => static function ($self, $stackPos) { $self->semValue = Modifiers::PRIVATE_SET; }, 392 => static function ($self, $stackPos) { $self->semValue = Modifiers::STATIC; }, 393 => static function ($self, $stackPos) { $self->semValue = Modifiers::ABSTRACT; }, 394 => static function ($self, $stackPos) { $self->semValue = Modifiers::FINAL; }, 395 => static function ($self, $stackPos) { $self->semValue = Modifiers::READONLY; }, 396 => null, 397 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 398 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 399 => static function ($self, $stackPos) { $self->semValue = new Node\VarLikeIdentifier(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 400 => static function ($self, $stackPos) { $self->semValue = new Node\PropertyItem($self->semStack[$stackPos-(1-1)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 401 => static function ($self, $stackPos) { $self->semValue = new Node\PropertyItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 402 => static function ($self, $stackPos) { $self->semValue = []; }, 403 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 404 => static function ($self, $stackPos) { $self->semValue = []; }, 405 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; $self->checkEmptyPropertyHookList($self->semStack[$stackPos-(3-2)], $stackPos-(3-1)); }, 406 => static function ($self, $stackPos) { $self->semValue = new Node\PropertyHook($self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-5)], ['flags' => $self->semStack[$stackPos-(5-2)], 'byRef' => $self->semStack[$stackPos-(5-3)], 'params' => [], 'attrGroups' => $self->semStack[$stackPos-(5-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); $self->checkPropertyHook($self->semValue, null); }, 407 => static function ($self, $stackPos) { $self->semValue = new Node\PropertyHook($self->semStack[$stackPos-(8-4)], $self->semStack[$stackPos-(8-8)], ['flags' => $self->semStack[$stackPos-(8-2)], 'byRef' => $self->semStack[$stackPos-(8-3)], 'params' => $self->semStack[$stackPos-(8-6)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); $self->checkPropertyHook($self->semValue, $stackPos-(8-5)); }, 408 => static function ($self, $stackPos) { $self->semValue = null; }, 409 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 410 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 411 => static function ($self, $stackPos) { $self->semValue = 0; }, 412 => static function ($self, $stackPos) { $self->checkPropertyHookModifiers($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, 413 => null, 414 => null, 415 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 416 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 417 => static function ($self, $stackPos) { $self->semValue = array(); }, 418 => null, 419 => null, 420 => static function ($self, $stackPos) { $self->semValue = new Expr\Assign($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 421 => static function ($self, $stackPos) { $self->semValue = new Expr\Assign($self->fixupArrayDestructuring($self->semStack[$stackPos-(3-1)]), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 422 => static function ($self, $stackPos) { $self->semValue = new Expr\Assign($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 423 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignRef($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 424 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignRef($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); if (!$self->phpVersion->allowsAssignNewByReference()) { $self->emitError(new Error('Cannot assign new by reference', $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]))); } }, 425 => null, 426 => null, 427 => static function ($self, $stackPos) { $self->semValue = new Expr\FuncCall(new Node\Name($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos-(2-1)])), $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 428 => static function ($self, $stackPos) { $self->semValue = new Expr\Clone_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 429 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Plus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 430 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Minus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 431 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Mul($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 432 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Div($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 433 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Concat($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 434 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Mod($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 435 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 436 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\BitwiseOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 437 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\BitwiseXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 438 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\ShiftLeft($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 439 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\ShiftRight($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 440 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Pow($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 441 => static function ($self, $stackPos) { $self->semValue = new Expr\AssignOp\Coalesce($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 442 => static function ($self, $stackPos) { $self->semValue = new Expr\PostInc($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 443 => static function ($self, $stackPos) { $self->semValue = new Expr\PreInc($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 444 => static function ($self, $stackPos) { $self->semValue = new Expr\PostDec($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 445 => static function ($self, $stackPos) { $self->semValue = new Expr\PreDec($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 446 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BooleanOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 447 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BooleanAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 448 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\LogicalOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 449 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\LogicalAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 450 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\LogicalXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 451 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BitwiseOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 452 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 453 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 454 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\BitwiseXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 455 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Concat($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 456 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Plus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 457 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Minus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 458 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Mul($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 459 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Div($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 460 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Mod($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 461 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\ShiftLeft($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 462 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\ShiftRight($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 463 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Pow($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 464 => static function ($self, $stackPos) { $self->semValue = new Expr\UnaryPlus($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 465 => static function ($self, $stackPos) { $self->semValue = new Expr\UnaryMinus($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 466 => static function ($self, $stackPos) { $self->semValue = new Expr\BooleanNot($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 467 => static function ($self, $stackPos) { $self->semValue = new Expr\BitwiseNot($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 468 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Identical($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 469 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\NotIdentical($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 470 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Equal($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 471 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\NotEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 472 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Spaceship($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 473 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Smaller($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 474 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\SmallerOrEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 475 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Greater($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 476 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\GreaterOrEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 477 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Pipe($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->checkPipeOperatorParentheses($self->semStack[$stackPos-(3-3)]); }, 478 => static function ($self, $stackPos) { $self->semValue = new Expr\Instanceof_($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 479 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; if ($self->semValue instanceof Expr\ArrowFunction) { $self->parenthesizedArrowFunctions->offsetSet($self->semValue); } }, 480 => static function ($self, $stackPos) { $self->semValue = new Expr\Ternary($self->semStack[$stackPos-(5-1)], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 481 => static function ($self, $stackPos) { $self->semValue = new Expr\Ternary($self->semStack[$stackPos-(4-1)], null, $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 482 => static function ($self, $stackPos) { $self->semValue = new Expr\BinaryOp\Coalesce($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 483 => static function ($self, $stackPos) { $self->semValue = new Expr\Isset_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 484 => static function ($self, $stackPos) { $self->semValue = new Expr\Empty_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 485 => static function ($self, $stackPos) { $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 486 => static function ($self, $stackPos) { $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE_ONCE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 487 => static function ($self, $stackPos) { $self->semValue = new Expr\Eval_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 488 => static function ($self, $stackPos) { $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 489 => static function ($self, $stackPos) { $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE_ONCE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 490 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = $self->getIntCastKind($self->semStack[$stackPos-(2-1)]); $self->semValue = new Expr\Cast\Int_($self->semStack[$stackPos-(2-2)], $attrs); }, 491 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = $self->getFloatCastKind($self->semStack[$stackPos-(2-1)]); $self->semValue = new Expr\Cast\Double($self->semStack[$stackPos-(2-2)], $attrs); }, 492 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = $self->getStringCastKind($self->semStack[$stackPos-(2-1)]); $self->semValue = new Expr\Cast\String_($self->semStack[$stackPos-(2-2)], $attrs); }, 493 => static function ($self, $stackPos) { $self->semValue = new Expr\Cast\Array_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 494 => static function ($self, $stackPos) { $self->semValue = new Expr\Cast\Object_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 495 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = $self->getBoolCastKind($self->semStack[$stackPos-(2-1)]); $self->semValue = new Expr\Cast\Bool_($self->semStack[$stackPos-(2-2)], $attrs); }, 496 => static function ($self, $stackPos) { $self->semValue = new Expr\Cast\Unset_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 497 => static function ($self, $stackPos) { $self->semValue = new Expr\Cast\Void_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 498 => static function ($self, $stackPos) { $self->semValue = $self->createExitExpr($self->semStack[$stackPos-(2-1)], $stackPos-(2-1), $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 499 => static function ($self, $stackPos) { $self->semValue = new Expr\ErrorSuppress($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 500 => null, 501 => static function ($self, $stackPos) { $self->semValue = new Expr\ShellExec($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 502 => static function ($self, $stackPos) { $self->semValue = new Expr\Print_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 503 => static function ($self, $stackPos) { $self->semValue = new Expr\Yield_(null, null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 504 => static function ($self, $stackPos) { $self->semValue = new Expr\Yield_($self->semStack[$stackPos-(2-2)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 505 => static function ($self, $stackPos) { $self->semValue = new Expr\Yield_($self->semStack[$stackPos-(4-4)], $self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 506 => static function ($self, $stackPos) { $self->semValue = new Expr\YieldFrom($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 507 => static function ($self, $stackPos) { $self->semValue = new Expr\Throw_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 508 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrowFunction(['static' => false, 'byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-4)], 'returnType' => $self->semStack[$stackPos-(8-6)], 'expr' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, 509 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrowFunction(['static' => true, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'returnType' => $self->semStack[$stackPos-(9-7)], 'expr' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 510 => static function ($self, $stackPos) { $self->semValue = new Expr\Closure(['static' => false, 'byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-4)], 'uses' => $self->semStack[$stackPos-(8-6)], 'returnType' => $self->semStack[$stackPos-(8-7)], 'stmts' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, 511 => static function ($self, $stackPos) { $self->semValue = new Expr\Closure(['static' => true, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'uses' => $self->semStack[$stackPos-(9-7)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 512 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrowFunction(['static' => false, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'returnType' => $self->semStack[$stackPos-(9-7)], 'expr' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 513 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrowFunction(['static' => true, 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-6)], 'returnType' => $self->semStack[$stackPos-(10-8)], 'expr' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); }, 514 => static function ($self, $stackPos) { $self->semValue = new Expr\Closure(['static' => false, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'uses' => $self->semStack[$stackPos-(9-7)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, 515 => static function ($self, $stackPos) { $self->semValue = new Expr\Closure(['static' => true, 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-6)], 'uses' => $self->semStack[$stackPos-(10-8)], 'returnType' => $self->semStack[$stackPos-(10-9)], 'stmts' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); }, 516 => static function ($self, $stackPos) { $self->semValue = array(new Stmt\Class_(null, ['type' => $self->semStack[$stackPos-(8-2)], 'extends' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])), $self->semStack[$stackPos-(8-3)]); $self->checkClass($self->semValue[0], -1); }, 517 => static function ($self, $stackPos) { $self->semValue = new Expr\New_($self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 518 => static function ($self, $stackPos) { list($class, $ctorArgs) = $self->semStack[$stackPos-(2-2)]; $self->semValue = new Expr\New_($class, $ctorArgs, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 519 => static function ($self, $stackPos) { $self->semValue = new Expr\New_($self->semStack[$stackPos-(2-2)], [], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 520 => null, 521 => null, 522 => static function ($self, $stackPos) { $self->semValue = array(); }, 523 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(4-3)]; }, 524 => null, 525 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 526 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 527 => static function ($self, $stackPos) { $self->semValue = new Node\ClosureUse($self->semStack[$stackPos-(2-2)], $self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 528 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 529 => static function ($self, $stackPos) { $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 530 => static function ($self, $stackPos) { $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 531 => static function ($self, $stackPos) { $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 532 => static function ($self, $stackPos) { $self->semValue = new Expr\StaticCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 533 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 534 => null, 535 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 536 => static function ($self, $stackPos) { $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 537 => static function ($self, $stackPos) { $self->semValue = new Name\FullyQualified(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 538 => static function ($self, $stackPos) { $self->semValue = new Name\Relative(substr($self->semStack[$stackPos-(1-1)], 10), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 539 => null, 540 => null, 541 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 542 => static function ($self, $stackPos) { $self->semValue = new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, 543 => null, 544 => null, 545 => static function ($self, $stackPos) { $self->semValue = array(); }, 546 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); foreach ($self->semValue as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '`', $self->phpVersion->supportsUnicodeEscapes()); } }; }, 547 => static function ($self, $stackPos) { foreach ($self->semStack[$stackPos-(1-1)] as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '`', $self->phpVersion->supportsUnicodeEscapes()); } }; $self->semValue = $self->semStack[$stackPos-(1-1)]; }, 548 => static function ($self, $stackPos) { $self->semValue = array(); }, 549 => null, 550 => static function ($self, $stackPos) { $self->semValue = new Expr\ConstFetch($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 551 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Line($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 552 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\File($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 553 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Dir($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 554 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Class_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 555 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Trait_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 556 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Method($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 557 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Function_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 558 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Namespace_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 559 => static function ($self, $stackPos) { $self->semValue = new Scalar\MagicConst\Property($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 560 => static function ($self, $stackPos) { $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 561 => static function ($self, $stackPos) { $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(5-1)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, 562 => static function ($self, $stackPos) { $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(3-1)], new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)])), $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, 563 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Expr\Array_::KIND_SHORT; $self->semValue = new Expr\Array_($self->semStack[$stackPos-(3-2)], $attrs); }, 564 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Expr\Array_::KIND_LONG; $self->semValue = new Expr\Array_($self->semStack[$stackPos-(4-3)], $attrs); $self->createdArrays->offsetSet($self->semValue); }, 565 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; $self->createdArrays->offsetSet($self->semValue); }, 566 => static function ($self, $stackPos) { $self->semValue = Scalar\String_::fromString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]), $self->phpVersion->supportsUnicodeEscapes()); }, 567 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED; foreach ($self->semStack[$stackPos-(3-2)] as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '"', $self->phpVersion->supportsUnicodeEscapes()); } }; $self->semValue = new Scalar\InterpolatedString($self->semStack[$stackPos-(3-2)], $attrs); }, 568 => static function ($self, $stackPos) { $self->semValue = $self->parseLNumber($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]), $self->phpVersion->allowsInvalidOctals()); }, 569 => static function ($self, $stackPos) { $self->semValue = Scalar\Float_::fromString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 570 => null, 571 => null, 572 => null, 573 => static function ($self, $stackPos) { $self->semValue = $self->parseDocString($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)]), true); }, 574 => static function ($self, $stackPos) { $self->semValue = $self->parseDocString($self->semStack[$stackPos-(2-1)], '', $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(2-2)], $self->tokenEndStack[$stackPos-(2-2)]), true); }, 575 => static function ($self, $stackPos) { $self->semValue = $self->parseDocString($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)]), true); }, 576 => static function ($self, $stackPos) { $self->semValue = null; }, 577 => null, 578 => null, 579 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 580 => null, 581 => null, 582 => null, 583 => null, 584 => null, 585 => null, 586 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 587 => null, 588 => null, 589 => null, 590 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 591 => null, 592 => static function ($self, $stackPos) { $self->semValue = new Expr\MethodCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 593 => static function ($self, $stackPos) { $self->semValue = new Expr\NullsafeMethodCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 594 => static function ($self, $stackPos) { $self->semValue = null; }, 595 => null, 596 => null, 597 => null, 598 => static function ($self, $stackPos) { $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 599 => static function ($self, $stackPos) { $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 600 => null, 601 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 602 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 603 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable(new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])), $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, 604 => static function ($self, $stackPos) { $var = $self->semStack[$stackPos-(1-1)]->name; $self->semValue = \is_string($var) ? new Node\VarLikeIdentifier($var, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])) : $var; }, 605 => static function ($self, $stackPos) { $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 606 => null, 607 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 608 => static function ($self, $stackPos) { $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 609 => static function ($self, $stackPos) { $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 610 => static function ($self, $stackPos) { $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 611 => static function ($self, $stackPos) { $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 612 => null, 613 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 614 => null, 615 => null, 616 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 617 => null, 618 => static function ($self, $stackPos) { $self->semValue = new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, 619 => static function ($self, $stackPos) { $self->semValue = new Expr\List_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('kind', Expr\List_::KIND_LIST); $self->postprocessList($self->semValue); }, 620 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(1-1)]; $end = count($self->semValue)-1; if ($self->semValue[$end]->value instanceof Expr\Error) array_pop($self->semValue); }, 621 => null, 622 => static function ($self, $stackPos) { /* do nothing -- prevent default action of $$=$self->semStack[$1]. See $551. */ }, 623 => static function ($self, $stackPos) { $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, 624 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 625 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(1-1)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 626 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(2-2)], null, true, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 627 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(1-1)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 628 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(3-3)], $self->semStack[$stackPos-(3-1)], false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 629 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(4-4)], $self->semStack[$stackPos-(4-1)], true, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 630 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(3-3)], $self->semStack[$stackPos-(3-1)], false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 631 => static function ($self, $stackPos) { $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(2-2)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]), true); }, 632 => static function ($self, $stackPos) { /* Create an Error node now to remember the position. We'll later either report an error, or convert this into a null element, depending on whether this is a creation or destructuring context. */ $attrs = $self->createEmptyElemAttributes($self->tokenPos); $self->semValue = new Node\ArrayItem(new Expr\Error($attrs), null, false, $attrs); }, 633 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 634 => static function ($self, $stackPos) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, 635 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, 636 => static function ($self, $stackPos) { $self->semValue = array($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)]); }, 637 => static function ($self, $stackPos) { $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]); $attrs['rawValue'] = $self->semStack[$stackPos-(1-1)]; $self->semValue = new Node\InterpolatedStringPart($self->semStack[$stackPos-(1-1)], $attrs); }, 638 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 639 => null, 640 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, 641 => static function ($self, $stackPos) { $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 642 => static function ($self, $stackPos) { $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 643 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 644 => static function ($self, $stackPos) { $self->semValue = new Expr\Variable($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, 645 => static function ($self, $stackPos) { $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(6-2)], $self->semStack[$stackPos-(6-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); }, 646 => static function ($self, $stackPos) { $self->semValue = $self->semStack[$stackPos-(3-2)]; }, 647 => static function ($self, $stackPos) { $self->semValue = new Scalar\String_($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 648 => static function ($self, $stackPos) { $self->semValue = $self->parseNumString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, 649 => static function ($self, $stackPos) { $self->semValue = $self->parseNumString('-' . $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, 650 => null, ]; } } ================================================ FILE: lib/PhpParser/Parser.php ================================================ Map of PHP token IDs to drop */ protected array $dropTokens; /** @var int[] Map of external symbols (static::T_*) to internal symbols */ protected array $tokenToSymbol; /** @var string[] Map of symbols to their names */ protected array $symbolToName; /** @var array Names of the production rules (only necessary for debugging) */ protected array $productions; /** @var int[] Map of states to a displacement into the $action table. The corresponding action for this * state/symbol pair is $action[$actionBase[$state] + $symbol]. If $actionBase[$state] is 0, the * action is defaulted, i.e. $actionDefault[$state] should be used instead. */ protected array $actionBase; /** @var int[] Table of actions. Indexed according to $actionBase comment. */ protected array $action; /** @var int[] Table indexed analogously to $action. If $actionCheck[$actionBase[$state] + $symbol] != $symbol * then the action is defaulted, i.e. $actionDefault[$state] should be used instead. */ protected array $actionCheck; /** @var int[] Map of states to their default action */ protected array $actionDefault; /** @var callable[] Semantic action callbacks */ protected array $reduceCallbacks; /** @var int[] Map of non-terminals to a displacement into the $goto table. The corresponding goto state for this * non-terminal/state pair is $goto[$gotoBase[$nonTerminal] + $state] (unless defaulted) */ protected array $gotoBase; /** @var int[] Table of states to goto after reduction. Indexed according to $gotoBase comment. */ protected array $goto; /** @var int[] Table indexed analogously to $goto. If $gotoCheck[$gotoBase[$nonTerminal] + $state] != $nonTerminal * then the goto state is defaulted, i.e. $gotoDefault[$nonTerminal] should be used. */ protected array $gotoCheck; /** @var int[] Map of non-terminals to the default state to goto after their reduction */ protected array $gotoDefault; /** @var int[] Map of rules to the non-terminal on their left-hand side, i.e. the non-terminal to use for * determining the state to goto after reduction. */ protected array $ruleToNonTerminal; /** @var int[] Map of rules to the length of their right-hand side, which is the number of elements that have to * be popped from the stack(s) on reduction. */ protected array $ruleToLength; /* * The following members are part of the parser state: */ /** @var mixed Temporary value containing the result of last semantic action (reduction) */ protected $semValue; /** @var mixed[] Semantic value stack (contains values of tokens and semantic action results) */ protected array $semStack; /** @var int[] Token start position stack */ protected array $tokenStartStack; /** @var int[] Token end position stack */ protected array $tokenEndStack; /** @var ErrorHandler Error handler */ protected ErrorHandler $errorHandler; /** @var int Error state, used to avoid error floods */ protected int $errorState; /** @var \SplObjectStorage|null Array nodes created during parsing, for postprocessing of empty elements. */ protected ?\SplObjectStorage $createdArrays; /** @var \SplObjectStorage|null * Arrow functions that are wrapped in parentheses, to enforce the pipe operator parentheses requirements. */ protected ?\SplObjectStorage $parenthesizedArrowFunctions; /** @var Token[] Tokens for the current parse */ protected array $tokens; /** @var int Current position in token array */ protected int $tokenPos; /** * Initialize $reduceCallbacks map. */ abstract protected function initReduceCallbacks(): void; /** * Creates a parser instance. * * Options: * * phpVersion: ?PhpVersion, * * @param Lexer $lexer A lexer * @param PhpVersion $phpVersion PHP version to target, defaults to latest supported. This * option is best-effort: Even if specified, parsing will generally assume the latest * supported version and only adjust behavior in minor ways, for example by omitting * errors in older versions and interpreting type hints as a name or identifier depending * on version. */ public function __construct(Lexer $lexer, ?PhpVersion $phpVersion = null) { $this->lexer = $lexer; $this->phpVersion = $phpVersion ?? PhpVersion::getNewestSupported(); $this->initReduceCallbacks(); $this->phpTokenToSymbol = $this->createTokenMap(); $this->dropTokens = array_fill_keys( [\T_WHITESPACE, \T_OPEN_TAG, \T_COMMENT, \T_DOC_COMMENT, \T_BAD_CHARACTER], true ); } /** * Parses PHP code into a node tree. * * If a non-throwing error handler is used, the parser will continue parsing after an error * occurred and attempt to build a partial AST. * * @param string $code The source code to parse * @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults * to ErrorHandler\Throwing. * * @return Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and * the parser was unable to recover from an error). */ public function parse(string $code, ?ErrorHandler $errorHandler = null): ?array { $this->errorHandler = $errorHandler ?: new ErrorHandler\Throwing(); $this->createdArrays = new \SplObjectStorage(); $this->parenthesizedArrowFunctions = new \SplObjectStorage(); $this->tokens = $this->lexer->tokenize($code, $this->errorHandler); $result = $this->doParse(); // Report errors for any empty elements used inside arrays. This is delayed until after the main parse, // because we don't know a priori whether a given array expression will be used in a destructuring context // or not. foreach ($this->createdArrays as $node) { foreach ($node->items as $item) { if ($item->value instanceof Expr\Error) { $this->errorHandler->handleError( new Error('Cannot use empty array elements in arrays', $item->getAttributes())); } } } // Clear out some of the interior state, so we don't hold onto unnecessary // memory between uses of the parser $this->tokenStartStack = []; $this->tokenEndStack = []; $this->semStack = []; $this->semValue = null; $this->createdArrays = null; $this->parenthesizedArrowFunctions = null; if ($result !== null) { $traverser = new NodeTraverser(new CommentAnnotatingVisitor($this->tokens)); $traverser->traverse($result); } return $result; } public function getTokens(): array { return $this->tokens; } /** @return Stmt[]|null */ protected function doParse(): ?array { // We start off with no lookahead-token $symbol = self::SYMBOL_NONE; $tokenValue = null; $this->tokenPos = -1; // Keep stack of start and end attributes $this->tokenStartStack = []; $this->tokenEndStack = [0]; // Start off in the initial state and keep a stack of previous states $state = 0; $stateStack = [$state]; // Semantic value stack (contains values of tokens and semantic action results) $this->semStack = []; // Current position in the stack(s) $stackPos = 0; $this->errorState = 0; for (;;) { //$this->traceNewState($state, $symbol); if ($this->actionBase[$state] === 0) { $rule = $this->actionDefault[$state]; } else { if ($symbol === self::SYMBOL_NONE) { do { $token = $this->tokens[++$this->tokenPos]; $tokenId = $token->id; } while (isset($this->dropTokens[$tokenId])); // Map the lexer token id to the internally used symbols. $tokenValue = $token->text; if (!isset($this->phpTokenToSymbol[$tokenId])) { throw new \RangeException(sprintf( 'The lexer returned an invalid token (id=%d, value=%s)', $tokenId, $tokenValue )); } $symbol = $this->phpTokenToSymbol[$tokenId]; //$this->traceRead($symbol); } $idx = $this->actionBase[$state] + $symbol; if ((($idx >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $symbol) || ($state < $this->YY2TBLSTATE && ($idx = $this->actionBase[$state + $this->numNonLeafStates] + $symbol) >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $symbol)) && ($action = $this->action[$idx]) !== $this->defaultAction) { /* * >= numNonLeafStates: shift and reduce * > 0: shift * = 0: accept * < 0: reduce * = -YYUNEXPECTED: error */ if ($action > 0) { /* shift */ //$this->traceShift($symbol); ++$stackPos; $stateStack[$stackPos] = $state = $action; $this->semStack[$stackPos] = $tokenValue; $this->tokenStartStack[$stackPos] = $this->tokenPos; $this->tokenEndStack[$stackPos] = $this->tokenPos; $symbol = self::SYMBOL_NONE; if ($this->errorState) { --$this->errorState; } if ($action < $this->numNonLeafStates) { continue; } /* $yyn >= numNonLeafStates means shift-and-reduce */ $rule = $action - $this->numNonLeafStates; } else { $rule = -$action; } } else { $rule = $this->actionDefault[$state]; } } for (;;) { if ($rule === 0) { /* accept */ //$this->traceAccept(); return $this->semValue; } if ($rule !== $this->unexpectedTokenRule) { /* reduce */ //$this->traceReduce($rule); $ruleLength = $this->ruleToLength[$rule]; try { $callback = $this->reduceCallbacks[$rule]; if ($callback !== null) { $callback($this, $stackPos); } elseif ($ruleLength > 0) { $this->semValue = $this->semStack[$stackPos - $ruleLength + 1]; } } catch (Error $e) { if (-1 === $e->getStartLine()) { $e->setStartLine($this->tokens[$this->tokenPos]->line); } $this->emitError($e); // Can't recover from this type of error return null; } /* Goto - shift nonterminal */ $lastTokenEnd = $this->tokenEndStack[$stackPos]; $stackPos -= $ruleLength; $nonTerminal = $this->ruleToNonTerminal[$rule]; $idx = $this->gotoBase[$nonTerminal] + $stateStack[$stackPos]; if ($idx >= 0 && $idx < $this->gotoTableSize && $this->gotoCheck[$idx] === $nonTerminal) { $state = $this->goto[$idx]; } else { $state = $this->gotoDefault[$nonTerminal]; } ++$stackPos; $stateStack[$stackPos] = $state; $this->semStack[$stackPos] = $this->semValue; $this->tokenEndStack[$stackPos] = $lastTokenEnd; if ($ruleLength === 0) { // Empty productions use the start attributes of the lookahead token. $this->tokenStartStack[$stackPos] = $this->tokenPos; } } else { /* error */ switch ($this->errorState) { case 0: $msg = $this->getErrorMessage($symbol, $state); $this->emitError(new Error($msg, $this->getAttributesForToken($this->tokenPos))); // Break missing intentionally // no break case 1: case 2: $this->errorState = 3; // Pop until error-expecting state uncovered while (!( (($idx = $this->actionBase[$state] + $this->errorSymbol) >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $this->errorSymbol) || ($state < $this->YY2TBLSTATE && ($idx = $this->actionBase[$state + $this->numNonLeafStates] + $this->errorSymbol) >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $this->errorSymbol) ) || ($action = $this->action[$idx]) === $this->defaultAction) { // Not totally sure about this if ($stackPos <= 0) { // Could not recover from error return null; } $state = $stateStack[--$stackPos]; //$this->tracePop($state); } //$this->traceShift($this->errorSymbol); ++$stackPos; $stateStack[$stackPos] = $state = $action; // We treat the error symbol as being empty, so we reset the end attributes // to the end attributes of the last non-error symbol $this->tokenStartStack[$stackPos] = $this->tokenPos; $this->tokenEndStack[$stackPos] = $this->tokenEndStack[$stackPos - 1]; break; case 3: if ($symbol === 0) { // Reached EOF without recovering from error return null; } //$this->traceDiscard($symbol); $symbol = self::SYMBOL_NONE; break 2; } } if ($state < $this->numNonLeafStates) { break; } /* >= numNonLeafStates means shift-and-reduce */ $rule = $state - $this->numNonLeafStates; } } } protected function emitError(Error $error): void { $this->errorHandler->handleError($error); } /** * Format error message including expected tokens. * * @param int $symbol Unexpected symbol * @param int $state State at time of error * * @return string Formatted error message */ protected function getErrorMessage(int $symbol, int $state): string { $expectedString = ''; if ($expected = $this->getExpectedTokens($state)) { $expectedString = ', expecting ' . implode(' or ', $expected); } return 'Syntax error, unexpected ' . $this->symbolToName[$symbol] . $expectedString; } /** * Get limited number of expected tokens in given state. * * @param int $state State * * @return string[] Expected tokens. If too many, an empty array is returned. */ protected function getExpectedTokens(int $state): array { $expected = []; $base = $this->actionBase[$state]; foreach ($this->symbolToName as $symbol => $name) { $idx = $base + $symbol; if ($idx >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $symbol || $state < $this->YY2TBLSTATE && ($idx = $this->actionBase[$state + $this->numNonLeafStates] + $symbol) >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $symbol ) { if ($this->action[$idx] !== $this->unexpectedTokenRule && $this->action[$idx] !== $this->defaultAction && $symbol !== $this->errorSymbol ) { if (count($expected) === 4) { /* Too many expected tokens */ return []; } $expected[] = $name; } } } return $expected; } /** * Get attributes for a node with the given start and end token positions. * * @param int $tokenStartPos Token position the node starts at * @param int $tokenEndPos Token position the node ends at * @return array Attributes */ protected function getAttributes(int $tokenStartPos, int $tokenEndPos): array { $startToken = $this->tokens[$tokenStartPos]; $afterEndToken = $this->tokens[$tokenEndPos + 1]; return [ 'startLine' => $startToken->line, 'startTokenPos' => $tokenStartPos, 'startFilePos' => $startToken->pos, 'endLine' => $afterEndToken->line, 'endTokenPos' => $tokenEndPos, 'endFilePos' => $afterEndToken->pos - 1, ]; } /** * Get attributes for a single token at the given token position. * * @return array Attributes */ protected function getAttributesForToken(int $tokenPos): array { if ($tokenPos < \count($this->tokens) - 1) { return $this->getAttributes($tokenPos, $tokenPos); } // Get attributes for the sentinel token. $token = $this->tokens[$tokenPos]; return [ 'startLine' => $token->line, 'startTokenPos' => $tokenPos, 'startFilePos' => $token->pos, 'endLine' => $token->line, 'endTokenPos' => $tokenPos, 'endFilePos' => $token->pos, ]; } /* * Tracing functions used for debugging the parser. */ /* protected function traceNewState($state, $symbol): void { echo '% State ' . $state . ', Lookahead ' . ($symbol == self::SYMBOL_NONE ? '--none--' : $this->symbolToName[$symbol]) . "\n"; } protected function traceRead($symbol): void { echo '% Reading ' . $this->symbolToName[$symbol] . "\n"; } protected function traceShift($symbol): void { echo '% Shift ' . $this->symbolToName[$symbol] . "\n"; } protected function traceAccept(): void { echo "% Accepted.\n"; } protected function traceReduce($n): void { echo '% Reduce by (' . $n . ') ' . $this->productions[$n] . "\n"; } protected function tracePop($state): void { echo '% Recovering, uncovered state ' . $state . "\n"; } protected function traceDiscard($symbol): void { echo '% Discard ' . $this->symbolToName[$symbol] . "\n"; } */ /* * Helper functions invoked by semantic actions */ /** * Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions. * * @param Node\Stmt[] $stmts * @return Node\Stmt[] */ protected function handleNamespaces(array $stmts): array { $hasErrored = false; $style = $this->getNamespacingStyle($stmts); if (null === $style) { // not namespaced, nothing to do return $stmts; } if ('brace' === $style) { // For braced namespaces we only have to check that there are no invalid statements between the namespaces $afterFirstNamespace = false; foreach ($stmts as $stmt) { if ($stmt instanceof Node\Stmt\Namespace_) { $afterFirstNamespace = true; } elseif (!$stmt instanceof Node\Stmt\HaltCompiler && !$stmt instanceof Node\Stmt\Nop && $afterFirstNamespace && !$hasErrored) { $this->emitError(new Error( 'No code may exist outside of namespace {}', $stmt->getAttributes())); $hasErrored = true; // Avoid one error for every statement } } return $stmts; } else { // For semicolon namespaces we have to move the statements after a namespace declaration into ->stmts $resultStmts = []; $targetStmts = &$resultStmts; $lastNs = null; foreach ($stmts as $stmt) { if ($stmt instanceof Node\Stmt\Namespace_) { if ($lastNs !== null) { $this->fixupNamespaceAttributes($lastNs); } if ($stmt->stmts === null) { $stmt->stmts = []; $targetStmts = &$stmt->stmts; $resultStmts[] = $stmt; } else { // This handles the invalid case of mixed style namespaces $resultStmts[] = $stmt; $targetStmts = &$resultStmts; } $lastNs = $stmt; } elseif ($stmt instanceof Node\Stmt\HaltCompiler) { // __halt_compiler() is not moved into the namespace $resultStmts[] = $stmt; } else { $targetStmts[] = $stmt; } } if ($lastNs !== null) { $this->fixupNamespaceAttributes($lastNs); } return $resultStmts; } } private function fixupNamespaceAttributes(Node\Stmt\Namespace_ $stmt): void { // We moved the statements into the namespace node, as such the end of the namespace node // needs to be extended to the end of the statements. if (empty($stmt->stmts)) { return; } // We only move the builtin end attributes here. This is the best we can do with the // knowledge we have. $endAttributes = ['endLine', 'endFilePos', 'endTokenPos']; $lastStmt = $stmt->stmts[count($stmt->stmts) - 1]; foreach ($endAttributes as $endAttribute) { if ($lastStmt->hasAttribute($endAttribute)) { $stmt->setAttribute($endAttribute, $lastStmt->getAttribute($endAttribute)); } } } /** @return array */ private function getNamespaceErrorAttributes(Namespace_ $node): array { $attrs = $node->getAttributes(); // Adjust end attributes to only cover the "namespace" keyword, not the whole namespace. if (isset($attrs['startLine'])) { $attrs['endLine'] = $attrs['startLine']; } if (isset($attrs['startTokenPos'])) { $attrs['endTokenPos'] = $attrs['startTokenPos']; } if (isset($attrs['startFilePos'])) { $attrs['endFilePos'] = $attrs['startFilePos'] + \strlen('namespace') - 1; } return $attrs; } /** * Determine namespacing style (semicolon or brace) * * @param Node[] $stmts Top-level statements. * * @return null|string One of "semicolon", "brace" or null (no namespaces) */ private function getNamespacingStyle(array $stmts): ?string { $style = null; $hasNotAllowedStmts = false; foreach ($stmts as $i => $stmt) { if ($stmt instanceof Node\Stmt\Namespace_) { $currentStyle = null === $stmt->stmts ? 'semicolon' : 'brace'; if (null === $style) { $style = $currentStyle; if ($hasNotAllowedStmts) { $this->emitError(new Error( 'Namespace declaration statement has to be the very first statement in the script', $this->getNamespaceErrorAttributes($stmt) )); } } elseif ($style !== $currentStyle) { $this->emitError(new Error( 'Cannot mix bracketed namespace declarations with unbracketed namespace declarations', $this->getNamespaceErrorAttributes($stmt) )); // Treat like semicolon style for namespace normalization return 'semicolon'; } continue; } /* declare(), __halt_compiler() and nops can be used before a namespace declaration */ if ($stmt instanceof Node\Stmt\Declare_ || $stmt instanceof Node\Stmt\HaltCompiler || $stmt instanceof Node\Stmt\Nop) { continue; } /* There may be a hashbang line at the very start of the file */ if ($i === 0 && $stmt instanceof Node\Stmt\InlineHTML && preg_match('/\A#!.*\r?\n\z/', $stmt->value)) { continue; } /* Everything else if forbidden before namespace declarations */ $hasNotAllowedStmts = true; } return $style; } /** @return Name|Identifier */ protected function handleBuiltinTypes(Name $name) { if (!$name->isUnqualified()) { return $name; } $lowerName = $name->toLowerString(); if (!$this->phpVersion->supportsBuiltinType($lowerName)) { return $name; } return new Node\Identifier($lowerName, $name->getAttributes()); } /** * Get combined start and end attributes at a stack location * * @param int $stackPos Stack location * * @return array Combined start and end attributes */ protected function getAttributesAt(int $stackPos): array { return $this->getAttributes($this->tokenStartStack[$stackPos], $this->tokenEndStack[$stackPos]); } protected function getFloatCastKind(string $cast): int { $cast = strtolower($cast); if (strpos($cast, 'float') !== false) { return Double::KIND_FLOAT; } if (strpos($cast, 'real') !== false) { return Double::KIND_REAL; } return Double::KIND_DOUBLE; } protected function getIntCastKind(string $cast): int { $cast = strtolower($cast); if (strpos($cast, 'integer') !== false) { return Expr\Cast\Int_::KIND_INTEGER; } return Expr\Cast\Int_::KIND_INT; } protected function getBoolCastKind(string $cast): int { $cast = strtolower($cast); if (strpos($cast, 'boolean') !== false) { return Expr\Cast\Bool_::KIND_BOOLEAN; } return Expr\Cast\Bool_::KIND_BOOL; } protected function getStringCastKind(string $cast): int { $cast = strtolower($cast); if (strpos($cast, 'binary') !== false) { return Expr\Cast\String_::KIND_BINARY; } return Expr\Cast\String_::KIND_STRING; } /** @param array $attributes */ protected function parseLNumber(string $str, array $attributes, bool $allowInvalidOctal = false): Int_ { try { return Int_::fromString($str, $attributes, $allowInvalidOctal); } catch (Error $error) { $this->emitError($error); // Use dummy value return new Int_(0, $attributes); } } /** * Parse a T_NUM_STRING token into either an integer or string node. * * @param string $str Number string * @param array $attributes Attributes * * @return Int_|String_ Integer or string node. */ protected function parseNumString(string $str, array $attributes) { if (!preg_match('/^(?:0|-?[1-9][0-9]*)$/', $str)) { return new String_($str, $attributes); } $num = +$str; if (!is_int($num)) { return new String_($str, $attributes); } return new Int_($num, $attributes); } /** @param array $attributes */ protected function stripIndentation( string $string, int $indentLen, string $indentChar, bool $newlineAtStart, bool $newlineAtEnd, array $attributes ): string { if ($indentLen === 0) { return $string; } $start = $newlineAtStart ? '(?:(?<=\n)|\A)' : '(?<=\n)'; $end = $newlineAtEnd ? '(?:(?=[\r\n])|\z)' : '(?=[\r\n])'; $regex = '/' . $start . '([ \t]*)(' . $end . ')?/'; return preg_replace_callback( $regex, function ($matches) use ($indentLen, $indentChar, $attributes) { $prefix = substr($matches[1], 0, $indentLen); if (false !== strpos($prefix, $indentChar === " " ? "\t" : " ")) { $this->emitError(new Error( 'Invalid indentation - tabs and spaces cannot be mixed', $attributes )); } elseif (strlen($prefix) < $indentLen && !isset($matches[2])) { $this->emitError(new Error( 'Invalid body indentation level ' . '(expecting an indentation level of at least ' . $indentLen . ')', $attributes )); } return substr($matches[0], strlen($prefix)); }, $string ); } /** * @param string|(Expr|InterpolatedStringPart)[] $contents * @param array $attributes * @param array $endTokenAttributes */ protected function parseDocString( string $startToken, $contents, string $endToken, array $attributes, array $endTokenAttributes, bool $parseUnicodeEscape ): Expr { $kind = strpos($startToken, "'") === false ? String_::KIND_HEREDOC : String_::KIND_NOWDOC; $regex = '/\A[bB]?<<<[ \t]*[\'"]?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)[\'"]?(?:\r\n|\n|\r)\z/'; $result = preg_match($regex, $startToken, $matches); assert($result === 1); $label = $matches[1]; $result = preg_match('/\A[ \t]*/', $endToken, $matches); assert($result === 1); $indentation = $matches[0]; $attributes['kind'] = $kind; $attributes['docLabel'] = $label; $attributes['docIndentation'] = $indentation; $indentHasSpaces = false !== strpos($indentation, " "); $indentHasTabs = false !== strpos($indentation, "\t"); if ($indentHasSpaces && $indentHasTabs) { $this->emitError(new Error( 'Invalid indentation - tabs and spaces cannot be mixed', $endTokenAttributes )); // Proceed processing as if this doc string is not indented $indentation = ''; } $indentLen = \strlen($indentation); $indentChar = $indentHasSpaces ? " " : "\t"; if (\is_string($contents)) { if ($contents === '') { $attributes['rawValue'] = $contents; return new String_('', $attributes); } $contents = $this->stripIndentation( $contents, $indentLen, $indentChar, true, true, $attributes ); $contents = preg_replace('~(\r\n|\n|\r)\z~', '', $contents); $attributes['rawValue'] = $contents; if ($kind === String_::KIND_HEREDOC) { $contents = String_::parseEscapeSequences($contents, null, $parseUnicodeEscape); } return new String_($contents, $attributes); } else { assert(count($contents) > 0); if (!$contents[0] instanceof Node\InterpolatedStringPart) { // If there is no leading encapsed string part, pretend there is an empty one $this->stripIndentation( '', $indentLen, $indentChar, true, false, $contents[0]->getAttributes() ); } $newContents = []; foreach ($contents as $i => $part) { if ($part instanceof Node\InterpolatedStringPart) { $isLast = $i === \count($contents) - 1; $part->value = $this->stripIndentation( $part->value, $indentLen, $indentChar, $i === 0, $isLast, $part->getAttributes() ); if ($isLast) { $part->value = preg_replace('~(\r\n|\n|\r)\z~', '', $part->value); } $part->setAttribute('rawValue', $part->value); $part->value = String_::parseEscapeSequences($part->value, null, $parseUnicodeEscape); if ('' === $part->value) { continue; } } $newContents[] = $part; } return new InterpolatedString($newContents, $attributes); } } protected function createCommentFromToken(Token $token, int $tokenPos): Comment { assert($token->id === \T_COMMENT || $token->id == \T_DOC_COMMENT); return \T_DOC_COMMENT === $token->id ? new Comment\Doc($token->text, $token->line, $token->pos, $tokenPos, $token->getEndLine(), $token->getEndPos() - 1, $tokenPos) : new Comment($token->text, $token->line, $token->pos, $tokenPos, $token->getEndLine(), $token->getEndPos() - 1, $tokenPos); } /** * Get last comment before the given token position, if any */ protected function getCommentBeforeToken(int $tokenPos): ?Comment { while (--$tokenPos >= 0) { $token = $this->tokens[$tokenPos]; if (!isset($this->dropTokens[$token->id])) { break; } if ($token->id === \T_COMMENT || $token->id === \T_DOC_COMMENT) { return $this->createCommentFromToken($token, $tokenPos); } } return null; } /** * Create a zero-length nop to capture preceding comments, if any. */ protected function maybeCreateZeroLengthNop(int $tokenPos): ?Nop { $comment = $this->getCommentBeforeToken($tokenPos); if ($comment === null) { return null; } $commentEndLine = $comment->getEndLine(); $commentEndFilePos = $comment->getEndFilePos(); $commentEndTokenPos = $comment->getEndTokenPos(); $attributes = [ 'startLine' => $commentEndLine, 'endLine' => $commentEndLine, 'startFilePos' => $commentEndFilePos + 1, 'endFilePos' => $commentEndFilePos, 'startTokenPos' => $commentEndTokenPos + 1, 'endTokenPos' => $commentEndTokenPos, ]; return new Nop($attributes); } protected function maybeCreateNop(int $tokenStartPos, int $tokenEndPos): ?Nop { if ($this->getCommentBeforeToken($tokenStartPos) === null) { return null; } return new Nop($this->getAttributes($tokenStartPos, $tokenEndPos)); } protected function handleHaltCompiler(): string { // Prevent the lexer from returning any further tokens. $nextToken = $this->tokens[$this->tokenPos + 1]; $this->tokenPos = \count($this->tokens) - 2; // Return text after __halt_compiler. return $nextToken->id === \T_INLINE_HTML ? $nextToken->text : ''; } protected function inlineHtmlHasLeadingNewline(int $stackPos): bool { $tokenPos = $this->tokenStartStack[$stackPos]; $token = $this->tokens[$tokenPos]; assert($token->id == \T_INLINE_HTML); if ($tokenPos > 0) { $prevToken = $this->tokens[$tokenPos - 1]; assert($prevToken->id == \T_CLOSE_TAG); return false !== strpos($prevToken->text, "\n") || false !== strpos($prevToken->text, "\r"); } return true; } /** * @return array */ protected function createEmptyElemAttributes(int $tokenPos): array { return $this->getAttributesForToken($tokenPos); } protected function fixupArrayDestructuring(Array_ $node): Expr\List_ { $this->createdArrays->offsetUnset($node); return new Expr\List_(array_map(function (Node\ArrayItem $item) { if ($item->value instanceof Expr\Error) { // We used Error as a placeholder for empty elements, which are legal for destructuring. return null; } if ($item->value instanceof Array_) { return new Node\ArrayItem( $this->fixupArrayDestructuring($item->value), $item->key, $item->byRef, $item->getAttributes()); } return $item; }, $node->items), ['kind' => Expr\List_::KIND_ARRAY] + $node->getAttributes()); } protected function postprocessList(Expr\List_ $node): void { foreach ($node->items as $i => $item) { if ($item->value instanceof Expr\Error) { // We used Error as a placeholder for empty elements, which are legal for destructuring. $node->items[$i] = null; } } } /** @param ElseIf_|Else_ $node */ protected function fixupAlternativeElse($node): void { // Make sure a trailing nop statement carrying comments is part of the node. $numStmts = \count($node->stmts); if ($numStmts !== 0 && $node->stmts[$numStmts - 1] instanceof Nop) { $nopAttrs = $node->stmts[$numStmts - 1]->getAttributes(); if (isset($nopAttrs['endLine'])) { $node->setAttribute('endLine', $nopAttrs['endLine']); } if (isset($nopAttrs['endFilePos'])) { $node->setAttribute('endFilePos', $nopAttrs['endFilePos']); } if (isset($nopAttrs['endTokenPos'])) { $node->setAttribute('endTokenPos', $nopAttrs['endTokenPos']); } } } protected function checkClassModifier(int $a, int $b, int $modifierPos): void { try { Modifiers::verifyClassModifier($a, $b); } catch (Error $error) { $error->setAttributes($this->getAttributesAt($modifierPos)); $this->emitError($error); } } protected function checkModifier(int $a, int $b, int $modifierPos): void { // Jumping through some hoops here because verifyModifier() is also used elsewhere try { Modifiers::verifyModifier($a, $b); } catch (Error $error) { $error->setAttributes($this->getAttributesAt($modifierPos)); $this->emitError($error); } } protected function checkParam(Param $node): void { if ($node->variadic && null !== $node->default) { $this->emitError(new Error( 'Variadic parameter cannot have a default value', $node->default->getAttributes() )); } if ($node->type instanceof Identifier && $node->type->name === 'void') { $this->emitError(new Error( 'void cannot be used as a parameter type', $node->type->getAttributes() )); } } protected function checkTryCatch(TryCatch $node): void { if (empty($node->catches) && null === $node->finally) { $this->emitError(new Error( 'Cannot use try without catch or finally', $node->getAttributes() )); } } protected function checkNamespace(Namespace_ $node): void { if (null !== $node->stmts) { foreach ($node->stmts as $stmt) { if ($stmt instanceof Namespace_) { $this->emitError(new Error( 'Namespace declarations cannot be nested', $stmt->getAttributes() )); } } } } private function checkClassName(?Identifier $name, int $namePos): void { if (null !== $name && $name->isSpecialClassName()) { $this->emitError(new Error( sprintf('Cannot use \'%s\' as class name as it is reserved', $name), $this->getAttributesAt($namePos) )); } } /** @param Name[] $interfaces */ private function checkImplementedInterfaces(array $interfaces): void { foreach ($interfaces as $interface) { if ($interface->isSpecialClassName()) { $this->emitError(new Error( sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface), $interface->getAttributes() )); } } } protected function checkClass(Class_ $node, int $namePos): void { $this->checkClassName($node->name, $namePos); if ($node->extends && $node->extends->isSpecialClassName()) { $this->emitError(new Error( sprintf('Cannot use \'%s\' as class name as it is reserved', $node->extends), $node->extends->getAttributes() )); } $this->checkImplementedInterfaces($node->implements); } protected function checkInterface(Interface_ $node, int $namePos): void { $this->checkClassName($node->name, $namePos); $this->checkImplementedInterfaces($node->extends); } protected function checkEnum(Enum_ $node, int $namePos): void { $this->checkClassName($node->name, $namePos); $this->checkImplementedInterfaces($node->implements); } protected function checkClassMethod(ClassMethod $node, int $modifierPos): void { if ($node->flags & Modifiers::STATIC) { switch ($node->name->toLowerString()) { case '__construct': $this->emitError(new Error( sprintf('Constructor %s() cannot be static', $node->name), $this->getAttributesAt($modifierPos))); break; case '__destruct': $this->emitError(new Error( sprintf('Destructor %s() cannot be static', $node->name), $this->getAttributesAt($modifierPos))); break; case '__clone': $this->emitError(new Error( sprintf('Clone method %s() cannot be static', $node->name), $this->getAttributesAt($modifierPos))); break; } } if ($node->flags & Modifiers::READONLY) { $this->emitError(new Error( sprintf('Method %s() cannot be readonly', $node->name), $this->getAttributesAt($modifierPos))); } } protected function checkClassConst(ClassConst $node, int $modifierPos): void { foreach ([Modifiers::STATIC, Modifiers::ABSTRACT, Modifiers::READONLY] as $modifier) { if ($node->flags & $modifier) { $this->emitError(new Error( "Cannot use '" . Modifiers::toString($modifier) . "' as constant modifier", $this->getAttributesAt($modifierPos))); } } } protected function checkUseUse(UseItem $node, int $namePos): void { if ($node->alias && $node->alias->isSpecialClassName()) { $this->emitError(new Error( sprintf( 'Cannot use %s as %s because \'%2$s\' is a special class name', $node->name, $node->alias ), $this->getAttributesAt($namePos) )); } } protected function checkPropertyHooksForMultiProperty(Property $property, int $hookPos): void { if (count($property->props) > 1) { $this->emitError(new Error( 'Cannot use hooks when declaring multiple properties', $this->getAttributesAt($hookPos))); } } /** @param PropertyHook[] $hooks */ protected function checkEmptyPropertyHookList(array $hooks, int $hookPos): void { if (empty($hooks)) { $this->emitError(new Error( 'Property hook list cannot be empty', $this->getAttributesAt($hookPos))); } } protected function checkPropertyHook(PropertyHook $hook, ?int $paramListPos): void { $name = $hook->name->toLowerString(); if ($name !== 'get' && $name !== 'set') { $this->emitError(new Error( 'Unknown hook "' . $hook->name . '", expected "get" or "set"', $hook->name->getAttributes())); } if ($name === 'get' && $paramListPos !== null) { $this->emitError(new Error( 'get hook must not have a parameter list', $this->getAttributesAt($paramListPos))); } } protected function checkPropertyHookModifiers(int $a, int $b, int $modifierPos): void { try { Modifiers::verifyModifier($a, $b); } catch (Error $error) { $error->setAttributes($this->getAttributesAt($modifierPos)); $this->emitError($error); } if ($b != Modifiers::FINAL) { $this->emitError(new Error( 'Cannot use the ' . Modifiers::toString($b) . ' modifier on a property hook', $this->getAttributesAt($modifierPos))); } } protected function checkConstantAttributes(Const_ $node): void { if ($node->attrGroups !== [] && count($node->consts) > 1) { $this->emitError(new Error( 'Cannot use attributes on multiple constants at once', $node->getAttributes())); } } protected function checkPipeOperatorParentheses(Expr $node): void { if ($node instanceof Expr\ArrowFunction && !$this->parenthesizedArrowFunctions->offsetExists($node)) { $this->emitError(new Error( 'Arrow functions on the right hand side of |> must be parenthesized', $node->getAttributes())); } } /** * @param Property|Param $node */ protected function addPropertyNameToHooks(Node $node): void { if ($node instanceof Property) { $name = $node->props[0]->name->toString(); } else { $name = $node->var->name; } foreach ($node->hooks as $hook) { $hook->setAttribute('propertyName', $name); } } /** @param array $args */ private function isSimpleExit(array $args): bool { if (\count($args) === 0) { return true; } if (\count($args) === 1) { $arg = $args[0]; return $arg instanceof Arg && $arg->name === null && $arg->byRef === false && $arg->unpack === false; } return false; } /** * @param array $args * @param array $attrs */ protected function createExitExpr(string $name, int $namePos, array $args, array $attrs): Expr { if ($this->isSimpleExit($args)) { // Create Exit node for backwards compatibility. $attrs['kind'] = strtolower($name) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE; return new Expr\Exit_(\count($args) === 1 ? $args[0]->value : null, $attrs); } return new Expr\FuncCall(new Name($name, $this->getAttributesAt($namePos)), $args, $attrs); } /** * Creates the token map. * * The token map maps the PHP internal token identifiers * to the identifiers used by the Parser. Additionally it * maps T_OPEN_TAG_WITH_ECHO to T_ECHO and T_CLOSE_TAG to ';'. * * @return array The token map */ protected function createTokenMap(): array { $tokenMap = []; // Single-char tokens use an identity mapping. for ($i = 0; $i < 256; ++$i) { $tokenMap[$i] = $i; } foreach ($this->symbolToName as $name) { if ($name[0] === 'T') { $tokenMap[\constant($name)] = constant(static::class . '::' . $name); } } // T_OPEN_TAG_WITH_ECHO with dropped T_OPEN_TAG results in T_ECHO $tokenMap[\T_OPEN_TAG_WITH_ECHO] = static::T_ECHO; // T_CLOSE_TAG is equivalent to ';' $tokenMap[\T_CLOSE_TAG] = ord(';'); // We have created a map from PHP token IDs to external symbol IDs. // Now map them to the internal symbol ID. $fullTokenMap = []; foreach ($tokenMap as $phpToken => $extSymbol) { $intSymbol = $this->tokenToSymbol[$extSymbol]; if ($intSymbol === $this->invalidSymbol) { continue; } $fullTokenMap[$phpToken] = $intSymbol; } return $fullTokenMap; } } ================================================ FILE: lib/PhpParser/ParserFactory.php ================================================ isHostVersion()) { $lexer = new Lexer(); } else { $lexer = new Lexer\Emulative($version); } if ($version->id >= 80000) { return new Php8($lexer, $version); } return new Php7($lexer, $version); } /** * Create a parser targeting the newest version supported by this library. Code for older * versions will be accepted if there have been no relevant backwards-compatibility breaks in * PHP. */ public function createForNewestSupportedVersion(): Parser { return $this->createForVersion(PhpVersion::getNewestSupported()); } /** * Create a parser targeting the host PHP version, that is the PHP version we're currently * running on. This parser will not use any token emulation. */ public function createForHostVersion(): Parser { return $this->createForVersion(PhpVersion::getHostVersion()); } } ================================================ FILE: lib/PhpParser/PhpVersion.php ================================================ 50100, 'callable' => 50400, 'bool' => 70000, 'int' => 70000, 'float' => 70000, 'string' => 70000, 'iterable' => 70100, 'void' => 70100, 'object' => 70200, 'null' => 80000, 'false' => 80000, 'mixed' => 80000, 'never' => 80100, 'true' => 80200, ]; private function __construct(int $id) { $this->id = $id; } /** * Create a PhpVersion object from major and minor version components. */ public static function fromComponents(int $major, int $minor): self { return new self($major * 10000 + $minor * 100); } /** * Get the newest PHP version supported by this library. Support for this version may be partial, * if it is still under development. */ public static function getNewestSupported(): self { return self::fromComponents(8, 5); } /** * Get the host PHP version, that is the PHP version we're currently running on. */ public static function getHostVersion(): self { return self::fromComponents(\PHP_MAJOR_VERSION, \PHP_MINOR_VERSION); } /** * Parse the version from a string like "8.1". */ public static function fromString(string $version): self { if (!preg_match('/^(\d+)\.(\d+)/', $version, $matches)) { throw new \LogicException("Invalid PHP version \"$version\""); } return self::fromComponents((int) $matches[1], (int) $matches[2]); } /** * Check whether two versions are the same. */ public function equals(PhpVersion $other): bool { return $this->id === $other->id; } /** * Check whether this version is greater than or equal to the argument. */ public function newerOrEqual(PhpVersion $other): bool { return $this->id >= $other->id; } /** * Check whether this version is older than the argument. */ public function older(PhpVersion $other): bool { return $this->id < $other->id; } /** * Check whether this is the host PHP version. */ public function isHostVersion(): bool { return $this->equals(self::getHostVersion()); } /** * Check whether this PHP version supports the given builtin type. Type name must be lowercase. */ public function supportsBuiltinType(string $type): bool { $minVersion = self::BUILTIN_TYPE_VERSIONS[$type] ?? null; return $minVersion !== null && $this->id >= $minVersion; } /** * Whether this version supports [] array literals. */ public function supportsShortArraySyntax(): bool { return $this->id >= 50400; } /** * Whether this version supports [] for destructuring. */ public function supportsShortArrayDestructuring(): bool { return $this->id >= 70100; } /** * Whether this version supports flexible heredoc/nowdoc. */ public function supportsFlexibleHeredoc(): bool { return $this->id >= 70300; } /** * Whether this version supports trailing commas in parameter lists. */ public function supportsTrailingCommaInParamList(): bool { return $this->id >= 80000; } /** * Whether this version allows "$var =& new Obj". */ public function allowsAssignNewByReference(): bool { return $this->id < 70000; } /** * Whether this version allows invalid octals like "08". */ public function allowsInvalidOctals(): bool { return $this->id < 70000; } /** * Whether this version allows DEL (\x7f) to occur in identifiers. */ public function allowsDelInIdentifiers(): bool { return $this->id < 70100; } /** * Whether this version supports yield in expression context without parentheses. */ public function supportsYieldWithoutParentheses(): bool { return $this->id >= 70000; } /** * Whether this version supports unicode escape sequences in strings. */ public function supportsUnicodeEscapes(): bool { return $this->id >= 70000; } /* * Whether this version supports attributes. */ public function supportsAttributes(): bool { return $this->id >= 80000; } public function supportsNewDereferenceWithoutParentheses(): bool { return $this->id >= 80400; } } ================================================ FILE: lib/PhpParser/PrettyPrinter/Standard.php ================================================ pAttrGroups($node->attrGroups, $this->phpVersion->supportsAttributes()) . $this->pModifiers($node->flags) . ($node->type ? $this->p($node->type) . ' ' : '') . ($node->byRef ? '&' : '') . ($node->variadic ? '...' : '') . $this->p($node->var) . ($node->default ? ' = ' . $this->p($node->default) : '') . ($node->hooks ? ' {' . $this->pStmts($node->hooks) . $this->nl . '}' : ''); } protected function pArg(Node\Arg $node): string { return ($node->name ? $node->name->toString() . ': ' : '') . ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '') . $this->p($node->value); } protected function pVariadicPlaceholder(Node\VariadicPlaceholder $node): string { return '...'; } protected function pConst(Node\Const_ $node): string { return $node->name . ' = ' . $this->p($node->value); } protected function pNullableType(Node\NullableType $node): string { return '?' . $this->p($node->type); } protected function pUnionType(Node\UnionType $node): string { $types = []; foreach ($node->types as $typeNode) { if ($typeNode instanceof Node\IntersectionType) { $types[] = '('. $this->p($typeNode) . ')'; continue; } $types[] = $this->p($typeNode); } return implode('|', $types); } protected function pIntersectionType(Node\IntersectionType $node): string { return $this->pImplode($node->types, '&'); } protected function pIdentifier(Node\Identifier $node): string { return $node->name; } protected function pVarLikeIdentifier(Node\VarLikeIdentifier $node): string { return '$' . $node->name; } protected function pAttribute(Node\Attribute $node): string { return $this->p($node->name) . ($node->args ? '(' . $this->pCommaSeparated($node->args) . ')' : ''); } protected function pAttributeGroup(Node\AttributeGroup $node): string { return '#[' . $this->pCommaSeparated($node->attrs) . ']'; } // Names protected function pName(Name $node): string { return $node->name; } protected function pName_FullyQualified(Name\FullyQualified $node): string { return '\\' . $node->name; } protected function pName_Relative(Name\Relative $node): string { return 'namespace\\' . $node->name; } // Magic Constants protected function pScalar_MagicConst_Class(MagicConst\Class_ $node): string { return '__CLASS__'; } protected function pScalar_MagicConst_Dir(MagicConst\Dir $node): string { return '__DIR__'; } protected function pScalar_MagicConst_File(MagicConst\File $node): string { return '__FILE__'; } protected function pScalar_MagicConst_Function(MagicConst\Function_ $node): string { return '__FUNCTION__'; } protected function pScalar_MagicConst_Line(MagicConst\Line $node): string { return '__LINE__'; } protected function pScalar_MagicConst_Method(MagicConst\Method $node): string { return '__METHOD__'; } protected function pScalar_MagicConst_Namespace(MagicConst\Namespace_ $node): string { return '__NAMESPACE__'; } protected function pScalar_MagicConst_Trait(MagicConst\Trait_ $node): string { return '__TRAIT__'; } protected function pScalar_MagicConst_Property(MagicConst\Property $node): string { return '__PROPERTY__'; } // Scalars private function indentString(string $str): string { return str_replace("\n", $this->nl, $str); } protected function pScalar_String(Scalar\String_ $node): string { $kind = $node->getAttribute('kind', Scalar\String_::KIND_SINGLE_QUOTED); switch ($kind) { case Scalar\String_::KIND_NOWDOC: $label = $node->getAttribute('docLabel'); if ($label && !$this->containsEndLabel($node->value, $label)) { $shouldIdent = $this->phpVersion->supportsFlexibleHeredoc(); $nl = $shouldIdent ? $this->nl : $this->newline; if ($node->value === '') { return "<<<'$label'$nl$label{$this->docStringEndToken}"; } // Make sure trailing \r is not combined with following \n into CRLF. if ($node->value[strlen($node->value) - 1] !== "\r") { $value = $shouldIdent ? $this->indentString($node->value) : $node->value; return "<<<'$label'$nl$value$nl$label{$this->docStringEndToken}"; } } /* break missing intentionally */ // no break case Scalar\String_::KIND_SINGLE_QUOTED: return $this->pSingleQuotedString($node->value); case Scalar\String_::KIND_HEREDOC: $label = $node->getAttribute('docLabel'); $escaped = $this->escapeString($node->value, null); if ($label && !$this->containsEndLabel($escaped, $label)) { $nl = $this->phpVersion->supportsFlexibleHeredoc() ? $this->nl : $this->newline; if ($escaped === '') { return "<<<$label$nl$label{$this->docStringEndToken}"; } return "<<<$label$nl$escaped$nl$label{$this->docStringEndToken}"; } /* break missing intentionally */ // no break case Scalar\String_::KIND_DOUBLE_QUOTED: return '"' . $this->escapeString($node->value, '"') . '"'; } throw new \Exception('Invalid string kind'); } protected function pScalar_InterpolatedString(Scalar\InterpolatedString $node): string { if ($node->getAttribute('kind') === Scalar\String_::KIND_HEREDOC) { $label = $node->getAttribute('docLabel'); if ($label && !$this->encapsedContainsEndLabel($node->parts, $label)) { $nl = $this->phpVersion->supportsFlexibleHeredoc() ? $this->nl : $this->newline; if (count($node->parts) === 1 && $node->parts[0] instanceof Node\InterpolatedStringPart && $node->parts[0]->value === '' ) { return "<<<$label$nl$label{$this->docStringEndToken}"; } return "<<<$label$nl" . $this->pEncapsList($node->parts, null) . "$nl$label{$this->docStringEndToken}"; } } return '"' . $this->pEncapsList($node->parts, '"') . '"'; } protected function pScalar_Int(Scalar\Int_ $node): string { if ($node->getAttribute('shouldPrintRawValue') === true) { return $node->getAttribute('rawValue'); } if ($node->value === -\PHP_INT_MAX - 1) { // PHP_INT_MIN cannot be represented as a literal, // because the sign is not part of the literal return '(-' . \PHP_INT_MAX . '-1)'; } $kind = $node->getAttribute('kind', Scalar\Int_::KIND_DEC); if (Scalar\Int_::KIND_DEC === $kind) { return (string) $node->value; } if ($node->value < 0) { $sign = '-'; $str = (string) -$node->value; } else { $sign = ''; $str = (string) $node->value; } switch ($kind) { case Scalar\Int_::KIND_BIN: return $sign . '0b' . base_convert($str, 10, 2); case Scalar\Int_::KIND_OCT: return $sign . '0' . base_convert($str, 10, 8); case Scalar\Int_::KIND_HEX: return $sign . '0x' . base_convert($str, 10, 16); } throw new \Exception('Invalid number kind'); } protected function pScalar_Float(Scalar\Float_ $node): string { if (!is_finite($node->value)) { if ($node->value === \INF) { return '1.0E+1000'; } if ($node->value === -\INF) { return '-1.0E+1000'; } else { return '\NAN'; } } // Try to find a short full-precision representation $stringValue = sprintf('%.16G', $node->value); if ($node->value !== (float) $stringValue) { $stringValue = sprintf('%.17G', $node->value); } // %G is locale dependent and there exists no locale-independent alternative. We don't want // mess with switching locales here, so let's assume that a comma is the only non-standard // decimal separator we may encounter... $stringValue = str_replace(',', '.', $stringValue); // ensure that number is really printed as float return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue; } // Assignments protected function pExpr_Assign(Expr\Assign $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\Assign::class, $this->p($node->var) . ' = ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignRef(Expr\AssignRef $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\AssignRef::class, $this->p($node->var) . ' =& ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_Plus(AssignOp\Plus $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\Plus::class, $this->p($node->var) . ' += ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_Minus(AssignOp\Minus $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\Minus::class, $this->p($node->var) . ' -= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_Mul(AssignOp\Mul $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\Mul::class, $this->p($node->var) . ' *= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_Div(AssignOp\Div $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\Div::class, $this->p($node->var) . ' /= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_Concat(AssignOp\Concat $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\Concat::class, $this->p($node->var) . ' .= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_Mod(AssignOp\Mod $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\Mod::class, $this->p($node->var) . ' %= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\BitwiseAnd::class, $this->p($node->var) . ' &= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\BitwiseOr::class, $this->p($node->var) . ' |= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\BitwiseXor::class, $this->p($node->var) . ' ^= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\ShiftLeft::class, $this->p($node->var) . ' <<= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\ShiftRight::class, $this->p($node->var) . ' >>= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_Pow(AssignOp\Pow $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\Pow::class, $this->p($node->var) . ' **= ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_AssignOp_Coalesce(AssignOp\Coalesce $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(AssignOp\Coalesce::class, $this->p($node->var) . ' ??= ', $node->expr, $precedence, $lhsPrecedence); } // Binary expressions protected function pExpr_BinaryOp_Plus(BinaryOp\Plus $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Plus::class, $node->left, ' + ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Minus(BinaryOp\Minus $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Minus::class, $node->left, ' - ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Mul(BinaryOp\Mul $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Mul::class, $node->left, ' * ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Div(BinaryOp\Div $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Div::class, $node->left, ' / ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Concat(BinaryOp\Concat $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Concat::class, $node->left, ' . ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Mod(BinaryOp\Mod $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Mod::class, $node->left, ' % ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\BooleanAnd::class, $node->left, ' && ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\BooleanOr::class, $node->left, ' || ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\BitwiseAnd::class, $node->left, ' & ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\BitwiseOr::class, $node->left, ' | ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\BitwiseXor::class, $node->left, ' ^ ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\ShiftLeft::class, $node->left, ' << ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\ShiftRight::class, $node->left, ' >> ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Pow(BinaryOp\Pow $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Pow::class, $node->left, ' ** ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\LogicalAnd::class, $node->left, ' and ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\LogicalOr::class, $node->left, ' or ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\LogicalXor::class, $node->left, ' xor ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Equal(BinaryOp\Equal $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Equal::class, $node->left, ' == ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\NotEqual::class, $node->left, ' != ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Identical(BinaryOp\Identical $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Identical::class, $node->left, ' === ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\NotIdentical::class, $node->left, ' !== ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Spaceship::class, $node->left, ' <=> ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Greater(BinaryOp\Greater $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Greater::class, $node->left, ' > ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\GreaterOrEqual::class, $node->left, ' >= ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Smaller::class, $node->left, ' < ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\SmallerOrEqual::class, $node->left, ' <= ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp(BinaryOp\Coalesce::class, $node->left, ' ?? ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_BinaryOp_Pipe(BinaryOp\Pipe $node, int $precedence, int $lhsPrecedence): string { if ($node->right instanceof Expr\ArrowFunction) { // Force parentheses around arrow functions. $lhsPrecedence = $this->precedenceMap[Expr\ArrowFunction::class][0]; } return $this->pInfixOp(BinaryOp\Pipe::class, $node->left, ' |> ', $node->right, $precedence, $lhsPrecedence); } protected function pExpr_Instanceof(Expr\Instanceof_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPostfixOp( Expr\Instanceof_::class, $node->expr, ' instanceof ' . $this->pNewOperand($node->class), $precedence, $lhsPrecedence); } // Unary expressions protected function pExpr_BooleanNot(Expr\BooleanNot $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\BooleanNot::class, '!', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_BitwiseNot(Expr\BitwiseNot $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\BitwiseNot::class, '~', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_UnaryMinus(Expr\UnaryMinus $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\UnaryMinus::class, '-', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_UnaryPlus(Expr\UnaryPlus $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_PreInc(Expr\PreInc $node): string { return '++' . $this->p($node->var); } protected function pExpr_PreDec(Expr\PreDec $node): string { return '--' . $this->p($node->var); } protected function pExpr_PostInc(Expr\PostInc $node): string { return $this->p($node->var) . '++'; } protected function pExpr_PostDec(Expr\PostDec $node): string { return $this->p($node->var) . '--'; } protected function pExpr_ErrorSuppress(Expr\ErrorSuppress $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\ErrorSuppress::class, '@', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_YieldFrom(Expr\YieldFrom $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\YieldFrom::class, 'yield from ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_Print(Expr\Print_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\Print_::class, 'print ', $node->expr, $precedence, $lhsPrecedence); } // Casts protected function pExpr_Cast_Int(Cast\Int_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Cast\Int_::class, '(int) ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_Cast_Double(Cast\Double $node, int $precedence, int $lhsPrecedence): string { $kind = $node->getAttribute('kind', Cast\Double::KIND_DOUBLE); if ($kind === Cast\Double::KIND_DOUBLE) { $cast = '(double)'; } elseif ($kind === Cast\Double::KIND_FLOAT) { $cast = '(float)'; } else { assert($kind === Cast\Double::KIND_REAL); $cast = '(real)'; } return $this->pPrefixOp(Cast\Double::class, $cast . ' ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_Cast_String(Cast\String_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Cast\String_::class, '(string) ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_Cast_Array(Cast\Array_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Cast\Array_::class, '(array) ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_Cast_Object(Cast\Object_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Cast\Object_::class, '(object) ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_Cast_Bool(Cast\Bool_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Cast\Bool_::class, '(bool) ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_Cast_Unset(Cast\Unset_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Cast\Unset_::class, '(unset) ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_Cast_Void(Cast\Void_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Cast\Void_::class, '(void) ', $node->expr, $precedence, $lhsPrecedence); } // Function calls and similar constructs protected function pExpr_FuncCall(Expr\FuncCall $node): string { return $this->pCallLhs($node->name) . '(' . $this->pMaybeMultiline($node->args) . ')'; } protected function pExpr_MethodCall(Expr\MethodCall $node): string { return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name) . '(' . $this->pMaybeMultiline($node->args) . ')'; } protected function pExpr_NullsafeMethodCall(Expr\NullsafeMethodCall $node): string { return $this->pDereferenceLhs($node->var) . '?->' . $this->pObjectProperty($node->name) . '(' . $this->pMaybeMultiline($node->args) . ')'; } protected function pExpr_StaticCall(Expr\StaticCall $node): string { return $this->pStaticDereferenceLhs($node->class) . '::' . ($node->name instanceof Expr ? ($node->name instanceof Expr\Variable ? $this->p($node->name) : '{' . $this->p($node->name) . '}') : $node->name) . '(' . $this->pMaybeMultiline($node->args) . ')'; } protected function pExpr_Empty(Expr\Empty_ $node): string { return 'empty(' . $this->p($node->expr) . ')'; } protected function pExpr_Isset(Expr\Isset_ $node): string { return 'isset(' . $this->pCommaSeparated($node->vars) . ')'; } protected function pExpr_Eval(Expr\Eval_ $node): string { return 'eval(' . $this->p($node->expr) . ')'; } protected function pExpr_Include(Expr\Include_ $node, int $precedence, int $lhsPrecedence): string { static $map = [ Expr\Include_::TYPE_INCLUDE => 'include', Expr\Include_::TYPE_INCLUDE_ONCE => 'include_once', Expr\Include_::TYPE_REQUIRE => 'require', Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once', ]; return $this->pPrefixOp(Expr\Include_::class, $map[$node->type] . ' ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_List(Expr\List_ $node): string { $syntax = $node->getAttribute('kind', $this->phpVersion->supportsShortArrayDestructuring() ? Expr\List_::KIND_ARRAY : Expr\List_::KIND_LIST); if ($syntax === Expr\List_::KIND_ARRAY) { return '[' . $this->pMaybeMultiline($node->items, true) . ']'; } else { return 'list(' . $this->pMaybeMultiline($node->items, true) . ')'; } } // Other protected function pExpr_Error(Expr\Error $node): string { throw new \LogicException('Cannot pretty-print AST with Error nodes'); } protected function pExpr_Variable(Expr\Variable $node): string { if ($node->name instanceof Expr) { return '${' . $this->p($node->name) . '}'; } else { return '$' . $node->name; } } protected function pExpr_Array(Expr\Array_ $node): string { $syntax = $node->getAttribute('kind', $this->shortArraySyntax ? Expr\Array_::KIND_SHORT : Expr\Array_::KIND_LONG); if ($syntax === Expr\Array_::KIND_SHORT) { return '[' . $this->pMaybeMultiline($node->items, true) . ']'; } else { return 'array(' . $this->pMaybeMultiline($node->items, true) . ')'; } } protected function pKey(?Node $node): string { if ($node === null) { return ''; } // => is not really an operator and does not typically participate in precedence resolution. // However, there is an exception if yield expressions with keys are involved: // [yield $a => $b] is interpreted as [(yield $a => $b)], so we need to ensure that // [(yield $a) => $b] is printed with parentheses. We approximate this by lowering the LHS // precedence to that of yield (which will also print unnecessary parentheses for rare low // precedence unary operators like include). $yieldPrecedence = $this->precedenceMap[Expr\Yield_::class][0]; return $this->p($node, self::MAX_PRECEDENCE, $yieldPrecedence) . ' => '; } protected function pArrayItem(Node\ArrayItem $node): string { return $this->pKey($node->key) . ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '') . $this->p($node->value); } protected function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node): string { return $this->pDereferenceLhs($node->var) . '[' . (null !== $node->dim ? $this->p($node->dim) : '') . ']'; } protected function pExpr_ConstFetch(Expr\ConstFetch $node): string { return $this->p($node->name); } protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node): string { return $this->pStaticDereferenceLhs($node->class) . '::' . $this->pObjectProperty($node->name); } protected function pExpr_PropertyFetch(Expr\PropertyFetch $node): string { return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name); } protected function pExpr_NullsafePropertyFetch(Expr\NullsafePropertyFetch $node): string { return $this->pDereferenceLhs($node->var) . '?->' . $this->pObjectProperty($node->name); } protected function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node): string { return $this->pStaticDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name); } protected function pExpr_ShellExec(Expr\ShellExec $node): string { return '`' . $this->pEncapsList($node->parts, '`') . '`'; } protected function pExpr_Closure(Expr\Closure $node): string { return $this->pAttrGroups($node->attrGroups, true) . $this->pStatic($node->static) . 'function ' . ($node->byRef ? '&' : '') . '(' . $this->pParams($node->params) . ')' . (!empty($node->uses) ? ' use (' . $this->pCommaSeparated($node->uses) . ')' : '') . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . ' {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pExpr_Match(Expr\Match_ $node): string { return 'match (' . $this->p($node->cond) . ') {' . $this->pCommaSeparatedMultiline($node->arms, true) . $this->nl . '}'; } protected function pMatchArm(Node\MatchArm $node): string { $result = ''; if ($node->conds) { for ($i = 0, $c = \count($node->conds); $i + 1 < $c; $i++) { $result .= $this->p($node->conds[$i]) . ', '; } $result .= $this->pKey($node->conds[$i]); } else { $result = 'default => '; } return $result . $this->p($node->body); } protected function pExpr_ArrowFunction(Expr\ArrowFunction $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp( Expr\ArrowFunction::class, $this->pAttrGroups($node->attrGroups, true) . $this->pStatic($node->static) . 'fn' . ($node->byRef ? '&' : '') . '(' . $this->pParams($node->params) . ')' . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . ' => ', $node->expr, $precedence, $lhsPrecedence); } protected function pClosureUse(Node\ClosureUse $node): string { return ($node->byRef ? '&' : '') . $this->p($node->var); } protected function pExpr_New(Expr\New_ $node): string { if ($node->class instanceof Stmt\Class_) { $args = $node->args ? '(' . $this->pMaybeMultiline($node->args) . ')' : ''; return 'new ' . $this->pClassCommon($node->class, $args); } return 'new ' . $this->pNewOperand($node->class) . '(' . $this->pMaybeMultiline($node->args) . ')'; } protected function pExpr_Clone(Expr\Clone_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\Clone_::class, 'clone ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_Ternary(Expr\Ternary $node, int $precedence, int $lhsPrecedence): string { // a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator. // this is okay because the part between ? and : never needs parentheses. return $this->pInfixOp(Expr\Ternary::class, $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else, $precedence, $lhsPrecedence ); } protected function pExpr_Exit(Expr\Exit_ $node): string { $kind = $node->getAttribute('kind', Expr\Exit_::KIND_DIE); return ($kind === Expr\Exit_::KIND_EXIT ? 'exit' : 'die') . (null !== $node->expr ? '(' . $this->p($node->expr) . ')' : ''); } protected function pExpr_Throw(Expr\Throw_ $node, int $precedence, int $lhsPrecedence): string { return $this->pPrefixOp(Expr\Throw_::class, 'throw ', $node->expr, $precedence, $lhsPrecedence); } protected function pExpr_Yield(Expr\Yield_ $node, int $precedence, int $lhsPrecedence): string { if ($node->value === null) { $opPrecedence = $this->precedenceMap[Expr\Yield_::class][0]; return $opPrecedence >= $lhsPrecedence ? '(yield)' : 'yield'; } else { if (!$this->phpVersion->supportsYieldWithoutParentheses()) { return '(yield ' . $this->pKey($node->key) . $this->p($node->value) . ')'; } return $this->pPrefixOp( Expr\Yield_::class, 'yield ' . $this->pKey($node->key), $node->value, $precedence, $lhsPrecedence); } } // Declarations protected function pStmt_Namespace(Stmt\Namespace_ $node): string { if ($this->canUseSemicolonNamespaces) { return 'namespace ' . $this->p($node->name) . ';' . $this->nl . $this->pStmts($node->stmts, false); } else { return 'namespace' . (null !== $node->name ? ' ' . $this->p($node->name) : '') . ' {' . $this->pStmts($node->stmts) . $this->nl . '}'; } } protected function pStmt_Use(Stmt\Use_ $node): string { return 'use ' . $this->pUseType($node->type) . $this->pCommaSeparated($node->uses) . ';'; } protected function pStmt_GroupUse(Stmt\GroupUse $node): string { return 'use ' . $this->pUseType($node->type) . $this->pName($node->prefix) . '\{' . $this->pCommaSeparated($node->uses) . '};'; } protected function pUseItem(Node\UseItem $node): string { return $this->pUseType($node->type) . $this->p($node->name) . (null !== $node->alias ? ' as ' . $node->alias : ''); } protected function pUseType(int $type): string { return $type === Stmt\Use_::TYPE_FUNCTION ? 'function ' : ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : ''); } protected function pStmt_Interface(Stmt\Interface_ $node): string { return $this->pAttrGroups($node->attrGroups) . 'interface ' . $node->name . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '') . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Enum(Stmt\Enum_ $node): string { return $this->pAttrGroups($node->attrGroups) . 'enum ' . $node->name . ($node->scalarType ? ' : ' . $this->p($node->scalarType) : '') . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '') . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Class(Stmt\Class_ $node): string { return $this->pClassCommon($node, ' ' . $node->name); } protected function pStmt_Trait(Stmt\Trait_ $node): string { return $this->pAttrGroups($node->attrGroups) . 'trait ' . $node->name . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_EnumCase(Stmt\EnumCase $node): string { return $this->pAttrGroups($node->attrGroups) . 'case ' . $node->name . ($node->expr ? ' = ' . $this->p($node->expr) : '') . ';'; } protected function pStmt_TraitUse(Stmt\TraitUse $node): string { return 'use ' . $this->pCommaSeparated($node->traits) . (empty($node->adaptations) ? ';' : ' {' . $this->pStmts($node->adaptations) . $this->nl . '}'); } protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node): string { return $this->p($node->trait) . '::' . $node->method . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';'; } protected function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node): string { return (null !== $node->trait ? $this->p($node->trait) . '::' : '') . $node->method . ' as' . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '') . (null !== $node->newName ? ' ' . $node->newName : '') . ';'; } protected function pStmt_Property(Stmt\Property $node): string { return $this->pAttrGroups($node->attrGroups) . (0 === $node->flags ? 'var ' : $this->pModifiers($node->flags)) . ($node->type ? $this->p($node->type) . ' ' : '') . $this->pCommaSeparated($node->props) . ($node->hooks ? ' {' . $this->pStmts($node->hooks) . $this->nl . '}' : ';'); } protected function pPropertyItem(Node\PropertyItem $node): string { return '$' . $node->name . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); } protected function pPropertyHook(Node\PropertyHook $node): string { return $this->pAttrGroups($node->attrGroups) . $this->pModifiers($node->flags) . ($node->byRef ? '&' : '') . $node->name . ($node->params ? '(' . $this->pParams($node->params) . ')' : '') . (\is_array($node->body) ? ' {' . $this->pStmts($node->body) . $this->nl . '}' : ($node->body !== null ? ' => ' . $this->p($node->body) : '') . ';'); } protected function pStmt_ClassMethod(Stmt\ClassMethod $node): string { return $this->pAttrGroups($node->attrGroups) . $this->pModifiers($node->flags) . 'function ' . ($node->byRef ? '&' : '') . $node->name . '(' . $this->pParams($node->params) . ')' . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . (null !== $node->stmts ? $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}' : ';'); } protected function pStmt_ClassConst(Stmt\ClassConst $node): string { return $this->pAttrGroups($node->attrGroups) . $this->pModifiers($node->flags) . 'const ' . (null !== $node->type ? $this->p($node->type) . ' ' : '') . $this->pCommaSeparated($node->consts) . ';'; } protected function pStmt_Function(Stmt\Function_ $node): string { return $this->pAttrGroups($node->attrGroups) . 'function ' . ($node->byRef ? '&' : '') . $node->name . '(' . $this->pParams($node->params) . ')' . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Const(Stmt\Const_ $node): string { return $this->pAttrGroups($node->attrGroups) . 'const ' . $this->pCommaSeparated($node->consts) . ';'; } protected function pStmt_Declare(Stmt\Declare_ $node): string { return 'declare (' . $this->pCommaSeparated($node->declares) . ')' . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . $this->nl . '}' : ';'); } protected function pDeclareItem(Node\DeclareItem $node): string { return $node->key . '=' . $this->p($node->value); } // Control flow protected function pStmt_If(Stmt\If_ $node): string { return 'if (' . $this->p($node->cond) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}' . ($node->elseifs ? ' ' . $this->pImplode($node->elseifs, ' ') : '') . (null !== $node->else ? ' ' . $this->p($node->else) : ''); } protected function pStmt_ElseIf(Stmt\ElseIf_ $node): string { return 'elseif (' . $this->p($node->cond) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Else(Stmt\Else_ $node): string { if (\count($node->stmts) === 1 && $node->stmts[0] instanceof Stmt\If_) { // Print as "else if" rather than "else { if }" return 'else ' . $this->p($node->stmts[0]); } return 'else {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_For(Stmt\For_ $node): string { return 'for (' . $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '') . $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '') . $this->pCommaSeparated($node->loop) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Foreach(Stmt\Foreach_ $node): string { return 'foreach (' . $this->p($node->expr) . ' as ' . (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '') . ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_While(Stmt\While_ $node): string { return 'while (' . $this->p($node->cond) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Do(Stmt\Do_ $node): string { return 'do {' . $this->pStmts($node->stmts) . $this->nl . '} while (' . $this->p($node->cond) . ');'; } protected function pStmt_Switch(Stmt\Switch_ $node): string { return 'switch (' . $this->p($node->cond) . ') {' . $this->pStmts($node->cases) . $this->nl . '}'; } protected function pStmt_Case(Stmt\Case_ $node): string { return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':' . $this->pStmts($node->stmts); } protected function pStmt_TryCatch(Stmt\TryCatch $node): string { return 'try {' . $this->pStmts($node->stmts) . $this->nl . '}' . ($node->catches ? ' ' . $this->pImplode($node->catches, ' ') : '') . ($node->finally !== null ? ' ' . $this->p($node->finally) : ''); } protected function pStmt_Catch(Stmt\Catch_ $node): string { return 'catch (' . $this->pImplode($node->types, '|') . ($node->var !== null ? ' ' . $this->p($node->var) : '') . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Finally(Stmt\Finally_ $node): string { return 'finally {' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pStmt_Break(Stmt\Break_ $node): string { return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';'; } protected function pStmt_Continue(Stmt\Continue_ $node): string { return 'continue' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';'; } protected function pStmt_Return(Stmt\Return_ $node): string { return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';'; } protected function pStmt_Label(Stmt\Label $node): string { return $node->name . ':'; } protected function pStmt_Goto(Stmt\Goto_ $node): string { return 'goto ' . $node->name . ';'; } // Other protected function pStmt_Expression(Stmt\Expression $node): string { return $this->p($node->expr) . ';'; } protected function pStmt_Echo(Stmt\Echo_ $node): string { return 'echo ' . $this->pCommaSeparated($node->exprs) . ';'; } protected function pStmt_Static(Stmt\Static_ $node): string { return 'static ' . $this->pCommaSeparated($node->vars) . ';'; } protected function pStmt_Global(Stmt\Global_ $node): string { return 'global ' . $this->pCommaSeparated($node->vars) . ';'; } protected function pStaticVar(Node\StaticVar $node): string { return $this->p($node->var) . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); } protected function pStmt_Unset(Stmt\Unset_ $node): string { return 'unset(' . $this->pCommaSeparated($node->vars) . ');'; } protected function pStmt_InlineHTML(Stmt\InlineHTML $node): string { $newline = $node->getAttribute('hasLeadingNewline', true) ? $this->newline : ''; return '?>' . $newline . $node->value . 'remaining; } protected function pStmt_Nop(Stmt\Nop $node): string { return ''; } protected function pStmt_Block(Stmt\Block $node): string { return '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } // Helpers protected function pClassCommon(Stmt\Class_ $node, string $afterClassToken): string { return $this->pAttrGroups($node->attrGroups, $node->name === null) . $this->pModifiers($node->flags) . 'class' . $afterClassToken . (null !== $node->extends ? ' extends ' . $this->p($node->extends) : '') . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '') . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } protected function pObjectProperty(Node $node): string { if ($node instanceof Expr) { return '{' . $this->p($node) . '}'; } else { assert($node instanceof Node\Identifier); return $node->name; } } /** @param (Expr|Node\InterpolatedStringPart)[] $encapsList */ protected function pEncapsList(array $encapsList, ?string $quote): string { $return = ''; foreach ($encapsList as $element) { if ($element instanceof Node\InterpolatedStringPart) { $return .= $this->escapeString($element->value, $quote); } else { $return .= '{' . $this->p($element) . '}'; } } return $return; } protected function pSingleQuotedString(string $string): string { // It is idiomatic to only escape backslashes when necessary, i.e. when followed by ', \ or // the end of the string ('Foo\Bar' instead of 'Foo\\Bar'). However, we also don't want to // produce an odd number of backslashes, so '\\\\a' should not get rendered as '\\\a', even // though that would be legal. $regex = '/\'|\\\\(?=[\'\\\\]|$)|(?<=\\\\)\\\\/'; return '\'' . preg_replace($regex, '\\\\$0', $string) . '\''; } protected function escapeString(string $string, ?string $quote): string { if (null === $quote) { // For doc strings, don't escape newlines $escaped = addcslashes($string, "\t\f\v$\\"); // But do escape isolated \r. Combined with the terminating newline, it might get // interpreted as \r\n and dropped from the string contents. $escaped = preg_replace('/\r(?!\n)/', '\\r', $escaped); if ($this->phpVersion->supportsFlexibleHeredoc()) { $escaped = $this->indentString($escaped); } } else { $escaped = addcslashes($string, "\n\r\t\f\v$" . $quote . "\\"); } // Escape control characters and non-UTF-8 characters. // Regex based on https://stackoverflow.com/a/11709412/385378. $regex = '/( [\x00-\x08\x0E-\x1F] # Control characters | [\xC0-\xC1] # Invalid UTF-8 Bytes | [\xF5-\xFF] # Invalid UTF-8 Bytes | \xE0(?=[\x80-\x9F]) # Overlong encoding of prior code point | \xF0(?=[\x80-\x8F]) # Overlong encoding of prior code point | [\xC2-\xDF](?![\x80-\xBF]) # Invalid UTF-8 Sequence Start | [\xE0-\xEF](?![\x80-\xBF]{2}) # Invalid UTF-8 Sequence Start | [\xF0-\xF4](?![\x80-\xBF]{3}) # Invalid UTF-8 Sequence Start | (?<=[\x00-\x7F\xF5-\xFF])[\x80-\xBF] # Invalid UTF-8 Sequence Middle | (? $part) { if ($part instanceof Node\InterpolatedStringPart && $this->containsEndLabel($this->escapeString($part->value, null), $label, $i === 0) ) { return true; } } return false; } protected function pDereferenceLhs(Node $node): string { if (!$this->dereferenceLhsRequiresParens($node)) { return $this->p($node); } else { return '(' . $this->p($node) . ')'; } } protected function pStaticDereferenceLhs(Node $node): string { if (!$this->staticDereferenceLhsRequiresParens($node)) { return $this->p($node); } else { return '(' . $this->p($node) . ')'; } } protected function pCallLhs(Node $node): string { if (!$this->callLhsRequiresParens($node)) { return $this->p($node); } else { return '(' . $this->p($node) . ')'; } } protected function pNewOperand(Node $node): string { if (!$this->newOperandRequiresParens($node)) { return $this->p($node); } else { return '(' . $this->p($node) . ')'; } } /** * @param Node[] $nodes */ protected function hasNodeWithComments(array $nodes): bool { foreach ($nodes as $node) { if ($node && $node->getComments()) { return true; } } return false; } /** @param Node[] $nodes */ protected function pMaybeMultiline(array $nodes, bool $trailingComma = false): string { if (!$this->hasNodeWithComments($nodes)) { return $this->pCommaSeparated($nodes); } else { return $this->pCommaSeparatedMultiline($nodes, $trailingComma) . $this->nl; } } /** @param Node\Param[] $params */ private function hasParamWithAttributes(array $params): bool { foreach ($params as $param) { if ($param->attrGroups) { return true; } } return false; } /** @param Node\Param[] $params */ protected function pParams(array $params): string { if ($this->hasNodeWithComments($params) || ($this->hasParamWithAttributes($params) && !$this->phpVersion->supportsAttributes()) ) { return $this->pCommaSeparatedMultiline($params, $this->phpVersion->supportsTrailingCommaInParamList()) . $this->nl; } return $this->pCommaSeparated($params); } /** @param Node\AttributeGroup[] $nodes */ protected function pAttrGroups(array $nodes, bool $inline = false): string { $result = ''; $sep = $inline ? ' ' : $this->nl; foreach ($nodes as $node) { $result .= $this->p($node) . $sep; } return $result; } } ================================================ FILE: lib/PhpParser/PrettyPrinter.php ================================================ */ protected array $precedenceMap = [ // [precedence, precedenceLHS, precedenceRHS] // Where the latter two are the precedences to use for the LHS and RHS of a binary operator, // where 1 is added to one of the sides depending on associativity. This information is not // used for unary operators and set to -1. Expr\Clone_::class => [-10, 0, 1], BinaryOp\Pow::class => [ 0, 0, 1], Expr\BitwiseNot::class => [ 10, -1, -1], Expr\UnaryPlus::class => [ 10, -1, -1], Expr\UnaryMinus::class => [ 10, -1, -1], Cast\Int_::class => [ 10, -1, -1], Cast\Double::class => [ 10, -1, -1], Cast\String_::class => [ 10, -1, -1], Cast\Array_::class => [ 10, -1, -1], Cast\Object_::class => [ 10, -1, -1], Cast\Bool_::class => [ 10, -1, -1], Cast\Unset_::class => [ 10, -1, -1], Expr\ErrorSuppress::class => [ 10, -1, -1], Expr\Instanceof_::class => [ 20, -1, -1], Expr\BooleanNot::class => [ 30, -1, -1], BinaryOp\Mul::class => [ 40, 41, 40], BinaryOp\Div::class => [ 40, 41, 40], BinaryOp\Mod::class => [ 40, 41, 40], BinaryOp\Plus::class => [ 50, 51, 50], BinaryOp\Minus::class => [ 50, 51, 50], // FIXME: This precedence is incorrect for PHP 8. BinaryOp\Concat::class => [ 50, 51, 50], BinaryOp\ShiftLeft::class => [ 60, 61, 60], BinaryOp\ShiftRight::class => [ 60, 61, 60], BinaryOp\Pipe::class => [ 65, 66, 65], BinaryOp\Smaller::class => [ 70, 70, 70], BinaryOp\SmallerOrEqual::class => [ 70, 70, 70], BinaryOp\Greater::class => [ 70, 70, 70], BinaryOp\GreaterOrEqual::class => [ 70, 70, 70], BinaryOp\Equal::class => [ 80, 80, 80], BinaryOp\NotEqual::class => [ 80, 80, 80], BinaryOp\Identical::class => [ 80, 80, 80], BinaryOp\NotIdentical::class => [ 80, 80, 80], BinaryOp\Spaceship::class => [ 80, 80, 80], BinaryOp\BitwiseAnd::class => [ 90, 91, 90], BinaryOp\BitwiseXor::class => [100, 101, 100], BinaryOp\BitwiseOr::class => [110, 111, 110], BinaryOp\BooleanAnd::class => [120, 121, 120], BinaryOp\BooleanOr::class => [130, 131, 130], BinaryOp\Coalesce::class => [140, 140, 141], Expr\Ternary::class => [150, 150, 150], Expr\Assign::class => [160, -1, -1], Expr\AssignRef::class => [160, -1, -1], AssignOp\Plus::class => [160, -1, -1], AssignOp\Minus::class => [160, -1, -1], AssignOp\Mul::class => [160, -1, -1], AssignOp\Div::class => [160, -1, -1], AssignOp\Concat::class => [160, -1, -1], AssignOp\Mod::class => [160, -1, -1], AssignOp\BitwiseAnd::class => [160, -1, -1], AssignOp\BitwiseOr::class => [160, -1, -1], AssignOp\BitwiseXor::class => [160, -1, -1], AssignOp\ShiftLeft::class => [160, -1, -1], AssignOp\ShiftRight::class => [160, -1, -1], AssignOp\Pow::class => [160, -1, -1], AssignOp\Coalesce::class => [160, -1, -1], Expr\YieldFrom::class => [170, -1, -1], Expr\Yield_::class => [175, -1, -1], Expr\Print_::class => [180, -1, -1], BinaryOp\LogicalAnd::class => [190, 191, 190], BinaryOp\LogicalXor::class => [200, 201, 200], BinaryOp\LogicalOr::class => [210, 211, 210], Expr\Include_::class => [220, -1, -1], Expr\ArrowFunction::class => [230, -1, -1], Expr\Throw_::class => [240, -1, -1], Expr\Cast\Void_::class => [250, -1, -1], ]; /** @var int Current indentation level. */ protected int $indentLevel; /** @var string String for single level of indentation */ private string $indent; /** @var int Width in spaces to indent by. */ private int $indentWidth; /** @var bool Whether to use tab indentation. */ private bool $useTabs; /** @var int Width in spaces of one tab. */ private int $tabWidth = 4; /** @var string Newline style. Does not include current indentation. */ protected string $newline; /** @var string Newline including current indentation. */ protected string $nl; /** @var string|null Token placed at end of doc string to ensure it is followed by a newline. * Null if flexible doc strings are used. */ protected ?string $docStringEndToken; /** @var bool Whether semicolon namespaces can be used (i.e. no global namespace is used) */ protected bool $canUseSemicolonNamespaces; /** @var bool Whether to use short array syntax if the node specifies no preference */ protected bool $shortArraySyntax; /** @var PhpVersion PHP version to target */ protected PhpVersion $phpVersion; /** @var TokenStream|null Original tokens for use in format-preserving pretty print */ protected ?TokenStream $origTokens; /** @var Internal\Differ Differ for node lists */ protected Differ $nodeListDiffer; /** @var array Map determining whether a certain character is a label character */ protected array $labelCharMap; /** * @var array> Map from token classes and subnode names to FIXUP_* constants. * This is used during format-preserving prints to place additional parens/braces if necessary. */ protected array $fixupMap; /** * @var array Map from "{$node->getType()}->{$subNode}" * to ['left' => $l, 'right' => $r], where $l and $r specify the token type that needs to be stripped * when removing this node. */ protected array $removalMap; /** * @var array Map from * "{$node->getType()}->{$subNode}" to [$find, $beforeToken, $extraLeft, $extraRight]. * $find is an optional token after which the insertion occurs. $extraLeft/Right * are optionally added before/after the main insertions. */ protected array $insertionMap; /** * @var array Map From "{$class}->{$subNode}" to string that should be inserted * between elements of this list subnode. */ protected array $listInsertionMap; /** * @var array */ protected array $emptyListInsertionMap; /** @var array * Map from "{$class}->{$subNode}" to [$printFn, $skipToken, $findToken] where $printFn is the function to * print the modifiers, $skipToken is the token to skip at the start and $findToken is the token before which * the modifiers should be reprinted. */ protected array $modifierChangeMap; /** * Creates a pretty printer instance using the given options. * * Supported options: * * PhpVersion $phpVersion: The PHP version to target (default to PHP 7.4). This option * controls compatibility of the generated code with older PHP * versions in cases where a simple stylistic choice exists (e.g. * array() vs []). It is safe to pretty-print an AST for a newer * PHP version while specifying an older target (but the result will * of course not be compatible with the older version in that case). * * string $newline: The newline style to use. Should be "\n" (default) or "\r\n". * * string $indent: The indentation to use. Should either be all spaces or a single * tab. Defaults to four spaces (" "). * * bool $shortArraySyntax: Whether to use [] instead of array() as the default array * syntax, if the node does not specify a format. Defaults to whether * the phpVersion support short array syntax. * * @param array{ * phpVersion?: PhpVersion, newline?: string, indent?: string, shortArraySyntax?: bool * } $options Dictionary of formatting options */ public function __construct(array $options = []) { $this->phpVersion = $options['phpVersion'] ?? PhpVersion::fromComponents(7, 4); $this->newline = $options['newline'] ?? "\n"; if ($this->newline !== "\n" && $this->newline != "\r\n") { throw new \LogicException('Option "newline" must be one of "\n" or "\r\n"'); } $this->shortArraySyntax = $options['shortArraySyntax'] ?? $this->phpVersion->supportsShortArraySyntax(); $this->docStringEndToken = $this->phpVersion->supportsFlexibleHeredoc() ? null : '_DOC_STRING_END_' . mt_rand(); $this->indent = $indent = $options['indent'] ?? ' '; if ($indent === "\t") { $this->useTabs = true; $this->indentWidth = $this->tabWidth; } elseif ($indent === \str_repeat(' ', \strlen($indent))) { $this->useTabs = false; $this->indentWidth = \strlen($indent); } else { throw new \LogicException('Option "indent" must either be all spaces or a single tab'); } } /** * Reset pretty printing state. */ protected function resetState(): void { $this->indentLevel = 0; $this->nl = $this->newline; $this->origTokens = null; } /** * Set indentation level * * @param int $level Level in number of spaces */ protected function setIndentLevel(int $level): void { $this->indentLevel = $level; if ($this->useTabs) { $tabs = \intdiv($level, $this->tabWidth); $spaces = $level % $this->tabWidth; $this->nl = $this->newline . \str_repeat("\t", $tabs) . \str_repeat(' ', $spaces); } else { $this->nl = $this->newline . \str_repeat(' ', $level); } } /** * Increase indentation level. */ protected function indent(): void { $this->indentLevel += $this->indentWidth; $this->nl .= $this->indent; } /** * Decrease indentation level. */ protected function outdent(): void { assert($this->indentLevel >= $this->indentWidth); $this->setIndentLevel($this->indentLevel - $this->indentWidth); } /** * Pretty prints an array of statements. * * @param Node[] $stmts Array of statements * * @return string Pretty printed statements */ public function prettyPrint(array $stmts): string { $this->resetState(); $this->preprocessNodes($stmts); return ltrim($this->handleMagicTokens($this->pStmts($stmts, false))); } /** * Pretty prints an expression. * * @param Expr $node Expression node * * @return string Pretty printed node */ public function prettyPrintExpr(Expr $node): string { $this->resetState(); return $this->handleMagicTokens($this->p($node)); } /** * Pretty prints a file of statements (includes the opening newline . $this->newline; } $p = "newline . $this->newline . $this->prettyPrint($stmts); if ($stmts[0] instanceof Stmt\InlineHTML) { $p = preg_replace('/^<\?php\s+\?>\r?\n?/', '', $p); } if ($stmts[count($stmts) - 1] instanceof Stmt\InlineHTML) { $p = preg_replace('/<\?php$/', '', rtrim($p)); } return $p; } /** * Preprocesses the top-level nodes to initialize pretty printer state. * * @param Node[] $nodes Array of nodes */ protected function preprocessNodes(array $nodes): void { /* We can use semicolon-namespaces unless there is a global namespace declaration */ $this->canUseSemicolonNamespaces = true; foreach ($nodes as $node) { if ($node instanceof Stmt\Namespace_ && null === $node->name) { $this->canUseSemicolonNamespaces = false; break; } } } /** * Handles (and removes) doc-string-end tokens. */ protected function handleMagicTokens(string $str): string { if ($this->docStringEndToken !== null) { // Replace doc-string-end tokens with nothing or a newline $str = str_replace( $this->docStringEndToken . ';' . $this->newline, ';' . $this->newline, $str); $str = str_replace($this->docStringEndToken, $this->newline, $str); } return $str; } /** * Pretty prints an array of nodes (statements) and indents them optionally. * * @param Node[] $nodes Array of nodes * @param bool $indent Whether to indent the printed nodes * * @return string Pretty printed statements */ protected function pStmts(array $nodes, bool $indent = true): string { if ($indent) { $this->indent(); } $result = ''; foreach ($nodes as $node) { $comments = $node->getComments(); if ($comments) { $result .= $this->nl . $this->pComments($comments); if ($node instanceof Stmt\Nop) { continue; } } $result .= $this->nl . $this->p($node); } if ($indent) { $this->outdent(); } return $result; } /** * Pretty-print an infix operation while taking precedence into account. * * @param string $class Node class of operator * @param Node $leftNode Left-hand side node * @param string $operatorString String representation of the operator * @param Node $rightNode Right-hand side node * @param int $precedence Precedence of parent operator * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator * * @return string Pretty printed infix operation */ protected function pInfixOp( string $class, Node $leftNode, string $operatorString, Node $rightNode, int $precedence, int $lhsPrecedence ): string { list($opPrecedence, $newPrecedenceLHS, $newPrecedenceRHS) = $this->precedenceMap[$class]; $prefix = ''; $suffix = ''; if ($opPrecedence >= $precedence) { $prefix = '('; $suffix = ')'; $lhsPrecedence = self::MAX_PRECEDENCE; } return $prefix . $this->p($leftNode, $newPrecedenceLHS, $newPrecedenceLHS) . $operatorString . $this->p($rightNode, $newPrecedenceRHS, $lhsPrecedence) . $suffix; } /** * Pretty-print a prefix operation while taking precedence into account. * * @param string $class Node class of operator * @param string $operatorString String representation of the operator * @param Node $node Node * @param int $precedence Precedence of parent operator * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator * * @return string Pretty printed prefix operation */ protected function pPrefixOp(string $class, string $operatorString, Node $node, int $precedence, int $lhsPrecedence): string { $opPrecedence = $this->precedenceMap[$class][0]; $prefix = ''; $suffix = ''; if ($opPrecedence >= $lhsPrecedence) { $prefix = '('; $suffix = ')'; $lhsPrecedence = self::MAX_PRECEDENCE; } $printedArg = $this->p($node, $opPrecedence, $lhsPrecedence); if (($operatorString === '+' && $printedArg[0] === '+') || ($operatorString === '-' && $printedArg[0] === '-') ) { // Avoid printing +(+$a) as ++$a and similar. $printedArg = '(' . $printedArg . ')'; } return $prefix . $operatorString . $printedArg . $suffix; } /** * Pretty-print a postfix operation while taking precedence into account. * * @param string $class Node class of operator * @param string $operatorString String representation of the operator * @param Node $node Node * @param int $precedence Precedence of parent operator * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator * * @return string Pretty printed postfix operation */ protected function pPostfixOp(string $class, Node $node, string $operatorString, int $precedence, int $lhsPrecedence): string { $opPrecedence = $this->precedenceMap[$class][0]; $prefix = ''; $suffix = ''; if ($opPrecedence >= $precedence) { $prefix = '('; $suffix = ')'; $lhsPrecedence = self::MAX_PRECEDENCE; } if ($opPrecedence < $lhsPrecedence) { $lhsPrecedence = $opPrecedence; } return $prefix . $this->p($node, $opPrecedence, $lhsPrecedence) . $operatorString . $suffix; } /** * Pretty prints an array of nodes and implodes the printed values. * * @param Node[] $nodes Array of Nodes to be printed * @param string $glue Character to implode with * * @return string Imploded pretty printed nodes> $pre */ protected function pImplode(array $nodes, string $glue = ''): string { $pNodes = []; foreach ($nodes as $node) { if (null === $node) { $pNodes[] = ''; } else { $pNodes[] = $this->p($node); } } return implode($glue, $pNodes); } /** * Pretty prints an array of nodes and implodes the printed values with commas. * * @param Node[] $nodes Array of Nodes to be printed * * @return string Comma separated pretty printed nodes */ protected function pCommaSeparated(array $nodes): string { return $this->pImplode($nodes, ', '); } /** * Pretty prints a comma-separated list of nodes in multiline style, including comments. * * The result includes a leading newline and one level of indentation (same as pStmts). * * @param Node[] $nodes Array of Nodes to be printed * @param bool $trailingComma Whether to use a trailing comma * * @return string Comma separated pretty printed nodes in multiline style */ protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma): string { $this->indent(); $result = ''; $lastIdx = count($nodes) - 1; foreach ($nodes as $idx => $node) { if ($node !== null) { $comments = $node->getComments(); if ($comments) { $result .= $this->nl . $this->pComments($comments); } $result .= $this->nl . $this->p($node); } else { $result .= $this->nl; } if ($trailingComma || $idx !== $lastIdx) { $result .= ','; } } $this->outdent(); return $result; } /** * Prints reformatted text of the passed comments. * * @param Comment[] $comments List of comments * * @return string Reformatted text of comments */ protected function pComments(array $comments): string { $formattedComments = []; foreach ($comments as $comment) { $formattedComments[] = str_replace("\n", $this->nl, $comment->getReformattedText()); } return implode($this->nl, $formattedComments); } /** * Perform a format-preserving pretty print of an AST. * * The format preservation is best effort. For some changes to the AST the formatting will not * be preserved (at least not locally). * * In order to use this method a number of prerequisites must be satisfied: * * The startTokenPos and endTokenPos attributes in the lexer must be enabled. * * The CloningVisitor must be run on the AST prior to modification. * * The original tokens must be provided, using the getTokens() method on the lexer. * * @param Node[] $stmts Modified AST with links to original AST * @param Node[] $origStmts Original AST with token offset information * @param Token[] $origTokens Tokens of the original code */ public function printFormatPreserving(array $stmts, array $origStmts, array $origTokens): string { $this->initializeNodeListDiffer(); $this->initializeLabelCharMap(); $this->initializeFixupMap(); $this->initializeRemovalMap(); $this->initializeInsertionMap(); $this->initializeListInsertionMap(); $this->initializeEmptyListInsertionMap(); $this->initializeModifierChangeMap(); $this->resetState(); $this->origTokens = new TokenStream($origTokens, $this->tabWidth); $this->preprocessNodes($stmts); $pos = 0; $result = $this->pArray($stmts, $origStmts, $pos, 0, 'File', 'stmts', null); if (null !== $result) { $result .= $this->origTokens->getTokenCode($pos, count($origTokens) - 1, 0); } else { // Fallback // TODO Add newline . $this->pStmts($stmts, false); } return $this->handleMagicTokens($result); } protected function pFallback(Node $node, int $precedence, int $lhsPrecedence): string { return $this->{'p' . $node->getType()}($node, $precedence, $lhsPrecedence); } /** * Pretty prints a node. * * This method also handles formatting preservation for nodes. * * @param Node $node Node to be pretty printed * @param int $precedence Precedence of parent operator * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator * @param bool $parentFormatPreserved Whether parent node has preserved formatting * * @return string Pretty printed node */ protected function p( Node $node, int $precedence = self::MAX_PRECEDENCE, int $lhsPrecedence = self::MAX_PRECEDENCE, bool $parentFormatPreserved = false ): string { // No orig tokens means this is a normal pretty print without preservation of formatting if (!$this->origTokens) { return $this->{'p' . $node->getType()}($node, $precedence, $lhsPrecedence); } /** @var Node|null $origNode */ $origNode = $node->getAttribute('origNode'); if (null === $origNode) { return $this->pFallback($node, $precedence, $lhsPrecedence); } $class = \get_class($node); \assert($class === \get_class($origNode)); $startPos = $origNode->getStartTokenPos(); $endPos = $origNode->getEndTokenPos(); \assert($startPos >= 0 && $endPos >= 0); $fallbackNode = $node; if ($node instanceof Expr\New_ && $node->class instanceof Stmt\Class_) { // Normalize node structure of anonymous classes assert($origNode instanceof Expr\New_); $node = PrintableNewAnonClassNode::fromNewNode($node); $origNode = PrintableNewAnonClassNode::fromNewNode($origNode); $class = PrintableNewAnonClassNode::class; } // InlineHTML node does not contain closing and opening PHP tags. If the parent formatting // is not preserved, then we need to use the fallback code to make sure the tags are // printed. if ($node instanceof Stmt\InlineHTML && !$parentFormatPreserved) { return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence); } $indentAdjustment = $this->indentLevel - $this->origTokens->getIndentationBefore($startPos); $type = $node->getType(); $fixupInfo = $this->fixupMap[$class] ?? null; $result = ''; $pos = $startPos; foreach ($node->getSubNodeNames() as $subNodeName) { $subNode = $node->$subNodeName; $origSubNode = $origNode->$subNodeName; if ((!$subNode instanceof Node && $subNode !== null) || (!$origSubNode instanceof Node && $origSubNode !== null) ) { if ($subNode === $origSubNode) { // Unchanged, can reuse old code continue; } if (is_array($subNode) && is_array($origSubNode)) { // Array subnode changed, we might be able to reconstruct it $listResult = $this->pArray( $subNode, $origSubNode, $pos, $indentAdjustment, $class, $subNodeName, $fixupInfo[$subNodeName] ?? null ); if (null === $listResult) { return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence); } $result .= $listResult; continue; } // Check if this is a modifier change $key = $class . '->' . $subNodeName; if (!isset($this->modifierChangeMap[$key])) { return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence); } [$printFn, $skipToken, $findToken] = $this->modifierChangeMap[$key]; $skipWSPos = $this->origTokens->skipRight($pos, $skipToken); $result .= $this->origTokens->getTokenCode($pos, $skipWSPos, $indentAdjustment); $result .= $this->$printFn($subNode); $pos = $this->origTokens->findRight($skipWSPos, $findToken); continue; } $extraLeft = ''; $extraRight = ''; if ($origSubNode !== null) { $subStartPos = $origSubNode->getStartTokenPos(); $subEndPos = $origSubNode->getEndTokenPos(); \assert($subStartPos >= 0 && $subEndPos >= 0); } else { if ($subNode === null) { // Both null, nothing to do continue; } // A node has been inserted, check if we have insertion information for it $key = $type . '->' . $subNodeName; if (!isset($this->insertionMap[$key])) { return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence); } list($findToken, $beforeToken, $extraLeft, $extraRight) = $this->insertionMap[$key]; if (null !== $findToken) { $subStartPos = $this->origTokens->findRight($pos, $findToken) + (int) !$beforeToken; } else { $subStartPos = $pos; } if (null === $extraLeft && null !== $extraRight) { // If inserting on the right only, skipping whitespace looks better $subStartPos = $this->origTokens->skipRightWhitespace($subStartPos); } $subEndPos = $subStartPos - 1; } if (null === $subNode) { // A node has been removed, check if we have removal information for it $key = $type . '->' . $subNodeName; if (!isset($this->removalMap[$key])) { return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence); } // Adjust positions to account for additional tokens that must be skipped $removalInfo = $this->removalMap[$key]; if (isset($removalInfo['left'])) { $subStartPos = $this->origTokens->skipLeft($subStartPos - 1, $removalInfo['left']) + 1; } if (isset($removalInfo['right'])) { $subEndPos = $this->origTokens->skipRight($subEndPos + 1, $removalInfo['right']) - 1; } } $result .= $this->origTokens->getTokenCode($pos, $subStartPos, $indentAdjustment); if (null !== $subNode) { $result .= $extraLeft; $origIndentLevel = $this->indentLevel; $this->setIndentLevel(max($this->origTokens->getIndentationBefore($subStartPos) + $indentAdjustment, 0)); // If it's the same node that was previously in this position, it certainly doesn't // need fixup. It's important to check this here, because our fixup checks are more // conservative than strictly necessary. if (isset($fixupInfo[$subNodeName]) && $subNode->getAttribute('origNode') !== $origSubNode ) { $fixup = $fixupInfo[$subNodeName]; $res = $this->pFixup($fixup, $subNode, $class, $subStartPos, $subEndPos); } else { $res = $this->p($subNode, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true); } $this->safeAppend($result, $res); $this->setIndentLevel($origIndentLevel); $result .= $extraRight; } $pos = $subEndPos + 1; } $result .= $this->origTokens->getTokenCode($pos, $endPos + 1, $indentAdjustment); return $result; } /** * Perform a format-preserving pretty print of an array. * * @param Node[] $nodes New nodes * @param Node[] $origNodes Original nodes * @param int $pos Current token position (updated by reference) * @param int $indentAdjustment Adjustment for indentation * @param string $parentNodeClass Class of the containing node. * @param string $subNodeName Name of array subnode. * @param null|int $fixup Fixup information for array item nodes * * @return null|string Result of pretty print or null if cannot preserve formatting */ protected function pArray( array $nodes, array $origNodes, int &$pos, int $indentAdjustment, string $parentNodeClass, string $subNodeName, ?int $fixup ): ?string { $diff = $this->nodeListDiffer->diffWithReplacements($origNodes, $nodes); $mapKey = $parentNodeClass . '->' . $subNodeName; $insertStr = $this->listInsertionMap[$mapKey] ?? null; $isStmtList = $subNodeName === 'stmts'; $beforeFirstKeepOrReplace = true; $skipRemovedNode = false; $delayedAdd = []; $lastElemIndentLevel = $this->indentLevel; $insertNewline = false; if ($insertStr === "\n") { $insertStr = ''; $insertNewline = true; } if ($isStmtList && \count($origNodes) === 1 && \count($nodes) !== 1) { $startPos = $origNodes[0]->getStartTokenPos(); $endPos = $origNodes[0]->getEndTokenPos(); \assert($startPos >= 0 && $endPos >= 0); if (!$this->origTokens->haveBraces($startPos, $endPos)) { // This was a single statement without braces, but either additional statements // have been added, or the single statement has been removed. This requires the // addition of braces. For now fall back. // TODO: Try to preserve formatting return null; } } $result = ''; foreach ($diff as $i => $diffElem) { $diffType = $diffElem->type; /** @var Node|string|null $arrItem */ $arrItem = $diffElem->new; /** @var Node|string|null $origArrItem */ $origArrItem = $diffElem->old; if ($diffType === DiffElem::TYPE_KEEP || $diffType === DiffElem::TYPE_REPLACE) { $beforeFirstKeepOrReplace = false; if ($origArrItem === null || $arrItem === null) { // We can only handle the case where both are null if ($origArrItem === $arrItem) { continue; } return null; } if (!$arrItem instanceof Node || !$origArrItem instanceof Node) { // We can only deal with nodes. This can occur for Names, which use string arrays. return null; } $itemStartPos = $origArrItem->getStartTokenPos(); $itemEndPos = $origArrItem->getEndTokenPos(); \assert($itemStartPos >= 0 && $itemEndPos >= 0 && $itemStartPos >= $pos); $origIndentLevel = $this->indentLevel; $lastElemIndentLevel = max($this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment, 0); $this->setIndentLevel($lastElemIndentLevel); $comments = $arrItem->getComments(); $origComments = $origArrItem->getComments(); $commentStartPos = $origComments ? $origComments[0]->getStartTokenPos() : $itemStartPos; \assert($commentStartPos >= 0); if ($commentStartPos < $pos) { // Comments may be assigned to multiple nodes if they start at the same position. // Make sure we don't try to print them multiple times. $commentStartPos = $itemStartPos; } if ($skipRemovedNode) { if ($isStmtList && $this->origTokens->haveTagInRange($pos, $itemStartPos)) { // We'd remove an opening/closing PHP tag. // TODO: Preserve formatting. $this->setIndentLevel($origIndentLevel); return null; } } else { $result .= $this->origTokens->getTokenCode( $pos, $commentStartPos, $indentAdjustment); } if (!empty($delayedAdd)) { /** @var Node $delayedAddNode */ foreach ($delayedAdd as $delayedAddNode) { if ($insertNewline) { $delayedAddComments = $delayedAddNode->getComments(); if ($delayedAddComments) { $result .= $this->pComments($delayedAddComments) . $this->nl; } } $this->safeAppend($result, $this->p($delayedAddNode, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true)); if ($insertNewline) { $result .= $insertStr . $this->nl; } else { $result .= $insertStr; } } $delayedAdd = []; } if ($comments !== $origComments) { if ($comments) { $result .= $this->pComments($comments) . $this->nl; } } else { $result .= $this->origTokens->getTokenCode( $commentStartPos, $itemStartPos, $indentAdjustment); } // If we had to remove anything, we have done so now. $skipRemovedNode = false; } elseif ($diffType === DiffElem::TYPE_ADD) { if (null === $insertStr) { // We don't have insertion information for this list type return null; } if (!$arrItem instanceof Node) { // We only support list insertion of nodes. return null; } // We go multiline if the original code was multiline, // or if it's an array item with a comment above it. // Match always uses multiline formatting. if ($insertStr === ', ' && ($this->isMultiline($origNodes) || $arrItem->getComments() || $parentNodeClass === Expr\Match_::class) ) { $insertStr = ','; $insertNewline = true; } if ($beforeFirstKeepOrReplace) { // Will be inserted at the next "replace" or "keep" element $delayedAdd[] = $arrItem; continue; } $itemStartPos = $pos; $itemEndPos = $pos - 1; $origIndentLevel = $this->indentLevel; $this->setIndentLevel($lastElemIndentLevel); if ($insertNewline) { $result .= $insertStr . $this->nl; $comments = $arrItem->getComments(); if ($comments) { $result .= $this->pComments($comments) . $this->nl; } } else { $result .= $insertStr; } } elseif ($diffType === DiffElem::TYPE_REMOVE) { if (!$origArrItem instanceof Node) { // We only support removal for nodes return null; } $itemStartPos = $origArrItem->getStartTokenPos(); $itemEndPos = $origArrItem->getEndTokenPos(); \assert($itemStartPos >= 0 && $itemEndPos >= 0); // Consider comments part of the node. $origComments = $origArrItem->getComments(); if ($origComments) { $itemStartPos = $origComments[0]->getStartTokenPos(); } if ($i === 0) { // If we're removing from the start, keep the tokens before the node and drop those after it, // instead of the other way around. $result .= $this->origTokens->getTokenCode( $pos, $itemStartPos, $indentAdjustment); $skipRemovedNode = true; } else { if ($isStmtList && $this->origTokens->haveTagInRange($pos, $itemStartPos)) { // We'd remove an opening/closing PHP tag. // TODO: Preserve formatting. return null; } } $pos = $itemEndPos + 1; continue; } else { throw new \Exception("Shouldn't happen"); } if (null !== $fixup && $arrItem->getAttribute('origNode') !== $origArrItem) { $res = $this->pFixup($fixup, $arrItem, null, $itemStartPos, $itemEndPos); } else { $res = $this->p($arrItem, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true); } $this->safeAppend($result, $res); $this->setIndentLevel($origIndentLevel); $pos = $itemEndPos + 1; } if ($skipRemovedNode) { // TODO: Support removing single node. return null; } if (!empty($delayedAdd)) { if (!isset($this->emptyListInsertionMap[$mapKey])) { return null; } list($findToken, $extraLeft, $extraRight) = $this->emptyListInsertionMap[$mapKey]; if (null !== $findToken) { // For anon classes skip to the class keyword. $isAnonClassArgs = $mapKey === PrintableNewAnonClassNode::class . '->args'; if ($isAnonClassArgs) { $insertPos = $this->origTokens->findRight($pos, \T_CLASS) + 1; $result .= $this->origTokens->getTokenCode($pos, $insertPos, $indentAdjustment); $pos = $insertPos; } // If "new Foo" was used without arguments, we need to convert to "new Foo()". if (($mapKey === Expr\New_::class . '->args' || $isAnonClassArgs) && !$this->origTokens->haveTokenImmediatelyAfter($pos - 1, '(') ) { $extraLeft = '('; $extraRight = ')'; } else { $insertPos = $this->origTokens->findRight($pos, $findToken) + 1; $result .= $this->origTokens->getTokenCode($pos, $insertPos, $indentAdjustment); $pos = $insertPos; } } $first = true; $result .= $extraLeft; foreach ($delayedAdd as $delayedAddNode) { if (!$first) { $result .= $insertStr; if ($insertNewline) { $result .= $this->nl; } } $result .= $this->p($delayedAddNode, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true); $first = false; } $result .= $extraRight === "\n" ? $this->nl : $extraRight; } return $result; } /** * Print node with fixups. * * Fixups here refer to the addition of extra parentheses, braces or other characters, that * are required to preserve program semantics in a certain context (e.g. to maintain precedence * or because only certain expressions are allowed in certain places). * * @param int $fixup Fixup type * @param Node $subNode Subnode to print * @param string|null $parentClass Class of parent node * @param int $subStartPos Original start pos of subnode * @param int $subEndPos Original end pos of subnode * * @return string Result of fixed-up print of subnode */ protected function pFixup(int $fixup, Node $subNode, ?string $parentClass, int $subStartPos, int $subEndPos): string { switch ($fixup) { case self::FIXUP_PREC_LEFT: // We use a conservative approximation where lhsPrecedence == precedence. if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) { $precedence = $this->precedenceMap[$parentClass][1]; return $this->p($subNode, $precedence, $precedence); } break; case self::FIXUP_PREC_RIGHT: if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) { $precedence = $this->precedenceMap[$parentClass][2]; return $this->p($subNode, $precedence, $precedence); } break; case self::FIXUP_PREC_UNARY: if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) { $precedence = $this->precedenceMap[$parentClass][0]; return $this->p($subNode, $precedence, $precedence); } break; case self::FIXUP_CALL_LHS: if ($this->callLhsRequiresParens($subNode) && !$this->origTokens->haveParens($subStartPos, $subEndPos) ) { return '(' . $this->p($subNode) . ')'; } break; case self::FIXUP_DEREF_LHS: if ($this->dereferenceLhsRequiresParens($subNode) && !$this->origTokens->haveParens($subStartPos, $subEndPos) ) { return '(' . $this->p($subNode) . ')'; } break; case self::FIXUP_STATIC_DEREF_LHS: if ($this->staticDereferenceLhsRequiresParens($subNode) && !$this->origTokens->haveParens($subStartPos, $subEndPos) ) { return '(' . $this->p($subNode) . ')'; } break; case self::FIXUP_NEW: if ($this->newOperandRequiresParens($subNode) && !$this->origTokens->haveParens($subStartPos, $subEndPos)) { return '(' . $this->p($subNode) . ')'; } break; case self::FIXUP_BRACED_NAME: case self::FIXUP_VAR_BRACED_NAME: if ($subNode instanceof Expr && !$this->origTokens->haveBraces($subStartPos, $subEndPos) ) { return ($fixup === self::FIXUP_VAR_BRACED_NAME ? '$' : '') . '{' . $this->p($subNode) . '}'; } break; case self::FIXUP_ENCAPSED: if (!$subNode instanceof Node\InterpolatedStringPart && !$this->origTokens->haveBraces($subStartPos, $subEndPos) ) { return '{' . $this->p($subNode) . '}'; } break; default: throw new \Exception('Cannot happen'); } // Nothing special to do return $this->p($subNode); } /** * Appends to a string, ensuring whitespace between label characters. * * Example: "echo" and "$x" result in "echo$x", but "echo" and "x" result in "echo x". * Without safeAppend the result would be "echox", which does not preserve semantics. */ protected function safeAppend(string &$str, string $append): void { if ($str === "") { $str = $append; return; } if ($append === "") { return; } if (!$this->labelCharMap[$append[0]] || !$this->labelCharMap[$str[\strlen($str) - 1]]) { $str .= $append; } else { $str .= " " . $append; } } /** * Determines whether the LHS of a call must be wrapped in parenthesis. * * @param Node $node LHS of a call * * @return bool Whether parentheses are required */ protected function callLhsRequiresParens(Node $node): bool { if ($node instanceof Expr\New_) { return !$this->phpVersion->supportsNewDereferenceWithoutParentheses(); } return !($node instanceof Node\Name || $node instanceof Expr\Variable || $node instanceof Expr\ArrayDimFetch || $node instanceof Expr\FuncCall || $node instanceof Expr\MethodCall || $node instanceof Expr\NullsafeMethodCall || $node instanceof Expr\StaticCall || $node instanceof Expr\Array_); } /** * Determines whether the LHS of an array/object operation must be wrapped in parentheses. * * @param Node $node LHS of dereferencing operation * * @return bool Whether parentheses are required */ protected function dereferenceLhsRequiresParens(Node $node): bool { // A constant can occur on the LHS of an array/object deref, but not a static deref. return $this->staticDereferenceLhsRequiresParens($node) && !$node instanceof Expr\ConstFetch; } /** * Determines whether the LHS of a static operation must be wrapped in parentheses. * * @param Node $node LHS of dereferencing operation * * @return bool Whether parentheses are required */ protected function staticDereferenceLhsRequiresParens(Node $node): bool { if ($node instanceof Expr\New_) { return !$this->phpVersion->supportsNewDereferenceWithoutParentheses(); } return !($node instanceof Expr\Variable || $node instanceof Node\Name || $node instanceof Expr\ArrayDimFetch || $node instanceof Expr\PropertyFetch || $node instanceof Expr\NullsafePropertyFetch || $node instanceof Expr\StaticPropertyFetch || $node instanceof Expr\FuncCall || $node instanceof Expr\MethodCall || $node instanceof Expr\NullsafeMethodCall || $node instanceof Expr\StaticCall || $node instanceof Expr\Array_ || $node instanceof Scalar\String_ || $node instanceof Expr\ClassConstFetch); } /** * Determines whether an expression used in "new" or "instanceof" requires parentheses. * * @param Node $node New or instanceof operand * * @return bool Whether parentheses are required */ protected function newOperandRequiresParens(Node $node): bool { if ($node instanceof Node\Name || $node instanceof Expr\Variable) { return false; } if ($node instanceof Expr\ArrayDimFetch || $node instanceof Expr\PropertyFetch || $node instanceof Expr\NullsafePropertyFetch ) { return $this->newOperandRequiresParens($node->var); } if ($node instanceof Expr\StaticPropertyFetch) { return $this->newOperandRequiresParens($node->class); } return true; } /** * Print modifiers, including trailing whitespace. * * @param int $modifiers Modifier mask to print * * @return string Printed modifiers */ protected function pModifiers(int $modifiers): string { return ($modifiers & Modifiers::FINAL ? 'final ' : '') . ($modifiers & Modifiers::ABSTRACT ? 'abstract ' : '') . ($modifiers & Modifiers::PUBLIC ? 'public ' : '') . ($modifiers & Modifiers::PROTECTED ? 'protected ' : '') . ($modifiers & Modifiers::PRIVATE ? 'private ' : '') . ($modifiers & Modifiers::PUBLIC_SET ? 'public(set) ' : '') . ($modifiers & Modifiers::PROTECTED_SET ? 'protected(set) ' : '') . ($modifiers & Modifiers::PRIVATE_SET ? 'private(set) ' : '') . ($modifiers & Modifiers::STATIC ? 'static ' : '') . ($modifiers & Modifiers::READONLY ? 'readonly ' : ''); } protected function pStatic(bool $static): string { return $static ? 'static ' : ''; } /** * Determine whether a list of nodes uses multiline formatting. * * @param (Node|null)[] $nodes Node list * * @return bool Whether multiline formatting is used */ protected function isMultiline(array $nodes): bool { if (\count($nodes) < 2) { return false; } $pos = -1; foreach ($nodes as $node) { if (null === $node) { continue; } $endPos = $node->getEndTokenPos() + 1; if ($pos >= 0) { $text = $this->origTokens->getTokenCode($pos, $endPos, 0); if (false === strpos($text, "\n")) { // We require that a newline is present between *every* item. If the formatting // is inconsistent, with only some items having newlines, we don't consider it // as multiline return false; } } $pos = $endPos; } return true; } /** * Lazily initializes label char map. * * The label char map determines whether a certain character may occur in a label. */ protected function initializeLabelCharMap(): void { if (isset($this->labelCharMap)) { return; } $this->labelCharMap = []; for ($i = 0; $i < 256; $i++) { $chr = chr($i); $this->labelCharMap[$chr] = $i >= 0x80 || ctype_alnum($chr); } if ($this->phpVersion->allowsDelInIdentifiers()) { $this->labelCharMap["\x7f"] = true; } } /** * Lazily initializes node list differ. * * The node list differ is used to determine differences between two array subnodes. */ protected function initializeNodeListDiffer(): void { if (isset($this->nodeListDiffer)) { return; } $this->nodeListDiffer = new Internal\Differ(function ($a, $b) { if ($a instanceof Node && $b instanceof Node) { return $a === $b->getAttribute('origNode'); } // Can happen for array destructuring return $a === null && $b === null; }); } /** * Lazily initializes fixup map. * * The fixup map is used to determine whether a certain subnode of a certain node may require * some kind of "fixup" operation, e.g. the addition of parenthesis or braces. */ protected function initializeFixupMap(): void { if (isset($this->fixupMap)) { return; } $this->fixupMap = [ Expr\Instanceof_::class => [ 'expr' => self::FIXUP_PREC_UNARY, 'class' => self::FIXUP_NEW, ], Expr\Ternary::class => [ 'cond' => self::FIXUP_PREC_LEFT, 'else' => self::FIXUP_PREC_RIGHT, ], Expr\Yield_::class => ['value' => self::FIXUP_PREC_UNARY], Expr\FuncCall::class => ['name' => self::FIXUP_CALL_LHS], Expr\StaticCall::class => ['class' => self::FIXUP_STATIC_DEREF_LHS], Expr\ArrayDimFetch::class => ['var' => self::FIXUP_DEREF_LHS], Expr\ClassConstFetch::class => [ 'class' => self::FIXUP_STATIC_DEREF_LHS, 'name' => self::FIXUP_BRACED_NAME, ], Expr\New_::class => ['class' => self::FIXUP_NEW], Expr\MethodCall::class => [ 'var' => self::FIXUP_DEREF_LHS, 'name' => self::FIXUP_BRACED_NAME, ], Expr\NullsafeMethodCall::class => [ 'var' => self::FIXUP_DEREF_LHS, 'name' => self::FIXUP_BRACED_NAME, ], Expr\StaticPropertyFetch::class => [ 'class' => self::FIXUP_STATIC_DEREF_LHS, 'name' => self::FIXUP_VAR_BRACED_NAME, ], Expr\PropertyFetch::class => [ 'var' => self::FIXUP_DEREF_LHS, 'name' => self::FIXUP_BRACED_NAME, ], Expr\NullsafePropertyFetch::class => [ 'var' => self::FIXUP_DEREF_LHS, 'name' => self::FIXUP_BRACED_NAME, ], Scalar\InterpolatedString::class => [ 'parts' => self::FIXUP_ENCAPSED, ], ]; $binaryOps = [ BinaryOp\Pow::class, BinaryOp\Mul::class, BinaryOp\Div::class, BinaryOp\Mod::class, BinaryOp\Plus::class, BinaryOp\Minus::class, BinaryOp\Concat::class, BinaryOp\ShiftLeft::class, BinaryOp\ShiftRight::class, BinaryOp\Smaller::class, BinaryOp\SmallerOrEqual::class, BinaryOp\Greater::class, BinaryOp\GreaterOrEqual::class, BinaryOp\Equal::class, BinaryOp\NotEqual::class, BinaryOp\Identical::class, BinaryOp\NotIdentical::class, BinaryOp\Spaceship::class, BinaryOp\BitwiseAnd::class, BinaryOp\BitwiseXor::class, BinaryOp\BitwiseOr::class, BinaryOp\BooleanAnd::class, BinaryOp\BooleanOr::class, BinaryOp\Coalesce::class, BinaryOp\LogicalAnd::class, BinaryOp\LogicalXor::class, BinaryOp\LogicalOr::class, BinaryOp\Pipe::class, ]; foreach ($binaryOps as $binaryOp) { $this->fixupMap[$binaryOp] = [ 'left' => self::FIXUP_PREC_LEFT, 'right' => self::FIXUP_PREC_RIGHT ]; } $prefixOps = [ Expr\Clone_::class, Expr\BitwiseNot::class, Expr\BooleanNot::class, Expr\UnaryPlus::class, Expr\UnaryMinus::class, Cast\Int_::class, Cast\Double::class, Cast\String_::class, Cast\Array_::class, Cast\Object_::class, Cast\Bool_::class, Cast\Unset_::class, Expr\ErrorSuppress::class, Expr\YieldFrom::class, Expr\Print_::class, Expr\Include_::class, Expr\Assign::class, Expr\AssignRef::class, AssignOp\Plus::class, AssignOp\Minus::class, AssignOp\Mul::class, AssignOp\Div::class, AssignOp\Concat::class, AssignOp\Mod::class, AssignOp\BitwiseAnd::class, AssignOp\BitwiseOr::class, AssignOp\BitwiseXor::class, AssignOp\ShiftLeft::class, AssignOp\ShiftRight::class, AssignOp\Pow::class, AssignOp\Coalesce::class, Expr\ArrowFunction::class, Expr\Throw_::class, ]; foreach ($prefixOps as $prefixOp) { $this->fixupMap[$prefixOp] = ['expr' => self::FIXUP_PREC_UNARY]; } } /** * Lazily initializes the removal map. * * The removal map is used to determine which additional tokens should be removed when a * certain node is replaced by null. */ protected function initializeRemovalMap(): void { if (isset($this->removalMap)) { return; } $stripBoth = ['left' => \T_WHITESPACE, 'right' => \T_WHITESPACE]; $stripLeft = ['left' => \T_WHITESPACE]; $stripRight = ['right' => \T_WHITESPACE]; $stripDoubleArrow = ['right' => \T_DOUBLE_ARROW]; $stripColon = ['left' => ':']; $stripEquals = ['left' => '=']; $this->removalMap = [ 'Expr_ArrayDimFetch->dim' => $stripBoth, 'ArrayItem->key' => $stripDoubleArrow, 'Expr_ArrowFunction->returnType' => $stripColon, 'Expr_Closure->returnType' => $stripColon, 'Expr_Exit->expr' => $stripBoth, 'Expr_Ternary->if' => $stripBoth, 'Expr_Yield->key' => $stripDoubleArrow, 'Expr_Yield->value' => $stripBoth, 'Param->type' => $stripRight, 'Param->default' => $stripEquals, 'Stmt_Break->num' => $stripBoth, 'Stmt_Catch->var' => $stripLeft, 'Stmt_ClassConst->type' => $stripRight, 'Stmt_ClassMethod->returnType' => $stripColon, 'Stmt_Class->extends' => ['left' => \T_EXTENDS], 'Stmt_Enum->scalarType' => $stripColon, 'Stmt_EnumCase->expr' => $stripEquals, 'Expr_PrintableNewAnonClass->extends' => ['left' => \T_EXTENDS], 'Stmt_Continue->num' => $stripBoth, 'Stmt_Foreach->keyVar' => $stripDoubleArrow, 'Stmt_Function->returnType' => $stripColon, 'Stmt_If->else' => $stripLeft, 'Stmt_Namespace->name' => $stripLeft, 'Stmt_Property->type' => $stripRight, 'PropertyItem->default' => $stripEquals, 'Stmt_Return->expr' => $stripBoth, 'Stmt_StaticVar->default' => $stripEquals, 'Stmt_TraitUseAdaptation_Alias->newName' => $stripLeft, 'Stmt_TryCatch->finally' => $stripLeft, // 'Stmt_Case->cond': Replace with "default" // 'Stmt_Class->name': Unclear what to do // 'Stmt_Declare->stmts': Not a plain node // 'Stmt_TraitUseAdaptation_Alias->newModifier': Not a plain node ]; } protected function initializeInsertionMap(): void { if (isset($this->insertionMap)) { return; } // TODO: "yield" where both key and value are inserted doesn't work // [$find, $beforeToken, $extraLeft, $extraRight] $this->insertionMap = [ 'Expr_ArrayDimFetch->dim' => ['[', false, null, null], 'ArrayItem->key' => [null, false, null, ' => '], 'Expr_ArrowFunction->returnType' => [')', false, ': ', null], 'Expr_Closure->returnType' => [')', false, ': ', null], 'Expr_Ternary->if' => ['?', false, ' ', ' '], 'Expr_Yield->key' => [\T_YIELD, false, null, ' => '], 'Expr_Yield->value' => [\T_YIELD, false, ' ', null], 'Param->type' => [null, false, null, ' '], 'Param->default' => [null, false, ' = ', null], 'Stmt_Break->num' => [\T_BREAK, false, ' ', null], 'Stmt_Catch->var' => [null, false, ' ', null], 'Stmt_ClassMethod->returnType' => [')', false, ': ', null], 'Stmt_ClassConst->type' => [\T_CONST, false, ' ', null], 'Stmt_Class->extends' => [null, false, ' extends ', null], 'Stmt_Enum->scalarType' => [null, false, ' : ', null], 'Stmt_EnumCase->expr' => [null, false, ' = ', null], 'Expr_PrintableNewAnonClass->extends' => [null, false, ' extends ', null], 'Stmt_Continue->num' => [\T_CONTINUE, false, ' ', null], 'Stmt_Foreach->keyVar' => [\T_AS, false, null, ' => '], 'Stmt_Function->returnType' => [')', false, ': ', null], 'Stmt_If->else' => [null, false, ' ', null], 'Stmt_Namespace->name' => [\T_NAMESPACE, false, ' ', null], 'Stmt_Property->type' => [\T_VARIABLE, true, null, ' '], 'PropertyItem->default' => [null, false, ' = ', null], 'Stmt_Return->expr' => [\T_RETURN, false, ' ', null], 'Stmt_StaticVar->default' => [null, false, ' = ', null], //'Stmt_TraitUseAdaptation_Alias->newName' => [T_AS, false, ' ', null], // TODO 'Stmt_TryCatch->finally' => [null, false, ' ', null], // 'Expr_Exit->expr': Complicated due to optional () // 'Stmt_Case->cond': Conversion from default to case // 'Stmt_Class->name': Unclear // 'Stmt_Declare->stmts': Not a proper node // 'Stmt_TraitUseAdaptation_Alias->newModifier': Not a proper node ]; } protected function initializeListInsertionMap(): void { if (isset($this->listInsertionMap)) { return; } $this->listInsertionMap = [ // special //'Expr_ShellExec->parts' => '', // TODO These need to be treated more carefully //'Scalar_InterpolatedString->parts' => '', Stmt\Catch_::class . '->types' => '|', UnionType::class . '->types' => '|', IntersectionType::class . '->types' => '&', Stmt\If_::class . '->elseifs' => ' ', Stmt\TryCatch::class . '->catches' => ' ', // comma-separated lists Expr\Array_::class . '->items' => ', ', Expr\ArrowFunction::class . '->params' => ', ', Expr\Closure::class . '->params' => ', ', Expr\Closure::class . '->uses' => ', ', Expr\FuncCall::class . '->args' => ', ', Expr\Isset_::class . '->vars' => ', ', Expr\List_::class . '->items' => ', ', Expr\MethodCall::class . '->args' => ', ', Expr\NullsafeMethodCall::class . '->args' => ', ', Expr\New_::class . '->args' => ', ', PrintableNewAnonClassNode::class . '->args' => ', ', Expr\StaticCall::class . '->args' => ', ', Stmt\ClassConst::class . '->consts' => ', ', Stmt\ClassMethod::class . '->params' => ', ', Stmt\Class_::class . '->implements' => ', ', Stmt\Enum_::class . '->implements' => ', ', PrintableNewAnonClassNode::class . '->implements' => ', ', Stmt\Const_::class . '->consts' => ', ', Stmt\Declare_::class . '->declares' => ', ', Stmt\Echo_::class . '->exprs' => ', ', Stmt\For_::class . '->init' => ', ', Stmt\For_::class . '->cond' => ', ', Stmt\For_::class . '->loop' => ', ', Stmt\Function_::class . '->params' => ', ', Stmt\Global_::class . '->vars' => ', ', Stmt\GroupUse::class . '->uses' => ', ', Stmt\Interface_::class . '->extends' => ', ', Expr\Match_::class . '->arms' => ', ', Stmt\Property::class . '->props' => ', ', Stmt\StaticVar::class . '->vars' => ', ', Stmt\TraitUse::class . '->traits' => ', ', Stmt\TraitUseAdaptation\Precedence::class . '->insteadof' => ', ', Stmt\Unset_::class . '->vars' => ', ', Stmt\UseUse::class . '->uses' => ', ', MatchArm::class . '->conds' => ', ', AttributeGroup::class . '->attrs' => ', ', PropertyHook::class . '->params' => ', ', // statement lists Expr\Closure::class . '->stmts' => "\n", Stmt\Case_::class . '->stmts' => "\n", Stmt\Catch_::class . '->stmts' => "\n", Stmt\Class_::class . '->stmts' => "\n", Stmt\Enum_::class . '->stmts' => "\n", PrintableNewAnonClassNode::class . '->stmts' => "\n", Stmt\Interface_::class . '->stmts' => "\n", Stmt\Trait_::class . '->stmts' => "\n", Stmt\ClassMethod::class . '->stmts' => "\n", Stmt\Declare_::class . '->stmts' => "\n", Stmt\Do_::class . '->stmts' => "\n", Stmt\ElseIf_::class . '->stmts' => "\n", Stmt\Else_::class . '->stmts' => "\n", Stmt\Finally_::class . '->stmts' => "\n", Stmt\Foreach_::class . '->stmts' => "\n", Stmt\For_::class . '->stmts' => "\n", Stmt\Function_::class . '->stmts' => "\n", Stmt\If_::class . '->stmts' => "\n", Stmt\Namespace_::class . '->stmts' => "\n", Stmt\Block::class . '->stmts' => "\n", // Attribute groups Stmt\Class_::class . '->attrGroups' => "\n", Stmt\Enum_::class . '->attrGroups' => "\n", Stmt\EnumCase::class . '->attrGroups' => "\n", Stmt\Interface_::class . '->attrGroups' => "\n", Stmt\Trait_::class . '->attrGroups' => "\n", Stmt\Function_::class . '->attrGroups' => "\n", Stmt\ClassMethod::class . '->attrGroups' => "\n", Stmt\ClassConst::class . '->attrGroups' => "\n", Stmt\Property::class . '->attrGroups' => "\n", PrintableNewAnonClassNode::class . '->attrGroups' => ' ', Expr\Closure::class . '->attrGroups' => ' ', Expr\ArrowFunction::class . '->attrGroups' => ' ', Param::class . '->attrGroups' => ' ', PropertyHook::class . '->attrGroups' => ' ', Stmt\Switch_::class . '->cases' => "\n", Stmt\TraitUse::class . '->adaptations' => "\n", Stmt\TryCatch::class . '->stmts' => "\n", Stmt\While_::class . '->stmts' => "\n", PropertyHook::class . '->body' => "\n", Stmt\Property::class . '->hooks' => "\n", Param::class . '->hooks' => "\n", // dummy for top-level context 'File->stmts' => "\n", ]; } protected function initializeEmptyListInsertionMap(): void { if (isset($this->emptyListInsertionMap)) { return; } // TODO Insertion into empty statement lists. // [$find, $extraLeft, $extraRight] $this->emptyListInsertionMap = [ Expr\ArrowFunction::class . '->params' => ['(', '', ''], Expr\Closure::class . '->uses' => [')', ' use (', ')'], Expr\Closure::class . '->params' => ['(', '', ''], Expr\FuncCall::class . '->args' => ['(', '', ''], Expr\MethodCall::class . '->args' => ['(', '', ''], Expr\NullsafeMethodCall::class . '->args' => ['(', '', ''], Expr\New_::class . '->args' => ['(', '', ''], PrintableNewAnonClassNode::class . '->args' => ['(', '', ''], PrintableNewAnonClassNode::class . '->implements' => [null, ' implements ', ''], Expr\StaticCall::class . '->args' => ['(', '', ''], Stmt\Class_::class . '->implements' => [null, ' implements ', ''], Stmt\Enum_::class . '->implements' => [null, ' implements ', ''], Stmt\ClassMethod::class . '->params' => ['(', '', ''], Stmt\Interface_::class . '->extends' => [null, ' extends ', ''], Stmt\Function_::class . '->params' => ['(', '', ''], Stmt\Interface_::class . '->attrGroups' => [null, '', "\n"], Stmt\Class_::class . '->attrGroups' => [null, '', "\n"], Stmt\ClassConst::class . '->attrGroups' => [null, '', "\n"], Stmt\ClassMethod::class . '->attrGroups' => [null, '', "\n"], Stmt\Function_::class . '->attrGroups' => [null, '', "\n"], Stmt\Property::class . '->attrGroups' => [null, '', "\n"], Stmt\Trait_::class . '->attrGroups' => [null, '', "\n"], Expr\ArrowFunction::class . '->attrGroups' => [null, '', ' '], Expr\Closure::class . '->attrGroups' => [null, '', ' '], Stmt\Const_::class . '->attrGroups' => [null, '', "\n"], PrintableNewAnonClassNode::class . '->attrGroups' => [\T_NEW, ' ', ''], /* These cannot be empty to start with: * Expr_Isset->vars * Stmt_Catch->types * Stmt_Const->consts * Stmt_ClassConst->consts * Stmt_Declare->declares * Stmt_Echo->exprs * Stmt_Global->vars * Stmt_GroupUse->uses * Stmt_Property->props * Stmt_StaticVar->vars * Stmt_TraitUse->traits * Stmt_TraitUseAdaptation_Precedence->insteadof * Stmt_Unset->vars * Stmt_Use->uses * UnionType->types */ /* TODO * Stmt_If->elseifs * Stmt_TryCatch->catches * Expr_Array->items * Expr_List->items * Stmt_For->init * Stmt_For->cond * Stmt_For->loop */ ]; } protected function initializeModifierChangeMap(): void { if (isset($this->modifierChangeMap)) { return; } $this->modifierChangeMap = [ Stmt\ClassConst::class . '->flags' => ['pModifiers', \T_WHITESPACE, \T_CONST], Stmt\ClassMethod::class . '->flags' => ['pModifiers', \T_WHITESPACE, \T_FUNCTION], Stmt\Class_::class . '->flags' => ['pModifiers', \T_WHITESPACE, \T_CLASS], Stmt\Property::class . '->flags' => ['pModifiers', \T_WHITESPACE, \T_VARIABLE], PrintableNewAnonClassNode::class . '->flags' => ['pModifiers', \T_NEW, \T_CLASS], Param::class . '->flags' => ['pModifiers', \T_WHITESPACE, \T_VARIABLE], PropertyHook::class . '->flags' => ['pModifiers', \T_WHITESPACE, \T_STRING], Expr\Closure::class . '->static' => ['pStatic', \T_WHITESPACE, \T_FUNCTION], Expr\ArrowFunction::class . '->static' => ['pStatic', \T_WHITESPACE, \T_FN], //Stmt\TraitUseAdaptation\Alias::class . '->newModifier' => 0, // TODO ]; // List of integer subnodes that are not modifiers: // Expr_Include->type // Stmt_GroupUse->type // Stmt_Use->type // UseItem->type } } ================================================ FILE: lib/PhpParser/Token.php ================================================ pos + \strlen($this->text); } /** Get 1-based end line number of the token. */ public function getEndLine(): int { return $this->line + \substr_count($this->text, "\n"); } } ================================================ FILE: lib/PhpParser/compatibility_tokens.php ================================================ \|null but return statement is missing\.$#' identifier: return.missing count: 1 path: lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php - message: '#^Method PhpParser\\NodeVisitor\\NodeConnectingVisitor\:\:enterNode\(\) should return array\\|int\|PhpParser\\Node\|null but return statement is missing\.$#' identifier: return.missing count: 1 path: lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php - message: '#^Method PhpParser\\NodeVisitor\\NodeConnectingVisitor\:\:leaveNode\(\) should return array\\|int\|PhpParser\\Node\|null but return statement is missing\.$#' identifier: return.missing count: 1 path: lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php - message: '#^Method PhpParser\\NodeVisitor\\ParentConnectingVisitor\:\:beforeTraverse\(\) should return array\\|null but return statement is missing\.$#' identifier: return.missing count: 1 path: lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php - message: '#^Method PhpParser\\NodeVisitor\\ParentConnectingVisitor\:\:enterNode\(\) should return array\\|int\|PhpParser\\Node\|null but return statement is missing\.$#' identifier: return.missing count: 1 path: lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php - message: '#^Method PhpParser\\NodeVisitor\\ParentConnectingVisitor\:\:leaveNode\(\) should return array\\|int\|PhpParser\\Node\|null but return statement is missing\.$#' identifier: return.missing count: 1 path: lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php - message: '#^Access to undefined constant static\(PhpParser\\ParserAbstract\)\:\:T_ECHO\.$#' identifier: classConstant.notFound count: 1 path: lib/PhpParser/ParserAbstract.php - message: '#^Unary operation "\+" on string results in an error\.$#' identifier: unaryOp.invalid count: 1 path: lib/PhpParser/ParserAbstract.php - message: '#^Variable \$action might not be defined\.$#' identifier: variable.undefined count: 1 path: lib/PhpParser/ParserAbstract.php ================================================ FILE: phpstan.neon.dist ================================================ includes: - phpstan-baseline.neon parameters: level: 6 paths: - lib treatPhpDocTypesAsCertain: false ================================================ FILE: phpunit.xml.dist ================================================ ./test/ ./lib/PhpParser/ ================================================ FILE: test/PhpParser/Builder/ClassConstTest.php ================================================ createClassConstBuilder("TEST", 1) ->makePrivate() ->getNode() ; $this->assertEquals( new Stmt\ClassConst( [ new Const_("TEST", new Int_(1)) ], Modifiers::PRIVATE ), $node ); $node = $this->createClassConstBuilder("TEST", 1) ->makeProtected() ->getNode() ; $this->assertEquals( new Stmt\ClassConst( [ new Const_("TEST", new Int_(1)) ], Modifiers::PROTECTED ), $node ); $node = $this->createClassConstBuilder("TEST", 1) ->makePublic() ->getNode() ; $this->assertEquals( new Stmt\ClassConst( [ new Const_("TEST", new Int_(1)) ], Modifiers::PUBLIC ), $node ); $node = $this->createClassConstBuilder("TEST", 1) ->makeFinal() ->getNode() ; $this->assertEquals( new Stmt\ClassConst( [ new Const_("TEST", new Int_(1)) ], Modifiers::FINAL ), $node ); } public function testDocComment(): void { $node = $this->createClassConstBuilder('TEST', 1) ->setDocComment('/** Test */') ->makePublic() ->getNode(); $this->assertEquals( new Stmt\ClassConst( [ new Const_("TEST", new Int_(1)) ], Modifiers::PUBLIC, [ 'comments' => [new Comment\Doc('/** Test */')] ] ), $node ); } public function testAddConst(): void { $node = $this->createClassConstBuilder('FIRST_TEST', 1) ->addConst("SECOND_TEST", 2) ->getNode(); $this->assertEquals( new Stmt\ClassConst( [ new Const_("FIRST_TEST", new Int_(1)), new Const_("SECOND_TEST", new Int_(2)) ] ), $node ); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $node = $this->createClassConstBuilder('ATTR_GROUP', 1) ->addAttribute($attributeGroup) ->getNode(); $this->assertEquals( new Stmt\ClassConst( [ new Const_("ATTR_GROUP", new Int_(1)) ], 0, [], [$attributeGroup] ), $node ); } public function testType(): void { $node = $this->createClassConstBuilder('TYPE', 1) ->setType('int') ->getNode(); $this->assertEquals( new Stmt\ClassConst( [new Const_('TYPE', new Int_(1))], 0, [], [], new Identifier('int')), $node ); } /** * @dataProvider provideTestDefaultValues */ public function testValues($value, $expectedValueNode): void { $node = $this->createClassConstBuilder('TEST', $value) ->getNode() ; $this->assertEquals($expectedValueNode, $node->consts[0]->value); } public static function provideTestDefaultValues() { return [ [ null, new Expr\ConstFetch(new Name('null')) ], [ true, new Expr\ConstFetch(new Name('true')) ], [ false, new Expr\ConstFetch(new Name('false')) ], [ 31415, new Scalar\Int_(31415) ], [ 3.1415, new Scalar\Float_(3.1415) ], [ 'Hallo World', new Scalar\String_('Hallo World') ], [ [1, 2, 3], new Expr\Array_([ new \PhpParser\Node\ArrayItem(new Scalar\Int_(1)), new \PhpParser\Node\ArrayItem(new Scalar\Int_(2)), new \PhpParser\Node\ArrayItem(new Scalar\Int_(3)), ]) ], [ ['foo' => 'bar', 'bar' => 'foo'], new Expr\Array_([ new \PhpParser\Node\ArrayItem( new Scalar\String_('bar'), new Scalar\String_('foo') ), new \PhpParser\Node\ArrayItem( new Scalar\String_('foo'), new Scalar\String_('bar') ), ]) ], [ new Scalar\MagicConst\Dir(), new Scalar\MagicConst\Dir() ] ]; } } ================================================ FILE: test/PhpParser/Builder/ClassTest.php ================================================ createClassBuilder('SomeLogger') ->extend('BaseLogger') ->implement('Namespaced\Logger', new Name('SomeInterface')) ->implement('\Fully\Qualified', 'namespace\NamespaceRelative') ->getNode() ; $this->assertEquals( new Stmt\Class_('SomeLogger', [ 'extends' => new Name('BaseLogger'), 'implements' => [ new Name('Namespaced\Logger'), new Name('SomeInterface'), new Name\FullyQualified('Fully\Qualified'), new Name\Relative('NamespaceRelative'), ], ]), $node ); } public function testAbstract(): void { $node = $this->createClassBuilder('Test') ->makeAbstract() ->getNode() ; $this->assertEquals( new Stmt\Class_('Test', [ 'flags' => Modifiers::ABSTRACT ]), $node ); } public function testFinal(): void { $node = $this->createClassBuilder('Test') ->makeFinal() ->getNode() ; $this->assertEquals( new Stmt\Class_('Test', [ 'flags' => Modifiers::FINAL ]), $node ); } public function testReadonly(): void { $node = $this->createClassBuilder('Test') ->makeReadonly() ->getNode() ; $this->assertEquals( new Stmt\Class_('Test', [ 'flags' => Modifiers::READONLY ]), $node ); } public function testStatementOrder(): void { $method = new Stmt\ClassMethod('testMethod'); $property = new Stmt\Property( Modifiers::PUBLIC, [new Node\PropertyItem('testProperty')] ); $const = new Stmt\ClassConst([ new Node\Const_('TEST_CONST', new Node\Scalar\String_('ABC')) ]); $use = new Stmt\TraitUse([new Name('SomeTrait')]); $node = $this->createClassBuilder('Test') ->addStmt($method) ->addStmt($property) ->addStmts([$const, $use]) ->getNode() ; $this->assertEquals( new Stmt\Class_('Test', [ 'stmts' => [$use, $const, $property, $method] ]), $node ); } public function testDocComment(): void { $docComment = <<<'DOC' /** * Test */ DOC; $class = $this->createClassBuilder('Test') ->setDocComment($docComment) ->getNode(); $this->assertEquals( new Stmt\Class_('Test', [], [ 'comments' => [ new Comment\Doc($docComment) ] ]), $class ); $class = $this->createClassBuilder('Test') ->setDocComment(new Comment\Doc($docComment)) ->getNode(); $this->assertEquals( new Stmt\Class_('Test', [], [ 'comments' => [ new Comment\Doc($docComment) ] ]), $class ); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $class = $this->createClassBuilder('ATTR_GROUP') ->addAttribute($attributeGroup) ->getNode(); $this->assertEquals( new Stmt\Class_('ATTR_GROUP', [ 'attrGroups' => [ $attributeGroup, ] ], []), $class ); } public function testInvalidStmtError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Unexpected node of type "Stmt_Echo"'); $this->createClassBuilder('Test') ->addStmt(new Stmt\Echo_([])) ; } public function testInvalidDocComment(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Doc comment must be a string or an instance of PhpParser\Comment\Doc'); $this->createClassBuilder('Test') ->setDocComment(new Comment('Test')); } public function testEmptyName(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name cannot be empty'); $this->createClassBuilder('Test') ->extend(''); } public function testInvalidName(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name must be a string or an instance of Node\Name'); $this->createClassBuilder('Test') ->extend(['Foo']); } } ================================================ FILE: test/PhpParser/Builder/EnumCaseTest.php ================================================ createEnumCaseBuilder('TEST') ->setDocComment('/** Test */') ->getNode(); $this->assertEquals( new Stmt\EnumCase( "TEST", null, [], [ 'comments' => [new Comment\Doc('/** Test */')] ] ), $node ); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $node = $this->createEnumCaseBuilder('ATTR_GROUP') ->addAttribute($attributeGroup) ->getNode(); $this->assertEquals( new Stmt\EnumCase( "ATTR_GROUP", null, [$attributeGroup] ), $node ); } /** * @dataProvider provideTestDefaultValues */ public function testValues($value, $expectedValueNode): void { $node = $this->createEnumCaseBuilder('TEST') ->setValue($value) ->getNode() ; $this->assertEquals($expectedValueNode, $node->expr); } public static function provideTestDefaultValues() { return [ [ 31415, new Scalar\Int_(31415) ], [ 'Hallo World', new Scalar\String_('Hallo World') ], ]; } } ================================================ FILE: test/PhpParser/Builder/EnumTest.php ================================================ createEnumBuilder('SomeEnum') ->implement('Namespaced\SomeInterface', new Name('OtherInterface')) ->getNode() ; $this->assertEquals( new Stmt\Enum_('SomeEnum', [ 'implements' => [ new Name('Namespaced\SomeInterface'), new Name('OtherInterface'), ], ]), $node ); } public function testSetScalarType(): void { $node = $this->createEnumBuilder('Test') ->setScalarType('int') ->getNode() ; $this->assertEquals( new Stmt\Enum_('Test', [ 'scalarType' => new Identifier('int'), ]), $node ); } public function testStatementOrder(): void { $method = new Stmt\ClassMethod('testMethod'); $enumCase = new Stmt\EnumCase( 'TEST_ENUM_CASE' ); $const = new Stmt\ClassConst([ new Node\Const_('TEST_CONST', new Node\Scalar\String_('ABC')) ]); $use = new Stmt\TraitUse([new Name('SomeTrait')]); $node = $this->createEnumBuilder('Test') ->addStmt($method) ->addStmt($enumCase) ->addStmts([$const, $use]) ->getNode() ; $this->assertEquals( new Stmt\Enum_('Test', [ 'stmts' => [$use, $enumCase, $const, $method] ]), $node ); } public function testDocComment(): void { $docComment = <<<'DOC' /** * Test */ DOC; $enum = $this->createEnumBuilder('Test') ->setDocComment($docComment) ->getNode(); $this->assertEquals( new Stmt\Enum_('Test', [], [ 'comments' => [ new Comment\Doc($docComment) ] ]), $enum ); $enum = $this->createEnumBuilder('Test') ->setDocComment(new Comment\Doc($docComment)) ->getNode(); $this->assertEquals( new Stmt\Enum_('Test', [], [ 'comments' => [ new Comment\Doc($docComment) ] ]), $enum ); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $enum = $this->createEnumBuilder('ATTR_GROUP') ->addAttribute($attributeGroup) ->getNode(); $this->assertEquals( new Stmt\Enum_('ATTR_GROUP', [ 'attrGroups' => [ $attributeGroup, ] ], []), $enum ); } public function testInvalidStmtError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Unexpected node of type "PropertyItem"'); $this->createEnumBuilder('Test') ->addStmt(new Node\PropertyItem('property')) ; } public function testInvalidDocComment(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Doc comment must be a string or an instance of PhpParser\Comment\Doc'); $this->createEnumBuilder('Test') ->setDocComment(new Comment('Test')); } public function testEmptyName(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name cannot be empty'); $this->createEnumBuilder('Test') ->implement(''); } public function testInvalidName(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name must be a string or an instance of Node\Name'); $this->createEnumBuilder('Test') ->implement(['Foo']); } } ================================================ FILE: test/PhpParser/Builder/FunctionTest.php ================================================ createFunctionBuilder('test') ->makeReturnByRef() ->getNode() ; $this->assertEquals( new Stmt\Function_('test', [ 'byRef' => true ]), $node ); } public function testParams(): void { $param1 = new Node\Param(new Variable('test1')); $param2 = new Node\Param(new Variable('test2')); $param3 = new Node\Param(new Variable('test3')); $node = $this->createFunctionBuilder('test') ->addParam($param1) ->addParams([$param2, $param3]) ->getNode() ; $this->assertEquals( new Stmt\Function_('test', [ 'params' => [$param1, $param2, $param3] ]), $node ); } public function testStmts(): void { $stmt1 = new Print_(new String_('test1')); $stmt2 = new Print_(new String_('test2')); $stmt3 = new Print_(new String_('test3')); $node = $this->createFunctionBuilder('test') ->addStmt($stmt1) ->addStmts([$stmt2, $stmt3]) ->getNode() ; $this->assertEquals( new Stmt\Function_('test', [ 'stmts' => [ new Stmt\Expression($stmt1), new Stmt\Expression($stmt2), new Stmt\Expression($stmt3), ] ]), $node ); } public function testDocComment(): void { $node = $this->createFunctionBuilder('test') ->setDocComment('/** Test */') ->getNode(); $this->assertEquals(new Stmt\Function_('test', [], [ 'comments' => [new Comment\Doc('/** Test */')] ]), $node); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $node = $this->createFunctionBuilder('attrGroup') ->addAttribute($attributeGroup) ->getNode(); $this->assertEquals(new Stmt\Function_('attrGroup', [ 'attrGroups' => [$attributeGroup], ], []), $node); } public function testReturnType(): void { $node = $this->createFunctionBuilder('test') ->setReturnType('void') ->getNode(); $this->assertEquals(new Stmt\Function_('test', [ 'returnType' => new Identifier('void'), ], []), $node); } public function testInvalidNullableVoidType(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('void type cannot be nullable'); $this->createFunctionBuilder('test')->setReturnType('?void'); } public function testInvalidParamError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected parameter node, got "Name"'); $this->createFunctionBuilder('test') ->addParam(new Node\Name('foo')) ; } public function testAddNonStmt(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected statement or expression node'); $this->createFunctionBuilder('test') ->addStmt(new Node\Name('Test')); } } ================================================ FILE: test/PhpParser/Builder/InterfaceTest.php ================================================ prettyPrint([$node]); } public function testEmpty(): void { $contract = $this->createInterfaceBuilder()->getNode(); $this->assertInstanceOf(Stmt\Interface_::class, $contract); $this->assertEquals(new Node\Identifier('Contract'), $contract->name); } public function testExtending(): void { $contract = $this->createInterfaceBuilder() ->extend('Space\Root1', 'Root2')->getNode(); $this->assertEquals( new Stmt\Interface_('Contract', [ 'extends' => [ new Node\Name('Space\Root1'), new Node\Name('Root2') ], ]), $contract ); } public function testAddMethod(): void { $method = new Stmt\ClassMethod('doSomething'); $contract = $this->createInterfaceBuilder()->addStmt($method)->getNode(); $this->assertSame([$method], $contract->stmts); } public function testAddConst(): void { $const = new Stmt\ClassConst([ new Node\Const_('SPEED_OF_LIGHT', new Float_(299792458.0)) ]); $contract = $this->createInterfaceBuilder()->addStmt($const)->getNode(); $this->assertSame(299792458.0, $contract->stmts[0]->consts[0]->value->value); } public function testOrder(): void { $const = new Stmt\ClassConst([ new Node\Const_('SPEED_OF_LIGHT', new Float_(299792458)) ]); $method = new Stmt\ClassMethod('doSomething'); $contract = $this->createInterfaceBuilder() ->addStmt($method) ->addStmt($const) ->getNode() ; $this->assertInstanceOf(Stmt\ClassConst::class, $contract->stmts[0]); $this->assertInstanceOf(Stmt\ClassMethod::class, $contract->stmts[1]); } public function testDocComment(): void { $node = $this->createInterfaceBuilder() ->setDocComment('/** Test */') ->getNode(); $this->assertEquals(new Stmt\Interface_('Contract', [], [ 'comments' => [new Comment\Doc('/** Test */')] ]), $node); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $node = $this->createInterfaceBuilder() ->addAttribute($attributeGroup) ->getNode(); $this->assertEquals(new Stmt\Interface_('Contract', [ 'attrGroups' => [$attributeGroup], ], []), $node); } public function testInvalidStmtError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Unexpected node of type "PropertyItem"'); $this->createInterfaceBuilder()->addStmt(new Node\PropertyItem('invalid')); } public function testFullFunctional(): void { $const = new Stmt\ClassConst([ new Node\Const_('SPEED_OF_LIGHT', new Float_(299792458)) ]); $method = new Stmt\ClassMethod('doSomething'); $contract = $this->createInterfaceBuilder() ->addStmt($method) ->addStmt($const) ->getNode() ; eval($this->dump($contract)); $this->assertTrue(interface_exists('Contract', false)); } } ================================================ FILE: test/PhpParser/Builder/MethodTest.php ================================================ createMethodBuilder('test') ->makePublic() ->makeAbstract() ->makeStatic() ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', [ 'flags' => Modifiers::PUBLIC | Modifiers::ABSTRACT | Modifiers::STATIC, 'stmts' => null, ]), $node ); $node = $this->createMethodBuilder('test') ->makeProtected() ->makeFinal() ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', [ 'flags' => Modifiers::PROTECTED | Modifiers::FINAL ]), $node ); $node = $this->createMethodBuilder('test') ->makePrivate() ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', [ 'type' => Modifiers::PRIVATE ]), $node ); } public function testReturnByRef(): void { $node = $this->createMethodBuilder('test') ->makeReturnByRef() ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', [ 'byRef' => true ]), $node ); } public function testParams(): void { $param1 = new Node\Param(new Variable('test1')); $param2 = new Node\Param(new Variable('test2')); $param3 = new Node\Param(new Variable('test3')); $node = $this->createMethodBuilder('test') ->addParam($param1) ->addParams([$param2, $param3]) ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', [ 'params' => [$param1, $param2, $param3] ]), $node ); } public function testStmts(): void { $stmt1 = new Print_(new String_('test1')); $stmt2 = new Print_(new String_('test2')); $stmt3 = new Print_(new String_('test3')); $node = $this->createMethodBuilder('test') ->addStmt($stmt1) ->addStmts([$stmt2, $stmt3]) ->getNode() ; $this->assertEquals( new Stmt\ClassMethod('test', [ 'stmts' => [ new Stmt\Expression($stmt1), new Stmt\Expression($stmt2), new Stmt\Expression($stmt3), ] ]), $node ); } public function testDocComment(): void { $node = $this->createMethodBuilder('test') ->setDocComment('/** Test */') ->getNode(); $this->assertEquals(new Stmt\ClassMethod('test', [], [ 'comments' => [new Comment\Doc('/** Test */')] ]), $node); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $node = $this->createMethodBuilder('attributeGroup') ->addAttribute($attributeGroup) ->getNode(); $this->assertEquals(new Stmt\ClassMethod('attributeGroup', [ 'attrGroups' => [$attributeGroup], ], []), $node); } public function testReturnType(): void { $node = $this->createMethodBuilder('test') ->setReturnType('bool') ->getNode(); $this->assertEquals(new Stmt\ClassMethod('test', [ 'returnType' => new Identifier('bool'), ], []), $node); } public function testAddStmtToAbstractMethodError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot add statements to an abstract method'); $this->createMethodBuilder('test') ->makeAbstract() ->addStmt(new Print_(new String_('test'))) ; } public function testMakeMethodWithStmtsAbstractError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot make method with statements abstract'); $this->createMethodBuilder('test') ->addStmt(new Print_(new String_('test'))) ->makeAbstract() ; } public function testInvalidParamError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected parameter node, got "Name"'); $this->createMethodBuilder('test') ->addParam(new Node\Name('foo')) ; } } ================================================ FILE: test/PhpParser/Builder/NamespaceTest.php ================================================ [$docComment]] ); $node = $this->createNamespaceBuilder('Name\Space') ->addStmt($stmt1) ->addStmts([$stmt2, $stmt3]) ->setDocComment($docComment) ->getNode() ; $this->assertEquals($expected, $node); $node = $this->createNamespaceBuilder(new Node\Name(['Name', 'Space'])) ->setDocComment($docComment) ->addStmts([$stmt1, $stmt2]) ->addStmt($stmt3) ->getNode() ; $this->assertEquals($expected, $node); $node = $this->createNamespaceBuilder(null)->getNode(); $this->assertNull($node->name); $this->assertEmpty($node->stmts); } } ================================================ FILE: test/PhpParser/Builder/ParamTest.php ================================================ createParamBuilder('test') ->setDefault($value) ->getNode() ; $this->assertEquals($expectedValueNode, $node->default); } public static function provideTestDefaultValues() { return [ [ null, new Expr\ConstFetch(new Node\Name('null')) ], [ true, new Expr\ConstFetch(new Node\Name('true')) ], [ false, new Expr\ConstFetch(new Node\Name('false')) ], [ 31415, new Scalar\Int_(31415) ], [ 3.1415, new Scalar\Float_(3.1415) ], [ 'Hallo World', new Scalar\String_('Hallo World') ], [ [1, 2, 3], new Expr\Array_([ new Node\ArrayItem(new Scalar\Int_(1)), new Node\ArrayItem(new Scalar\Int_(2)), new Node\ArrayItem(new Scalar\Int_(3)), ]) ], [ ['foo' => 'bar', 'bar' => 'foo'], new Expr\Array_([ new Node\ArrayItem( new Scalar\String_('bar'), new Scalar\String_('foo') ), new Node\ArrayItem( new Scalar\String_('foo'), new Scalar\String_('bar') ), ]) ], [ new Scalar\MagicConst\Dir(), new Scalar\MagicConst\Dir() ] ]; } /** * @dataProvider provideTestTypes * @dataProvider provideTestNullableTypes * @dataProvider provideTestUnionTypes */ public function testTypes($typeHint, $expectedType): void { $node = $this->createParamBuilder('test') ->setType($typeHint) ->getNode() ; $type = $node->type; /* Manually implement comparison to avoid __toString stupidity */ if ($expectedType instanceof Node\NullableType) { $this->assertInstanceOf(get_class($expectedType), $type); $expectedType = $expectedType->type; $type = $type->type; } $this->assertInstanceOf(get_class($expectedType), $type); $this->assertEquals($expectedType, $type); } public static function provideTestTypes() { return [ ['array', new Node\Identifier('array')], ['callable', new Node\Identifier('callable')], ['bool', new Node\Identifier('bool')], ['int', new Node\Identifier('int')], ['float', new Node\Identifier('float')], ['string', new Node\Identifier('string')], ['iterable', new Node\Identifier('iterable')], ['object', new Node\Identifier('object')], ['Array', new Node\Identifier('array')], ['CALLABLE', new Node\Identifier('callable')], ['mixed', new Node\Identifier('mixed')], ['Some\Class', new Node\Name('Some\Class')], ['\Foo', new Node\Name\FullyQualified('Foo')], ['self', new Node\Name('self')], [new Node\Name('Some\Class'), new Node\Name('Some\Class')], ]; } public static function provideTestNullableTypes() { return [ ['?array', new Node\NullableType(new Node\Identifier('array'))], ['?Some\Class', new Node\NullableType(new Node\Name('Some\Class'))], [ new Node\NullableType(new Node\Identifier('int')), new Node\NullableType(new Node\Identifier('int')) ], [ new Node\NullableType(new Node\Name('Some\Class')), new Node\NullableType(new Node\Name('Some\Class')) ], ]; } public static function provideTestUnionTypes() { return [ [ new Node\UnionType([ new Node\Name('Some\Class'), new Node\Identifier('array'), ]), new Node\UnionType([ new Node\Name('Some\Class'), new Node\Identifier('array'), ]), ], [ new Node\UnionType([ new Node\Identifier('self'), new Node\Identifier('array'), new Node\Name\FullyQualified('Foo') ]), new Node\UnionType([ new Node\Identifier('self'), new Node\Identifier('array'), new Node\Name\FullyQualified('Foo') ]), ], ]; } public function testVoidTypeError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Parameter type cannot be void'); $this->createParamBuilder('test')->setType('void'); } public function testInvalidTypeError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Type must be a string, or an instance of Name, Identifier or ComplexType'); $this->createParamBuilder('test')->setType(new \stdClass()); } public function testByRef(): void { $node = $this->createParamBuilder('test') ->makeByRef() ->getNode() ; $this->assertEquals( new Node\Param(new Expr\Variable('test'), null, null, true), $node ); } public function testVariadic(): void { $node = $this->createParamBuilder('test') ->makeVariadic() ->getNode() ; $this->assertEquals( new Node\Param(new Expr\Variable('test'), null, null, false, true), $node ); } public function testMakePublic(): void { $node = $this->createParamBuilder('test') ->makePublic() ->getNode() ; $this->assertEquals( new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::PUBLIC), $node ); } public function testMakeProtected(): void { $node = $this->createParamBuilder('test') ->makeProtected() ->getNode() ; $this->assertEquals( new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::PROTECTED), $node ); $node = $this->createParamBuilder('test') ->makeProtectedSet() ->getNode() ; $this->assertEquals( new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::PROTECTED_SET), $node ); } public function testMakePrivate(): void { $node = $this->createParamBuilder('test') ->makePrivate() ->getNode() ; $this->assertEquals( new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::PRIVATE), $node ); $node = $this->createParamBuilder('test') ->makePrivateSet() ->getNode() ; $this->assertEquals( new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::PRIVATE_SET), $node ); } public function testMakeReadonly(): void { $node = $this->createParamBuilder('test') ->makeReadonly() ->getNode() ; $this->assertEquals( new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::READONLY), $node ); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $node = $this->createParamBuilder('attributeGroup') ->addAttribute($attributeGroup) ->getNode(); $this->assertEquals( new Node\Param(new Expr\Variable('attributeGroup'), null, null, false, false, [], 0, [$attributeGroup]), $node ); } } ================================================ FILE: test/PhpParser/Builder/PropertyTest.php ================================================ createPropertyBuilder('test') ->makePrivate() ->makeStatic() ->getNode() ; $this->assertEquals( new Stmt\Property( Modifiers::PRIVATE | Modifiers::STATIC, [new PropertyItem('test')] ), $node ); $node = $this->createPropertyBuilder('test') ->makeProtected() ->getNode() ; $this->assertEquals( new Stmt\Property( Modifiers::PROTECTED, [new PropertyItem('test')] ), $node ); $node = $this->createPropertyBuilder('test') ->makePublic() ->getNode() ; $this->assertEquals( new Stmt\Property( Modifiers::PUBLIC, [new PropertyItem('test')] ), $node ); $node = $this->createPropertyBuilder('test') ->makeReadonly() ->getNode() ; $this->assertEquals( new Stmt\Property( Modifiers::READONLY, [new PropertyItem('test')] ), $node ); $node = $this->createPropertyBuilder('test') ->makeFinal() ->getNode(); $this->assertEquals( new Stmt\Property(Modifiers::FINAL, [new PropertyItem('test')]), $node); $node = $this->createPropertyBuilder('test') ->makePrivateSet() ->getNode(); $this->assertEquals( new Stmt\Property(Modifiers::PRIVATE_SET, [new PropertyItem('test')]), $node); $node = $this->createPropertyBuilder('test') ->makeProtectedSet() ->getNode(); $this->assertEquals( new Stmt\Property(Modifiers::PROTECTED_SET, [new PropertyItem('test')]), $node); } public function testAbstractWithoutHook() { $this->expectException(Error::class); $this->expectExceptionMessage('Only hooked properties may be declared abstract'); $this->createPropertyBuilder('test')->makeAbstract()->getNode(); } public function testDocComment(): void { $node = $this->createPropertyBuilder('test') ->setDocComment('/** Test */') ->getNode(); $this->assertEquals(new Stmt\Property( Modifiers::PUBLIC, [ new \PhpParser\Node\PropertyItem('test') ], [ 'comments' => [new Comment\Doc('/** Test */')] ] ), $node); } /** * @dataProvider provideTestDefaultValues */ public function testDefaultValues($value, $expectedValueNode): void { $node = $this->createPropertyBuilder('test') ->setDefault($value) ->getNode() ; $this->assertEquals($expectedValueNode, $node->props[0]->default); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $node = $this->createPropertyBuilder('test') ->addAttribute($attributeGroup) ->getNode() ; $this->assertEquals( new Stmt\Property( Modifiers::PUBLIC, [ new \PhpParser\Node\PropertyItem('test') ], [], null, [$attributeGroup] ), $node ); } public function testAddHook(): void { $get = new PropertyHook('get', null); $set = new PropertyHook('set', null); $node = $this->createPropertyBuilder('test') ->addHook($get) ->addHook($set) ->makeAbstract() ->getNode(); $this->assertEquals( new Stmt\Property( Modifiers::ABSTRACT, [new PropertyItem('test')], [], null, [], [$get, $set]), $node); } public static function provideTestDefaultValues() { return [ [ null, new Expr\ConstFetch(new Name('null')) ], [ true, new Expr\ConstFetch(new Name('true')) ], [ false, new Expr\ConstFetch(new Name('false')) ], [ 31415, new Scalar\Int_(31415) ], [ 3.1415, new Scalar\Float_(3.1415) ], [ 'Hallo World', new Scalar\String_('Hallo World') ], [ [1, 2, 3], new Expr\Array_([ new \PhpParser\Node\ArrayItem(new Scalar\Int_(1)), new \PhpParser\Node\ArrayItem(new Scalar\Int_(2)), new \PhpParser\Node\ArrayItem(new Scalar\Int_(3)), ]) ], [ ['foo' => 'bar', 'bar' => 'foo'], new Expr\Array_([ new \PhpParser\Node\ArrayItem( new Scalar\String_('bar'), new Scalar\String_('foo') ), new \PhpParser\Node\ArrayItem( new Scalar\String_('foo'), new Scalar\String_('bar') ), ]) ], [ new Scalar\MagicConst\Dir(), new Scalar\MagicConst\Dir() ] ]; } } ================================================ FILE: test/PhpParser/Builder/TraitTest.php ================================================ createTraitBuilder('TestTrait') ->setDocComment('/** Nice trait */') ->addStmt($method1) ->addStmts([$method2, $method3]) ->addStmt($prop) ->addStmt($use) ->addStmt($const) ->getNode(); $this->assertEquals(new Stmt\Trait_('TestTrait', [ 'stmts' => [$use, $const, $prop, $method1, $method2, $method3] ], [ 'comments' => [ new Comment\Doc('/** Nice trait */') ] ]), $trait); } public function testInvalidStmtError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Unexpected node of type "Stmt_Echo"'); $this->createTraitBuilder('Test') ->addStmt(new Stmt\Echo_([])) ; } public function testGetMethods(): void { $methods = [ new ClassMethod('foo'), new ClassMethod('bar'), new ClassMethod('fooBar'), ]; $trait = new Stmt\Trait_('Foo', [ 'stmts' => [ new TraitUse([]), $methods[0], new ClassConst([]), $methods[1], new Property(0, []), $methods[2], ] ]); $this->assertSame($methods, $trait->getMethods()); } public function testGetProperties(): void { $properties = [ new Property(Modifiers::PUBLIC, [new PropertyItem('foo')]), new Property(Modifiers::PUBLIC, [new PropertyItem('bar')]), ]; $trait = new Stmt\Trait_('Foo', [ 'stmts' => [ new TraitUse([]), $properties[0], new ClassConst([]), $properties[1], new ClassMethod('fooBar'), ] ]); $this->assertSame($properties, $trait->getProperties()); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $node = $this->createTraitBuilder('AttributeGroup') ->addAttribute($attributeGroup) ->getNode() ; $this->assertEquals( new Stmt\Trait_( 'AttributeGroup', [ 'attrGroups' => [$attributeGroup], ] ), $node ); } } ================================================ FILE: test/PhpParser/Builder/TraitUseAdaptationTest.php ================================================ createTraitUseAdaptationBuilder(null, 'foo'); $this->assertEquals( new Stmt\TraitUseAdaptation\Alias(null, 'foo', null, 'bar'), (clone $builder)->as('bar')->getNode() ); $this->assertEquals( new Stmt\TraitUseAdaptation\Alias(null, 'foo', Modifiers::PUBLIC, null), (clone $builder)->makePublic()->getNode() ); $this->assertEquals( new Stmt\TraitUseAdaptation\Alias(null, 'foo', Modifiers::PROTECTED, null), (clone $builder)->makeProtected()->getNode() ); $this->assertEquals( new Stmt\TraitUseAdaptation\Alias(null, 'foo', Modifiers::PRIVATE, null), (clone $builder)->makePrivate()->getNode() ); } public function testInsteadof(): void { $node = $this->createTraitUseAdaptationBuilder('SomeTrait', 'foo') ->insteadof('AnotherTrait') ->getNode() ; $this->assertEquals( new Stmt\TraitUseAdaptation\Precedence( new Name('SomeTrait'), 'foo', [new Name('AnotherTrait')] ), $node ); } public function testAsOnNotAlias(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot set alias for not alias adaptation buider'); $this->createTraitUseAdaptationBuilder('Test', 'foo') ->insteadof('AnotherTrait') ->as('bar') ; } public function testInsteadofOnNotPrecedence(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot add overwritten traits for not precedence adaptation buider'); $this->createTraitUseAdaptationBuilder('Test', 'foo') ->as('bar') ->insteadof('AnotherTrait') ; } public function testInsteadofWithoutTrait(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Precedence adaptation must have trait'); $this->createTraitUseAdaptationBuilder(null, 'foo') ->insteadof('AnotherTrait') ; } public function testMakeOnNotAlias(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot set access modifier for not alias adaptation buider'); $this->createTraitUseAdaptationBuilder('Test', 'foo') ->insteadof('AnotherTrait') ->makePublic() ; } public function testMultipleMake(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Multiple access type modifiers are not allowed'); $this->createTraitUseAdaptationBuilder(null, 'foo') ->makePrivate() ->makePublic() ; } public function testUndefinedType(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Type of adaptation is not defined'); $this->createTraitUseAdaptationBuilder(null, 'foo') ->getNode() ; } } ================================================ FILE: test/PhpParser/Builder/TraitUseTest.php ================================================ createTraitUseBuilder('SomeTrait') ->and('AnotherTrait') ->getNode() ; $this->assertEquals( new Stmt\TraitUse([ new Name('SomeTrait'), new Name('AnotherTrait') ]), $node ); } public function testWith(): void { $node = $this->createTraitUseBuilder('SomeTrait') ->with(new Stmt\TraitUseAdaptation\Alias(null, 'foo', null, 'bar')) ->with((new TraitUseAdaptation(null, 'test'))->as('baz')) ->getNode() ; $this->assertEquals( new Stmt\TraitUse([new Name('SomeTrait')], [ new Stmt\TraitUseAdaptation\Alias(null, 'foo', null, 'bar'), new Stmt\TraitUseAdaptation\Alias(null, 'test', null, 'baz') ]), $node ); } public function testInvalidAdaptationNode(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Adaptation must have type TraitUseAdaptation'); $this->createTraitUseBuilder('Test') ->with(new Stmt\Echo_([])) ; } } ================================================ FILE: test/PhpParser/Builder/UseTest.php ================================================ createUseBuilder('Foo\Bar')->getNode(); $this->assertEquals(new Stmt\Use_([ new \PhpParser\Node\UseItem(new Name('Foo\Bar'), null) ]), $node); $node = $this->createUseBuilder(new Name('Foo\Bar'))->as('XYZ')->getNode(); $this->assertEquals(new Stmt\Use_([ new \PhpParser\Node\UseItem(new Name('Foo\Bar'), 'XYZ') ]), $node); $node = $this->createUseBuilder('foo\bar', Stmt\Use_::TYPE_FUNCTION)->as('foo')->getNode(); $this->assertEquals(new Stmt\Use_([ new \PhpParser\Node\UseItem(new Name('foo\bar'), 'foo') ], Stmt\Use_::TYPE_FUNCTION), $node); $node = $this->createUseBuilder('foo\BAR', Stmt\Use_::TYPE_CONSTANT)->as('FOO')->getNode(); $this->assertEquals(new Stmt\Use_([ new \PhpParser\Node\UseItem(new Name('foo\BAR'), 'FOO') ], Stmt\Use_::TYPE_CONSTANT), $node); } } ================================================ FILE: test/PhpParser/BuilderFactoryTest.php ================================================ assertInstanceOf($className, $factory->$methodName('test')); } public static function provideTestFactory() { return [ ['namespace', Builder\Namespace_::class], ['class', Builder\Class_::class], ['interface', Builder\Interface_::class], ['trait', Builder\Trait_::class], ['enum', Builder\Enum_::class], ['method', Builder\Method::class], ['function', Builder\Function_::class], ['property', Builder\Property::class], ['param', Builder\Param::class], ['use', Builder\Use_::class], ['useFunction', Builder\Use_::class], ['useConst', Builder\Use_::class], ['enumCase', Builder\EnumCase::class], ]; } public function testFactoryClassConst(): void { $factory = new BuilderFactory(); $this->assertInstanceOf(Builder\ClassConst::class, $factory->classConst('TEST', 1)); } public function testAttribute(): void { $factory = new BuilderFactory(); $this->assertEquals( new Attribute(new Name('AttributeName'), [new Arg( new String_('bar'), false, false, [], new Identifier('foo') )]), $factory->attribute('AttributeName', ['foo' => 'bar']) ); } public function testVal(): void { // This method is a wrapper around BuilderHelpers::normalizeValue(), // which is already tested elsewhere $factory = new BuilderFactory(); $this->assertEquals( new String_("foo"), $factory->val("foo") ); } public function testConcat(): void { $factory = new BuilderFactory(); $varA = new Expr\Variable('a'); $varB = new Expr\Variable('b'); $varC = new Expr\Variable('c'); $this->assertEquals( new Concat($varA, $varB), $factory->concat($varA, $varB) ); $this->assertEquals( new Concat(new Concat($varA, $varB), $varC), $factory->concat($varA, $varB, $varC) ); $this->assertEquals( new Concat(new Concat(new String_("a"), $varB), new String_("c")), $factory->concat("a", $varB, "c") ); } public function testConcatOneError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected at least two expressions'); (new BuilderFactory())->concat("a"); } public function testConcatInvalidExpr(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected string or Expr'); (new BuilderFactory())->concat("a", 42); } public function testArgs(): void { $factory = new BuilderFactory(); $unpack = new Arg(new Expr\Variable('c'), false, true); $this->assertEquals( [ new Arg(new Expr\Variable('a')), new Arg(new String_('b')), $unpack ], $factory->args([new Expr\Variable('a'), 'b', $unpack]) ); } public function testNamedArgs(): void { $factory = new BuilderFactory(); $this->assertEquals( [ new Arg(new String_('foo')), new Arg(new String_('baz'), false, false, [], new Identifier('bar')), ], $factory->args(['foo', 'bar' => 'baz']) ); } public function testCalls(): void { $factory = new BuilderFactory(); // Simple function call $this->assertEquals( new Expr\FuncCall( new Name('var_dump'), [new Arg(new String_('str'))] ), $factory->funcCall('var_dump', ['str']) ); // Dynamic function call $this->assertEquals( new Expr\FuncCall(new Expr\Variable('fn')), $factory->funcCall(new Expr\Variable('fn')) ); // Simple method call $this->assertEquals( new Expr\MethodCall( new Expr\Variable('obj'), new Identifier('method'), [new Arg(new Int_(42))] ), $factory->methodCall(new Expr\Variable('obj'), 'method', [42]) ); // Explicitly pass Identifier node $this->assertEquals( new Expr\MethodCall( new Expr\Variable('obj'), new Identifier('method') ), $factory->methodCall(new Expr\Variable('obj'), new Identifier('method')) ); // Dynamic method call $this->assertEquals( new Expr\MethodCall( new Expr\Variable('obj'), new Expr\Variable('method') ), $factory->methodCall(new Expr\Variable('obj'), new Expr\Variable('method')) ); // Simple static method call $this->assertEquals( new Expr\StaticCall( new Name\FullyQualified('Foo'), new Identifier('bar'), [new Arg(new Expr\Variable('baz'))] ), $factory->staticCall('\Foo', 'bar', [new Expr\Variable('baz')]) ); // Dynamic static method call $this->assertEquals( new Expr\StaticCall( new Expr\Variable('foo'), new Expr\Variable('bar') ), $factory->staticCall(new Expr\Variable('foo'), new Expr\Variable('bar')) ); // Simple new call $this->assertEquals( new Expr\New_(new Name\FullyQualified('stdClass')), $factory->new('\stdClass') ); // Dynamic new call $this->assertEquals( new Expr\New_( new Expr\Variable('foo'), [new Arg(new String_('bar'))] ), $factory->new(new Expr\Variable('foo'), ['bar']) ); } public function testConstFetches(): void { $factory = new BuilderFactory(); $this->assertEquals( new Expr\ConstFetch(new Name('FOO')), $factory->constFetch('FOO') ); $this->assertEquals( new Expr\ClassConstFetch(new Name('Foo'), new Identifier('BAR')), $factory->classConstFetch('Foo', 'BAR') ); $this->assertEquals( new Expr\ClassConstFetch(new Expr\Variable('foo'), new Identifier('BAR')), $factory->classConstFetch(new Expr\Variable('foo'), 'BAR') ); $this->assertEquals( new Expr\ClassConstFetch(new Name('Foo'), new Expr\Variable('foo')), $factory->classConstFetch('Foo', $factory->var('foo')) ); } public function testVar(): void { $factory = new BuilderFactory(); $this->assertEquals( new Expr\Variable("foo"), $factory->var("foo") ); $this->assertEquals( new Expr\Variable(new Expr\Variable("foo")), $factory->var($factory->var("foo")) ); } public function testPropertyFetch(): void { $f = new BuilderFactory(); $this->assertEquals( new Expr\PropertyFetch(new Expr\Variable('foo'), 'bar'), $f->propertyFetch($f->var('foo'), 'bar') ); $this->assertEquals( new Expr\PropertyFetch(new Expr\Variable('foo'), 'bar'), $f->propertyFetch($f->var('foo'), new Identifier('bar')) ); $this->assertEquals( new Expr\PropertyFetch(new Expr\Variable('foo'), new Expr\Variable('bar')), $f->propertyFetch($f->var('foo'), $f->var('bar')) ); } public function testInvalidIdentifier(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected string or instance of Node\Identifier'); (new BuilderFactory())->classConstFetch('Foo', new Name('foo')); } public function testInvalidIdentifierOrExpr(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected string or instance of Node\Identifier or Node\Expr'); (new BuilderFactory())->staticCall('Foo', new Name('bar')); } public function testInvalidNameOrExpr(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name must be a string or an instance of Node\Name or Node\Expr'); (new BuilderFactory())->funcCall(new Node\Stmt\Return_()); } public function testInvalidVar(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Variable name must be string or Expr'); (new BuilderFactory())->var(new Node\Stmt\Return_()); } public function testIntegration(): void { $factory = new BuilderFactory(); $node = $factory->namespace('Name\Space') ->addStmt($factory->use('Foo\Bar\SomeOtherClass')) ->addStmt($factory->use('Foo\Bar')->as('A')) ->addStmt($factory->useFunction('strlen')) ->addStmt($factory->useConst('PHP_VERSION')) ->addStmt($factory ->class('SomeClass') ->extend('SomeOtherClass') ->implement('A\Few', '\Interfaces') ->addAttribute($factory->attribute('ClassAttribute', ['repository' => 'fqcn'])) ->makeAbstract() ->addStmt($factory->useTrait('FirstTrait')) ->addStmt($factory->useTrait('SecondTrait', 'ThirdTrait') ->and('AnotherTrait') ->with($factory->traitUseAdaptation('foo')->as('bar')) ->with($factory->traitUseAdaptation('AnotherTrait', 'baz')->as('test')) ->with($factory->traitUseAdaptation('AnotherTrait', 'func')->insteadof('SecondTrait'))) ->addStmt($factory->method('firstMethod') ->addAttribute($factory->attribute('Route', ['/index', 'name' => 'homepage'])) ) ->addStmt($factory->method('someMethod') ->makePublic() ->makeAbstract() ->addParam($factory->param('someParam')->setType('SomeClass')) ->setDocComment('/** * This method does something. * * @param SomeClass And takes a parameter */')) ->addStmt($factory->method('anotherMethod') ->makeProtected() ->addParam($factory->param('someParam') ->setDefault('test') ->addAttribute($factory->attribute('TaggedIterator', ['app.handlers'])) ) ->addStmt(new Expr\Print_(new Expr\Variable('someParam')))) ->addStmt($factory->property('someProperty')->makeProtected()) ->addStmt($factory->property('anotherProperty') ->makePrivate() ->setDefault([1, 2, 3])) ->addStmt($factory->property('integerProperty') ->setType('int') ->addAttribute($factory->attribute('Column', ['options' => ['unsigned' => true]])) ->setDefault(1)) ->addStmt($factory->classConst('CONST_WITH_ATTRIBUTE', 1) ->makePublic() ->addAttribute($factory->attribute('ConstAttribute')) ) ->addStmt($factory->classConst("FIRST_CLASS_CONST", 1) ->addConst("SECOND_CLASS_CONST", 2) ->makePrivate())) ->getNode() ; $expected = <<<'EOC' true])] public int $integerProperty = 1; #[Route('/index', name: 'homepage')] function firstMethod() { } /** * This method does something. * * @param SomeClass And takes a parameter */ abstract public function someMethod(SomeClass $someParam); protected function anotherMethod( #[TaggedIterator('app.handlers')] $someParam = 'test' ) { print $someParam; } } EOC; $stmts = [$node]; $prettyPrinter = new PrettyPrinter\Standard(); $generated = $prettyPrinter->prettyPrintFile($stmts); $this->assertEquals( str_replace("\r\n", "\n", $expected), str_replace("\r\n", "\n", $generated) ); } } ================================================ FILE: test/PhpParser/BuilderHelpersTest.php ================================================ assertEquals($builder->getNode(), BuilderHelpers::normalizeNode($builder)); $attribute = new Node\Attribute(new Node\Name('Test')); $this->assertSame($attribute, BuilderHelpers::normalizeNode($attribute)); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected node or builder object'); BuilderHelpers::normalizeNode('test'); } public function testNormalizeStmt(): void { $stmt = new Node\Stmt\Class_('Class'); $this->assertSame($stmt, BuilderHelpers::normalizeStmt($stmt)); $expr = new Expr\Variable('fn'); $normalizedExpr = BuilderHelpers::normalizeStmt($expr); $this->assertEquals(new Stmt\Expression($expr), $normalizedExpr); $this->assertSame($expr, $normalizedExpr->expr); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected statement or expression node'); BuilderHelpers::normalizeStmt(new Node\Attribute(new Node\Name('Test'))); } public function testNormalizeStmtInvalidType(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected node or builder object'); BuilderHelpers::normalizeStmt('test'); } public function testNormalizeIdentifier(): void { $identifier = new Node\Identifier('fn'); $this->assertSame($identifier, BuilderHelpers::normalizeIdentifier($identifier)); $this->assertEquals($identifier, BuilderHelpers::normalizeIdentifier('fn')); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected string or instance of Node\Identifier'); BuilderHelpers::normalizeIdentifier(1); } public function testNormalizeIdentifierOrExpr(): void { $identifier = new Node\Identifier('fn'); $this->assertSame($identifier, BuilderHelpers::normalizeIdentifierOrExpr($identifier)); $expr = new Expr\Variable('fn'); $this->assertSame($expr, BuilderHelpers::normalizeIdentifierOrExpr($expr)); $this->assertEquals($identifier, BuilderHelpers::normalizeIdentifierOrExpr('fn')); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected string or instance of Node\Identifier'); BuilderHelpers::normalizeIdentifierOrExpr(1); } public function testNormalizeName(): void { $name = new Node\Name('test'); $this->assertSame($name, BuilderHelpers::normalizeName($name)); $this->assertEquals( new Node\Name\FullyQualified(['Namespace', 'Test']), BuilderHelpers::normalizeName('\\Namespace\\Test') ); $this->assertEquals( new Node\Name\Relative(['Test']), BuilderHelpers::normalizeName('namespace\\Test') ); $this->assertEquals($name, BuilderHelpers::normalizeName('test')); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name cannot be empty'); BuilderHelpers::normalizeName(''); } public function testNormalizeNameInvalidType(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name must be a string or an instance of Node\Name'); BuilderHelpers::normalizeName(1); } public function testNormalizeNameOrExpr(): void { $expr = new Expr\Variable('fn'); $this->assertSame($expr, BuilderHelpers::normalizeNameOrExpr($expr)); $name = new Node\Name('test'); $this->assertSame($name, BuilderHelpers::normalizeNameOrExpr($name)); $this->assertEquals( new Node\Name\FullyQualified(['Namespace', 'Test']), BuilderHelpers::normalizeNameOrExpr('\\Namespace\\Test') ); $this->assertEquals( new Node\Name\Relative(['Test']), BuilderHelpers::normalizeNameOrExpr('namespace\\Test') ); $this->assertEquals($name, BuilderHelpers::normalizeNameOrExpr('test')); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name cannot be empty'); BuilderHelpers::normalizeNameOrExpr(''); } public function testNormalizeNameOrExpInvalidType(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name must be a string or an instance of Node\Name or Node\Expr'); BuilderHelpers::normalizeNameOrExpr(1); } public function testNormalizeType(): void { $this->assertEquals(new Node\Identifier('array'), BuilderHelpers::normalizeType('array')); $this->assertEquals(new Node\Identifier('callable'), BuilderHelpers::normalizeType('callable')); $this->assertEquals(new Node\Identifier('string'), BuilderHelpers::normalizeType('string')); $this->assertEquals(new Node\Identifier('int'), BuilderHelpers::normalizeType('int')); $this->assertEquals(new Node\Identifier('float'), BuilderHelpers::normalizeType('float')); $this->assertEquals(new Node\Identifier('bool'), BuilderHelpers::normalizeType('bool')); $this->assertEquals(new Node\Identifier('iterable'), BuilderHelpers::normalizeType('iterable')); $this->assertEquals(new Node\Identifier('void'), BuilderHelpers::normalizeType('void')); $this->assertEquals(new Node\Identifier('object'), BuilderHelpers::normalizeType('object')); $this->assertEquals(new Node\Identifier('null'), BuilderHelpers::normalizeType('null')); $this->assertEquals(new Node\Identifier('false'), BuilderHelpers::normalizeType('false')); $this->assertEquals(new Node\Identifier('mixed'), BuilderHelpers::normalizeType('mixed')); $this->assertEquals(new Node\Identifier('never'), BuilderHelpers::normalizeType('never')); $this->assertEquals(new Node\Identifier('true'), BuilderHelpers::normalizeType('true')); $intIdentifier = new Node\Identifier('int'); $this->assertSame($intIdentifier, BuilderHelpers::normalizeType($intIdentifier)); $intName = new Node\Name('int'); $this->assertSame($intName, BuilderHelpers::normalizeType($intName)); $intNullable = new Node\NullableType(new Identifier('int')); $this->assertSame($intNullable, BuilderHelpers::normalizeType($intNullable)); $unionType = new Node\UnionType([new Node\Identifier('int'), new Node\Identifier('string')]); $this->assertSame($unionType, BuilderHelpers::normalizeType($unionType)); $intersectionType = new Node\IntersectionType([new Node\Name('A'), new Node\Name('B')]); $this->assertSame($intersectionType, BuilderHelpers::normalizeType($intersectionType)); $expectedNullable = new Node\NullableType($intIdentifier); $nullable = BuilderHelpers::normalizeType('?int'); $this->assertEquals($expectedNullable, $nullable); $this->assertEquals($intIdentifier, $nullable->type); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Type must be a string, or an instance of Name, Identifier or ComplexType'); BuilderHelpers::normalizeType(1); } public function testNormalizeTypeNullableVoid(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('void type cannot be nullable'); BuilderHelpers::normalizeType('?void'); } public function testNormalizeTypeNullableMixed(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('mixed type cannot be nullable'); BuilderHelpers::normalizeType('?mixed'); } public function testNormalizeTypeNullableNever(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('never type cannot be nullable'); BuilderHelpers::normalizeType('?never'); } public function testNormalizeValue(): void { $expression = new Scalar\Int_(1); $this->assertSame($expression, BuilderHelpers::normalizeValue($expression)); $this->assertEquals(new Expr\ConstFetch(new Node\Name('null')), BuilderHelpers::normalizeValue(null)); $this->assertEquals(new Expr\ConstFetch(new Node\Name('true')), BuilderHelpers::normalizeValue(true)); $this->assertEquals(new Expr\ConstFetch(new Node\Name('false')), BuilderHelpers::normalizeValue(false)); $this->assertEquals(new Scalar\Int_(2), BuilderHelpers::normalizeValue(2)); $this->assertEquals(new Scalar\Float_(2.5), BuilderHelpers::normalizeValue(2.5)); $this->assertEquals(new Scalar\String_('text'), BuilderHelpers::normalizeValue('text')); $this->assertEquals( new Expr\Array_([ new Node\ArrayItem(new Scalar\Int_(0)), new Node\ArrayItem(new Scalar\Int_(1), new Scalar\String_('test')), ]), BuilderHelpers::normalizeValue([ 0, 'test' => 1, ]) ); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Invalid value'); BuilderHelpers::normalizeValue(new \stdClass()); } public function testNormalizeDocComment(): void { $docComment = new Comment\Doc('Some doc comment'); $this->assertSame($docComment, BuilderHelpers::normalizeDocComment($docComment)); $this->assertEquals($docComment, BuilderHelpers::normalizeDocComment('Some doc comment')); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Doc comment must be a string or an instance of PhpParser\Comment\Doc'); BuilderHelpers::normalizeDocComment(1); } public function testNormalizeAttribute(): void { $attribute = new Node\Attribute(new Node\Name('Test')); $attributeGroup = new Node\AttributeGroup([$attribute]); $this->assertEquals($attributeGroup, BuilderHelpers::normalizeAttribute($attribute)); $this->assertSame($attributeGroup, BuilderHelpers::normalizeAttribute($attributeGroup)); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Attribute must be an instance of PhpParser\Node\Attribute or PhpParser\Node\AttributeGroup'); BuilderHelpers::normalizeAttribute('test'); } public function testNormalizeValueEnum() { if (\PHP_VERSION_ID <= 80100) { $this->markTestSkipped('Enums are supported since PHP 8.1'); } include __DIR__ . '/../fixtures/Suit.php'; $this->assertEquals(new Expr\ClassConstFetch(new FullyQualified(\Suit::class), new Identifier('Hearts')), BuilderHelpers::normalizeValue(\Suit::Hearts)); } } ================================================ FILE: test/PhpParser/CodeParsingTest.php ================================================ parseModeLine($modeLine); $parser = $this->createParser($modes['version'] ?? null); list($stmts, $output) = $this->getParseOutput($parser, $code, $modes); $this->assertSame($expected, $output, $name); $this->checkAttributes($stmts); } public function createParser(?string $version): Parser { $factory = new ParserFactory(); $version = $version === null ? PhpVersion::getNewestSupported() : PhpVersion::fromString($version); return $factory->createForVersion($version); } // Must be public for updateTests.php public function getParseOutput(Parser $parser, $code, array $modes) { $dumpPositions = isset($modes['positions']); $dumpOtherAttributes = isset($modes['attributes']); $errors = new ErrorHandler\Collecting(); $stmts = $parser->parse($code, $errors); $output = ''; foreach ($errors->getErrors() as $error) { $output .= $this->formatErrorMessage($error, $code) . "\n"; } if (null !== $stmts) { $dumper = new NodeDumper([ 'dumpComments' => true, 'dumpPositions' => $dumpPositions, 'dumpOtherAttributes' => $dumpOtherAttributes, ]); $output .= $dumper->dump($stmts, $code); } return [$stmts, canonicalize($output)]; } public static function provideTestParse() { return self::getTests(__DIR__ . '/../code/parser', 'test'); } private function formatErrorMessage(Error $e, $code) { if ($e->hasColumnInfo()) { return $e->getMessageWithColumnInfo($code); } return $e->getMessage(); } private function checkAttributes($stmts): void { if ($stmts === null) { return; } $traverser = new NodeTraverser(new class () extends NodeVisitorAbstract { public function enterNode(Node $node): void { $startLine = $node->getStartLine(); $endLine = $node->getEndLine(); $startFilePos = $node->getStartFilePos(); $endFilePos = $node->getEndFilePos(); $startTokenPos = $node->getStartTokenPos(); $endTokenPos = $node->getEndTokenPos(); if ($startLine < 0 || $endLine < 0 || $startFilePos < 0 || $endFilePos < 0 || $startTokenPos < 0 || $endTokenPos < 0 ) { throw new \Exception('Missing location information on ' . $node->getType()); } if ($endLine < $startLine || $endFilePos < $startFilePos || $endTokenPos < $startTokenPos ) { // Nop and Error can have inverted order, if they are empty. // This can also happen for a Param containing an Error. if (!$node instanceof Stmt\Nop && !$node instanceof Expr\Error && !$node instanceof Node\Param ) { throw new \Exception('End < start on ' . $node->getType()); } } } }); $traverser->traverse($stmts); } } ================================================ FILE: test/PhpParser/CodeTestAbstract.php ================================================ $fileContents) { list($name, $tests) = $parser->parseTest($fileContents, $chunksPerTest); // first part is the name $name .= ' (' . $fileName . ')'; $shortName = ltrim(str_replace($directory, '', $fileName), '/\\'); // multiple sections possible with always two forming a pair foreach ($tests as $i => list($mode, $parts)) { $dataSetName = $shortName . (count($parts) > 1 ? '#' . $i : ''); $allTests[$dataSetName] = array_merge([$name], $parts, [$mode]); } } return $allTests; } public function parseModeLine(?string $modeLine): array { if ($modeLine === null) { return []; } $modes = []; foreach (explode(',', $modeLine) as $mode) { $kv = explode('=', $mode, 2); if (isset($kv[1])) { $modes[$kv[0]] = $kv[1]; } else { $modes[$kv[0]] = true; } } return $modes; } } ================================================ FILE: test/PhpParser/CodeTestParser.php ================================================ extractMode($lastPart); $tests[] = [$mode, array_merge($chunk, [$lastPart])]; } return [$name, $tests]; } public function reconstructTest($name, array $tests) { $result = $name; foreach ($tests as list($mode, $parts)) { $lastPart = array_pop($parts); foreach ($parts as $part) { $result .= "\n-----\n$part"; } $result .= "\n-----\n"; if (null !== $mode) { $result .= "!!$mode\n"; } $result .= $lastPart; } return $result . "\n"; } private function extractMode(string $expected): array { $firstNewLine = strpos($expected, "\n"); if (false === $firstNewLine) { $firstNewLine = strlen($expected); } $firstLine = substr($expected, 0, $firstNewLine); if (0 !== strpos($firstLine, '!!')) { return [$expected, null]; } $expected = substr($expected, $firstNewLine + 1); return [$expected, substr($firstLine, 2)]; } } ================================================ FILE: test/PhpParser/CommentTest.php ================================================ assertSame('/* Some comment */', $comment->getText()); $this->assertSame('/* Some comment */', (string) $comment); $this->assertSame(1, $comment->getStartLine()); $this->assertSame(10, $comment->getStartFilePos()); $this->assertSame(2, $comment->getStartTokenPos()); $this->assertSame(1, $comment->getEndLine()); $this->assertSame(27, $comment->getEndFilePos()); $this->assertSame(2, $comment->getEndTokenPos()); } /** * @dataProvider provideTestReformatting */ public function testReformatting($commentText, $reformattedText): void { $comment = new Comment($commentText); $this->assertSame($reformattedText, $comment->getReformattedText()); } public static function provideTestReformatting() { return [ ['// Some text', '// Some text'], ['/* Some text */', '/* Some text */'], [ "/**\n * Some text.\n * Some more text.\n */", "/**\n * Some text.\n * Some more text.\n */" ], [ "/**\r\n * Some text.\r\n * Some more text.\r\n */", "/**\n * Some text.\n * Some more text.\n */" ], [ "/*\n Some text.\n Some more text.\n */", "/*\n Some text.\n Some more text.\n*/" ], [ "/*\r\n Some text.\r\n Some more text.\r\n */", "/*\n Some text.\n Some more text.\n*/" ], [ "/* Some text.\n More text.\n Even more text. */", "/* Some text.\n More text.\n Even more text. */" ], [ "/* Some text.\r\n More text.\r\n Even more text. */", "/* Some text.\n More text.\n Even more text. */" ], [ "/* Some text.\n More text.\n Indented text. */", "/* Some text.\n More text.\n Indented text. */", ], // invalid comment -> no reformatting [ "hello\n world", "hello\n world", ], ]; } } ================================================ FILE: test/PhpParser/CompatibilityTest.php ================================================ assertTrue($node instanceof Expr\ClosureUse); $node = new Node\ArrayItem($var); $this->assertTrue($node instanceof Expr\ArrayItem); $node = new Node\StaticVar($var); $this->assertTrue($node instanceof Stmt\StaticVar); $node = new Scalar\Float_(1.0); $this->assertTrue($node instanceof Scalar\DNumber); $node = new Scalar\Int_(1); $this->assertTrue($node instanceof Scalar\LNumber); $part = new InterpolatedStringPart('foo'); $this->assertTrue($part instanceof Scalar\EncapsedStringPart); $node = new Scalar\InterpolatedString([$part]); $this->assertTrue($node instanceof Scalar\Encapsed); $node = new Node\DeclareItem('strict_types', new Scalar\Int_(1)); $this->assertTrue($node instanceof Stmt\DeclareDeclare); $node = new Node\PropertyItem('x'); $this->assertTrue($node instanceof Stmt\PropertyProperty); $node = new Node\UseItem(new Name('X')); $this->assertTrue($node instanceof Stmt\UseUse); } /** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testAliases2(): void { $var = new Expr\Variable('x'); $node = new Node\Expr\ClosureUse($var); $this->assertTrue($node instanceof Node\ClosureUse); $node = new Node\Expr\ArrayItem($var); $this->assertTrue($node instanceof Node\ArrayItem); $node = new Node\Stmt\StaticVar($var); $this->assertTrue($node instanceof Node\StaticVar); $node = new Node\Scalar\DNumber(1.0); $this->assertTrue($node instanceof Scalar\Float_); $node = new Node\Scalar\LNumber(1); $this->assertTrue($node instanceof Scalar\Int_); $part = new Node\Scalar\EncapsedStringPart('foo'); $this->assertTrue($part instanceof Node\InterpolatedStringPart); $node = new Scalar\Encapsed([$part]); $this->assertTrue($node instanceof Scalar\InterpolatedString); $node = new Stmt\DeclareDeclare('strict_types', new Scalar\LNumber(1)); $this->assertTrue($node instanceof Node\DeclareItem); $node = new Stmt\PropertyProperty('x'); $this->assertTrue($node instanceof Node\PropertyItem); $node = new Stmt\UseUse(new Name('X')); $this->assertTrue($node instanceof Node\UseItem); } } ================================================ FILE: test/PhpParser/ConstExprEvaluatorTest.php ================================================ createForNewestSupportedVersion(); $expr = $parser->parse('expr; $evaluator = new ConstExprEvaluator(); $this->assertSame($expected, $evaluator->evaluateDirectly($expr)); } public static function provideTestEvaluate() { return [ ['1', 1], ['1.0', 1.0], ['"foo"', "foo"], ['[0, 1]', [0, 1]], ['["foo" => "bar"]', ["foo" => "bar"]], ['[...["bar"]]', ["bar"]], ['[...["foo" => "bar"]]', ["foo" => "bar"]], ['["a", "b" => "b", ...["b" => "bb", "c"]]', ["a", "b" => "bb", "c"]], ['NULL', null], ['False', false], ['true', true], ['+1', 1], ['-1', -1], ['~0', -1], ['!true', false], ['[0][0]', 0], ['"a"[0]', "a"], ['true ? 1 : (1/0)', 1], ['false ? (1/0) : 1', 1], ['42 ?: (1/0)', 42], ['false ?: 42', 42], ['false ?? 42', false], ['null ?? 42', 42], ['[0][0] ?? 42', 0], ['[][0] ?? 42', 42], ['0b11 & 0b10', 0b10], ['0b11 | 0b10', 0b11], ['0b11 ^ 0b10', 0b01], ['1 << 2', 4], ['4 >> 2', 1], ['"a" . "b"', "ab"], ['4 + 2', 6], ['4 - 2', 2], ['4 * 2', 8], ['4 / 2', 2], ['4 % 2', 0], ['4 ** 2', 16], ['1 == 1.0', true], ['1 != 1.0', false], ['1 < 2.0', true], ['1 <= 2.0', true], ['1 > 2.0', false], ['1 >= 2.0', false], ['1 <=> 2.0', -1], ['1 === 1.0', false], ['1 !== 1.0', true], ['true && true', true], ['true and true', true], ['false && (1/0)', false], ['false and (1/0)', false], ['false || false', false], ['false or false', false], ['true || (1/0)', true], ['true or (1/0)', true], ['true xor false', true], ['"foo" |> "strlen"', 3], ]; } public function testEvaluateFails(): void { $this->expectException(ConstExprEvaluationException::class); $this->expectExceptionMessage('Expression of type Expr_Variable cannot be evaluated'); $evaluator = new ConstExprEvaluator(); $evaluator->evaluateDirectly(new Expr\Variable('a')); } public function testEvaluateFallback(): void { $evaluator = new ConstExprEvaluator(function (Expr $expr) { if ($expr instanceof Scalar\MagicConst\Line) { return 42; } throw new ConstExprEvaluationException(); }); $expr = new Expr\BinaryOp\Plus( new Scalar\Int_(8), new Scalar\MagicConst\Line() ); $this->assertSame(50, $evaluator->evaluateDirectly($expr)); } /** * @dataProvider provideTestEvaluateSilently */ public function testEvaluateSilently($expr, $exception, $msg): void { $evaluator = new ConstExprEvaluator(); try { $evaluator->evaluateSilently($expr); } catch (ConstExprEvaluationException $e) { $this->assertSame( 'An error occurred during constant expression evaluation', $e->getMessage() ); $prev = $e->getPrevious(); $this->assertInstanceOf($exception, $prev); $this->assertSame($msg, $prev->getMessage()); } } public static function provideTestEvaluateSilently() { return [ [ new Expr\BinaryOp\Mod(new Scalar\Int_(42), new Scalar\Int_(0)), \Error::class, 'Modulo by zero' ], [ new Expr\BinaryOp\Plus(new Scalar\Int_(42), new Scalar\String_("1foo")), \ErrorException::class, \PHP_VERSION_ID >= 80000 ? 'A non-numeric value encountered' : 'A non well formed numeric value encountered' ], ]; } } ================================================ FILE: test/PhpParser/ErrorHandler/CollectingTest.php ================================================ assertFalse($errorHandler->hasErrors()); $this->assertEmpty($errorHandler->getErrors()); $errorHandler->handleError($e1 = new Error('Test 1')); $errorHandler->handleError($e2 = new Error('Test 2')); $this->assertTrue($errorHandler->hasErrors()); $this->assertSame([$e1, $e2], $errorHandler->getErrors()); $errorHandler->clearErrors(); $this->assertFalse($errorHandler->hasErrors()); $this->assertEmpty($errorHandler->getErrors()); } } ================================================ FILE: test/PhpParser/ErrorHandler/ThrowingTest.php ================================================ expectException(Error::class); $this->expectExceptionMessage('Test'); $errorHandler = new Throwing(); $errorHandler->handleError(new Error('Test')); } } ================================================ FILE: test/PhpParser/ErrorTest.php ================================================ 10, 'endLine' => 11, ]; $error = new Error('Some error', $attributes); $this->assertSame('Some error', $error->getRawMessage()); $this->assertSame($attributes, $error->getAttributes()); $this->assertSame(10, $error->getStartLine()); $this->assertSame(11, $error->getEndLine()); $this->assertSame('Some error on line 10', $error->getMessage()); return $error; } /** * @depends testConstruct */ public function testSetMessageAndLine(Error $error): void { $error->setRawMessage('Some other error'); $this->assertSame('Some other error', $error->getRawMessage()); $error->setStartLine(15); $this->assertSame(15, $error->getStartLine()); $this->assertSame('Some other error on line 15', $error->getMessage()); } public function testUnknownLine(): void { $error = new Error('Some error'); $this->assertSame(-1, $error->getStartLine()); $this->assertSame(-1, $error->getEndLine()); $this->assertSame('Some error on unknown line', $error->getMessage()); } /** @dataProvider provideTestColumnInfo */ public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn): void { $error = new Error('Some error', [ 'startFilePos' => $startPos, 'endFilePos' => $endPos, ]); $this->assertTrue($error->hasColumnInfo()); $this->assertSame($startColumn, $error->getStartColumn($code)); $this->assertSame($endColumn, $error->getEndColumn($code)); } public static function provideTestColumnInfo() { return [ // Error at "bar" [" 3]); $this->assertFalse($error->hasColumnInfo()); try { $error->getStartColumn(''); $this->fail('Expected RuntimeException'); } catch (\RuntimeException $e) { $this->assertSame('Error does not have column information', $e->getMessage()); } try { $error->getEndColumn(''); $this->fail('Expected RuntimeException'); } catch (\RuntimeException $e) { $this->assertSame('Error does not have column information', $e->getMessage()); } } public function testInvalidPosInfo(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Invalid position information'); $error = new Error('Some error', [ 'startFilePos' => 10, 'endFilePos' => 11, ]); $error->getStartColumn('code'); } } ================================================ FILE: test/PhpParser/Internal/DifferTest.php ================================================ type) { case DiffElem::TYPE_KEEP: $diffStr .= $diffElem->old; break; case DiffElem::TYPE_REMOVE: $diffStr .= '-' . $diffElem->old; break; case DiffElem::TYPE_ADD: $diffStr .= '+' . $diffElem->new; break; case DiffElem::TYPE_REPLACE: $diffStr .= '/' . $diffElem->old . $diffElem->new; break; default: assert(false); break; } } return $diffStr; } /** @dataProvider provideTestDiff */ public function testDiff($oldStr, $newStr, $expectedDiffStr): void { $differ = new Differ(function ($a, $b) { return $a === $b; }); $diff = $differ->diff(str_split($oldStr), str_split($newStr)); $this->assertSame($expectedDiffStr, $this->formatDiffString($diff)); } public static function provideTestDiff() { return [ ['abc', 'abc', 'abc'], ['abc', 'abcdef', 'abc+d+e+f'], ['abcdef', 'abc', 'abc-d-e-f'], ['abcdef', 'abcxyzdef', 'abc+x+y+zdef'], ['axyzb', 'ab', 'a-x-y-zb'], ['abcdef', 'abxyef', 'ab-c-d+x+yef'], ['abcdef', 'cdefab', '-a-bcdef+a+b'], ]; } /** @dataProvider provideTestDiffWithReplacements */ public function testDiffWithReplacements($oldStr, $newStr, $expectedDiffStr): void { $differ = new Differ(function ($a, $b) { return $a === $b; }); $diff = $differ->diffWithReplacements(str_split($oldStr), str_split($newStr)); $this->assertSame($expectedDiffStr, $this->formatDiffString($diff)); } public static function provideTestDiffWithReplacements() { return [ ['abcde', 'axyze', 'a/bx/cy/dze'], ['abcde', 'xbcdy', '/axbcd/ey'], ['abcde', 'axye', 'a-b-c-d+x+ye'], ['abcde', 'axyzue', 'a-b-c-d+x+y+z+ue'], ]; } public function testNonContiguousIndices(): void { $differ = new Differ(function ($a, $b) { return $a === $b; }); $diff = $differ->diff([0 => 'a', 2 => 'b'], [0 => 'a', 3 => 'b']); $this->assertEquals([ new DiffElem(DiffElem::TYPE_KEEP, 'a', 'a'), new DiffElem(DiffElem::TYPE_KEEP, 'b', 'b'), ], $diff); } } ================================================ FILE: test/PhpParser/JsonDecoderTest.php ================================================ parse($code); $json = json_encode($stmts); $jsonDecoder = new JsonDecoder(); $decodedStmts = $jsonDecoder->decode($json); $this->assertEquals($stmts, $decodedStmts); } /** @dataProvider provideTestDecodingError */ public function testDecodingError($json, $expectedMessage): void { $jsonDecoder = new JsonDecoder(); $this->expectException(\RuntimeException::class); $this->expectExceptionMessage($expectedMessage); $jsonDecoder->decode($json); } public static function provideTestDecodingError() { return [ ['???', 'JSON decoding error: Syntax error'], ['{"nodeType":123}', 'Node type must be a string'], ['{"nodeType":"Name","attributes":123}', 'Attributes must be an array'], ['{"nodeType":"Comment"}', 'Comment must have text'], ['{"nodeType":"xxx"}', 'Unknown node type "xxx"'], ]; } } ================================================ FILE: test/PhpParser/Lexer/EmulativeTest.php ================================================ getLexer(); $code = 'assertEquals([ new Token(\T_OPEN_TAG, 'tokenize($code)); } /** * @dataProvider provideTestReplaceKeywords */ public function testReplaceKeywordsUppercase(string $keyword, int $expectedToken): void { $lexer = $this->getLexer(); $code = 'assertEquals([ new Token(\T_OPEN_TAG, 'tokenize($code)); } /** * @dataProvider provideTestReplaceKeywords */ public function testNoReplaceKeywordsAfterObjectOperator(string $keyword): void { $lexer = $this->getLexer(); $code = '' . $keyword; $this->assertEquals([ new Token(\T_OPEN_TAG, '', 1, 6), new Token(\T_STRING, $keyword, 1, 8), new Token(0, "\0", 1, \strlen($code)), ], $lexer->tokenize($code)); } /** * @dataProvider provideTestReplaceKeywords */ public function testNoReplaceKeywordsAfterObjectOperatorWithSpaces(string $keyword): void { $lexer = $this->getLexer(); $code = ' ' . $keyword; $this->assertEquals([ new Token(\T_OPEN_TAG, '', 1, 6), new Token(\T_WHITESPACE, ' ', 1, 8), new Token(\T_STRING, $keyword, 1, 12), new Token(0, "\0", 1, \strlen($code)), ], $lexer->tokenize($code)); } /** * @dataProvider provideTestReplaceKeywords */ public function testNoReplaceKeywordsAfterNullsafeObjectOperator(string $keyword): void { $lexer = $this->getLexer(); $code = '' . $keyword; $this->assertEquals([ new Token(\T_OPEN_TAG, '', 1, 6), new Token(\T_STRING, $keyword, 1, 9), new Token(0, "\0", 1, \strlen($code)), ], $lexer->tokenize($code)); } public static function provideTestReplaceKeywords() { return [ // PHP 8.4 ['__PROPERTY__', \T_PROPERTY_C], // PHP 8.0 ['match', \T_MATCH], // PHP 7.4 ['fn', \T_FN], // PHP 5.5 ['finally', \T_FINALLY], ['yield', \T_YIELD], // PHP 5.4 ['callable', \T_CALLABLE], ['insteadof', \T_INSTEADOF], ['trait', \T_TRAIT], ['__TRAIT__', \T_TRAIT_C], // PHP 5.3 ['__DIR__', \T_DIR], ['goto', \T_GOTO], ['namespace', \T_NAMESPACE], ['__NAMESPACE__', \T_NS_C], ]; } private function assertSameTokens(array $expectedTokens, array $tokens): void { $reducedTokens = []; foreach ($tokens as $token) { if ($token->id === 0 || $token->isIgnorable()) { continue; } $reducedTokens[] = [$token->id, $token->text]; } $this->assertSame($expectedTokens, $reducedTokens); } /** * @dataProvider provideTestLexNewFeatures */ public function testLexNewFeatures(string $code, array $expectedTokens): void { $lexer = $this->getLexer(); $this->assertSameTokens($expectedTokens, $lexer->tokenize('getLexer(); $fullCode = 'assertEquals([ new Token(\T_OPEN_TAG, 'tokenize($fullCode)); } /** * @dataProvider provideTestLexNewFeatures */ public function testErrorAfterEmulation($code): void { $errorHandler = new ErrorHandler\Collecting(); $lexer = $this->getLexer(); $lexer->tokenize('getErrors(); $this->assertCount(1, $errors); $error = $errors[0]; $this->assertSame('Unexpected null byte', $error->getRawMessage()); $attrs = $error->getAttributes(); $expPos = strlen('assertSame($expPos, $attrs['startFilePos']); $this->assertSame($expPos, $attrs['endFilePos']); $this->assertSame($expLine, $attrs['startLine']); $this->assertSame($expLine, $attrs['endLine']); } public static function provideTestLexNewFeatures() { return [ ['yield from', [ [\T_YIELD_FROM, 'yield from'], ]], ["yield\r\nfrom", [ [\T_YIELD_FROM, "yield\r\nfrom"], ]], ['...', [ [\T_ELLIPSIS, '...'], ]], ['**', [ [\T_POW, '**'], ]], ['**=', [ [\T_POW_EQUAL, '**='], ]], ['??', [ [\T_COALESCE, '??'], ]], ['<=>', [ [\T_SPACESHIP, '<=>'], ]], ['0b1010110', [ [\T_LNUMBER, '0b1010110'], ]], ['0b1011010101001010110101010010101011010101010101101011001110111100', [ [\T_DNUMBER, '0b1011010101001010110101010010101011010101010101101011001110111100'], ]], ['\\', [ [\T_NS_SEPARATOR, '\\'], ]], ["<<<'NOWDOC'\nNOWDOC;\n", [ [\T_START_HEREDOC, "<<<'NOWDOC'\n"], [\T_END_HEREDOC, 'NOWDOC'], [ord(';'), ';'], ]], ["<<<'NOWDOC'\nFoobar\nNOWDOC;\n", [ [\T_START_HEREDOC, "<<<'NOWDOC'\n"], [\T_ENCAPSED_AND_WHITESPACE, "Foobar\n"], [\T_END_HEREDOC, 'NOWDOC'], [ord(';'), ';'], ]], // PHP 7.3: Flexible heredoc/nowdoc ["<<', [ [\T_NULLSAFE_OBJECT_OPERATOR, '?->'], ]], ['#[Attr]', [ [\T_ATTRIBUTE, '#['], [\T_STRING, 'Attr'], [ord(']'), ']'], ]], ["#[\nAttr\n]", [ [\T_ATTRIBUTE, '#['], [\T_STRING, 'Attr'], [ord(']'), ']'], ]], // Test interaction of two patch-based emulators ["<<public(set)', [ [\T_OBJECT_OPERATOR, '->'], [\T_STRING, 'public'], [\ord('('), '('], [\T_STRING, 'set'], [\ord(')'), ')'], ]], ['?-> public(set)', [ [\T_NULLSAFE_OBJECT_OPERATOR, '?->'], [\T_STRING, 'public'], [\ord('('), '('], [\T_STRING, 'set'], [\ord(')'), ')'], ]], // PHP 8.5: Pipe operator ['|>', [ [\T_PIPE, '|>'] ]], // PHP 8.5: Void cast ['(void)', [ [\T_VOID_CAST, '(void)'], ]], ["( \tvoid \t)", [ [\T_VOID_CAST, "( \tvoid \t)"], ]], ['( vOiD)', [ [\T_VOID_CAST, '( vOiD)'], ]], ["(void\n)", [ [\ord('('), '('], [\T_STRING, 'void'], [\ord(')'), ')'], ]], ]; } /** * @dataProvider provideTestTargetVersion */ public function testTargetVersion(string $phpVersion, string $code, array $expectedTokens): void { $lexer = new Emulative(PhpVersion::fromString($phpVersion)); $this->assertSameTokens($expectedTokens, $lexer->tokenize('bar"', [ [ord('"'), '"'], [\T_VARIABLE, '$foo'], [\T_NULLSAFE_OBJECT_OPERATOR, '?->'], [\T_STRING, 'bar'], [ord('"'), '"'], ]], ['8.0', '"$foo?->bar baz"', [ [ord('"'), '"'], [\T_VARIABLE, '$foo'], [\T_NULLSAFE_OBJECT_OPERATOR, '?->'], [\T_STRING, 'bar'], [\T_ENCAPSED_AND_WHITESPACE, ' baz'], [ord('"'), '"'], ]], ['8.4', '__PROPERTY__', [[\T_PROPERTY_C, '__PROPERTY__']]], ['8.3', '__PROPERTY__', [[\T_STRING, '__PROPERTY__']]], ['8.4', '__property__', [[\T_PROPERTY_C, '__property__']]], ['8.3', '__property__', [[\T_STRING, '__property__']]], ['8.4', 'public(set)', [ [\T_PUBLIC_SET, 'public(set)'], ]], ['8.3', 'public(set)', [ [\T_PUBLIC, 'public'], [\ord('('), '('], [\T_STRING, 'set'], [\ord(')'), ')'] ]], ['8.5', '|>', [ [\T_PIPE, '|>'] ]], ['8.4', '|>', [ [\ord('|'), '|'], [\ord('>'), '>'], ]], ['8.5', '(void)', [ [\T_VOID_CAST, '(void)'], ]], ['8.5', "( \tvoid \t)", [ [\T_VOID_CAST, "( \tvoid \t)"], ]], ['8.4', '(void)', [ [\ord('('), '('], [\T_STRING, 'void'], [\ord(')'), ')'], ]], ['8.4', "( \tVOID \t)", [ [\ord('('), '('], [\T_STRING, 'VOID'], [\ord(')'), ')'], ]], ]; } } ================================================ FILE: test/PhpParser/LexerTest.php ================================================ markTestSkipped('HHVM does not throw warnings from token_get_all()'); } $errorHandler = new ErrorHandler\Collecting(); $lexer = $this->getLexer(); $lexer->tokenize($code, $errorHandler); $errors = $errorHandler->getErrors(); $this->assertCount(count($messages), $errors); for ($i = 0; $i < count($messages); $i++) { $this->assertSame($messages[$i], $errors[$i]->getMessageWithColumnInfo($code)); } } public static function provideTestError() { return [ ["expectException(Error::class); $this->expectExceptionMessage('Unterminated comment on line 1'); $lexer = $this->getLexer(); $lexer->tokenize("getLexer(); $tokens = $lexer->tokenize($code); foreach ($tokens as $token) { if ($token->id === 0 || $token->isIgnorable()) { continue; } $expectedToken = array_shift($expectedTokens); $this->assertSame($expectedToken[0], $token->id); $this->assertSame($expectedToken[1], $token->text); } } public static function provideTestLex() { return [ // tests PHP 8 T_NAME_* emulation [ 'getLexer(); $this->assertEquals($expectedTokens, $lexer->tokenize($code)); } } ================================================ FILE: test/PhpParser/ModifiersTest.php ================================================ assertSame('public', Modifiers::toString(Modifiers::PUBLIC)); } public function testToStringInvalid() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Unknown modifier 3'); Modifiers::toString(Modifiers::PUBLIC | Modifiers::PROTECTED); } } ================================================ FILE: test/PhpParser/NameContextTest.php ================================================ startNamespace(new Name('NS')); $nameContext->addAlias(new Name('Foo'), 'Foo', Use_::TYPE_NORMAL); $nameContext->addAlias(new Name('Foo\Bar'), 'Alias', Use_::TYPE_NORMAL); $nameContext->addAlias(new Name('Foo\fn'), 'fn', Use_::TYPE_FUNCTION); $nameContext->addAlias(new Name('Foo\CN'), 'CN', Use_::TYPE_CONSTANT); $possibleNames = $nameContext->getPossibleNames($name, $type); $possibleNames = array_map(function (Name $name) { return $name->toCodeString(); }, $possibleNames); $this->assertSame($expectedPossibleNames, $possibleNames); // Here the last name is always the shortest one $expectedShortName = $expectedPossibleNames[count($expectedPossibleNames) - 1]; $this->assertSame( $expectedShortName, $nameContext->getShortName($name, $type)->toCodeString() ); } public static function provideTestGetPossibleNames() { return [ [Use_::TYPE_NORMAL, 'Test', ['\Test']], [Use_::TYPE_NORMAL, 'Test\Namespaced', ['\Test\Namespaced']], [Use_::TYPE_NORMAL, 'NS\Test', ['\NS\Test', 'Test']], [Use_::TYPE_NORMAL, 'ns\Test', ['\ns\Test', 'Test']], [Use_::TYPE_NORMAL, 'NS\Foo\Bar', ['\NS\Foo\Bar']], [Use_::TYPE_NORMAL, 'ns\foo\Bar', ['\ns\foo\Bar']], [Use_::TYPE_NORMAL, 'Foo', ['\Foo', 'Foo']], [Use_::TYPE_NORMAL, 'Foo\Bar', ['\Foo\Bar', 'Foo\Bar', 'Alias']], [Use_::TYPE_NORMAL, 'Foo\Bar\Baz', ['\Foo\Bar\Baz', 'Foo\Bar\Baz', 'Alias\Baz']], [Use_::TYPE_NORMAL, 'Foo\fn\Bar', ['\Foo\fn\Bar', 'Foo\fn\Bar']], [Use_::TYPE_FUNCTION, 'Foo\fn\bar', ['\Foo\fn\bar', 'Foo\fn\bar']], [Use_::TYPE_FUNCTION, 'Foo\fn', ['\Foo\fn', 'Foo\fn', 'fn']], [Use_::TYPE_FUNCTION, 'Foo\FN', ['\Foo\FN', 'Foo\FN', 'fn']], [Use_::TYPE_CONSTANT, 'Foo\CN\BAR', ['\Foo\CN\BAR', 'Foo\CN\BAR']], [Use_::TYPE_CONSTANT, 'Foo\CN', ['\Foo\CN', 'Foo\CN', 'CN']], [Use_::TYPE_CONSTANT, 'foo\CN', ['\foo\CN', 'Foo\CN', 'CN']], [Use_::TYPE_CONSTANT, 'foo\cn', ['\foo\cn', 'Foo\cn']], // self/parent/static must not be fully qualified [Use_::TYPE_NORMAL, 'self', ['self']], [Use_::TYPE_NORMAL, 'parent', ['parent']], [Use_::TYPE_NORMAL, 'static', ['static']], // true/false/null do not need to be fully qualified, even in namespaces [Use_::TYPE_CONSTANT, 'true', ['\true', 'true']], [Use_::TYPE_CONSTANT, 'false', ['\false', 'false']], [Use_::TYPE_CONSTANT, 'null', ['\null', 'null']], ]; } } ================================================ FILE: test/PhpParser/Node/Expr/CallableLikeTest.php ================================================ assertSame($isFirstClassCallable, $node->isFirstClassCallable()); if (!$isFirstClassCallable) { $this->assertSame($node->getRawArgs(), $node->getArgs()); } } /** * @dataProvider provideTestGetArg */ public function testGetArg(CallLike $node, ?Arg $expected): void { $this->assertSame($expected, $node->getArg('bar', 1)); } public static function provideTestIsFirstClassCallable() { $normalArgs = [new Arg(new Int_(1))]; $callableArgs = [new VariadicPlaceholder()]; return [ [new FuncCall(new Name('test'), $normalArgs), false], [new FuncCall(new Name('test'), $callableArgs), true], [new MethodCall(new Variable('this'), 'test', $normalArgs), false], [new MethodCall(new Variable('this'), 'test', $callableArgs), true], [new StaticCall(new Name('Test'), 'test', $normalArgs), false], [new StaticCall(new Name('Test'), 'test', $callableArgs), true], [new New_(new Name('Test'), $normalArgs), false], [new NullsafeMethodCall(new Variable('this'), 'test', $normalArgs), false], // This is not legal code, but accepted by the parser. [new New_(new Name('Test'), $callableArgs), true], [new NullsafeMethodCall(new Variable('this'), 'test', $callableArgs), true], ]; } public static function provideTestGetArg() { $foo = new Arg(new Int_(1)); $namedFoo = new Arg(new Int_(1), false, false, [], new Identifier('foo')); $bar = new Arg(new Int_(2)); $namedBar = new Arg(new Int_(2), false, false, [], new Identifier('bar')); $unpack = new Arg(new Int_(3), false, true); $callableArgs = [new VariadicPlaceholder()]; return [ [new FuncCall(new Name('test'), [$foo]), null], [new FuncCall(new Name('test'), [$namedFoo]), null], [new FuncCall(new Name('test'), [$foo, $bar]), $bar], [new FuncCall(new Name('test'), [$namedBar]), $namedBar], [new FuncCall(new Name('test'), [$namedFoo, $namedBar]), $namedBar], [new FuncCall(new Name('test'), [$namedBar, $namedFoo]), $namedBar], [new FuncCall(new Name('test'), [$namedFoo, $unpack]), null], [new FuncCall(new Name('test'), $callableArgs), null], [new MethodCall(new Variable('this'), 'test', [$foo]), null], [new MethodCall(new Variable('this'), 'test', [$namedFoo]), null], [new MethodCall(new Variable('this'), 'test', [$foo, $bar]), $bar], [new MethodCall(new Variable('this'), 'test', [$namedBar]), $namedBar], [new MethodCall(new Variable('this'), 'test', [$namedFoo, $namedBar]), $namedBar], [new MethodCall(new Variable('this'), 'test', [$namedBar, $namedFoo]), $namedBar], [new MethodCall(new Variable('this'), 'test', [$namedFoo, $unpack]), null], [new MethodCall(new Variable('this'), 'test', $callableArgs), null], [new StaticCall(new Name('Test'), 'test', [$foo]), null], [new StaticCall(new Name('Test'), 'test', [$namedFoo]), null], [new StaticCall(new Name('Test'), 'test', [$foo, $bar]), $bar], [new StaticCall(new Name('Test'), 'test', [$namedBar]), $namedBar], [new StaticCall(new Name('Test'), 'test', [$namedFoo, $namedBar]), $namedBar], [new StaticCall(new Name('Test'), 'test', [$namedBar, $namedFoo]), $namedBar], [new StaticCall(new Name('Test'), 'test', [$namedFoo, $unpack]), null], [new StaticCall(new Name('Test'), 'test', $callableArgs), null], [new New_(new Name('test'), [$foo]), null], [new New_(new Name('test'), [$namedFoo]), null], [new New_(new Name('test'), [$foo, $bar]), $bar], [new New_(new Name('test'), [$namedBar]), $namedBar], [new New_(new Name('test'), [$namedFoo, $namedBar]), $namedBar], [new New_(new Name('test'), [$namedBar, $namedFoo]), $namedBar], [new New_(new Name('test'), [$namedFoo, $unpack]), null], [new NullsafeMethodCall(new Variable('this'), 'test', [$foo]), null], [new NullsafeMethodCall(new Variable('this'), 'test', [$namedFoo]), null], [new NullsafeMethodCall(new Variable('this'), 'test', [$foo, $bar]), $bar], [new NullsafeMethodCall(new Variable('this'), 'test', [$namedBar]), $namedBar], [new NullsafeMethodCall(new Variable('this'), 'test', [$namedFoo, $namedBar]), $namedBar], [new NullsafeMethodCall(new Variable('this'), 'test', [$namedBar, $namedFoo]), $namedBar], [new NullsafeMethodCall(new Variable('this'), 'test', [$namedFoo, $unpack]), null], // This is not legal code, but accepted by the parser. [new New_(new Name('Test'), $callableArgs), null], [new NullsafeMethodCall(new Variable('this'), 'test', $callableArgs), null], ]; } } ================================================ FILE: test/PhpParser/Node/IdentifierTest.php ================================================ assertSame('Foo', (string) $identifier); $this->assertSame('Foo', $identifier->toString()); $this->assertSame('foo', $identifier->toLowerString()); } /** @dataProvider provideTestIsSpecialClassName */ public function testIsSpecialClassName($identifier, $expected): void { $identifier = new Identifier($identifier); $this->assertSame($expected, $identifier->isSpecialClassName()); } public static function provideTestIsSpecialClassName() { return [ ['self', true], ['PARENT', true], ['Static', true], ['other', false], ]; } } ================================================ FILE: test/PhpParser/Node/NameTest.php ================================================ assertSame('foo\bar', $name->name); $name = new Name('foo\bar'); $this->assertSame('foo\bar', $name->name); $name = new Name($name); $this->assertSame('foo\bar', $name->name); } public function testGet(): void { $name = new Name('foo'); $this->assertSame('foo', $name->getFirst()); $this->assertSame('foo', $name->getLast()); $this->assertSame(['foo'], $name->getParts()); $name = new Name('foo\bar'); $this->assertSame('foo', $name->getFirst()); $this->assertSame('bar', $name->getLast()); $this->assertSame(['foo', 'bar'], $name->getParts()); } public function testToString(): void { $name = new Name('Foo\Bar'); $this->assertSame('Foo\Bar', (string) $name); $this->assertSame('Foo\Bar', $name->toString()); $this->assertSame('foo\bar', $name->toLowerString()); } public function testSlice(): void { $name = new Name('foo\bar\baz'); $this->assertEquals(new Name('foo\bar\baz'), $name->slice(0)); $this->assertEquals(new Name('bar\baz'), $name->slice(1)); $this->assertNull($name->slice(3)); $this->assertEquals(new Name('foo\bar\baz'), $name->slice(-3)); $this->assertEquals(new Name('bar\baz'), $name->slice(-2)); $this->assertEquals(new Name('foo\bar'), $name->slice(0, -1)); $this->assertNull($name->slice(0, -3)); $this->assertEquals(new Name('bar'), $name->slice(1, -1)); $this->assertNull($name->slice(1, -2)); $this->assertEquals(new Name('bar'), $name->slice(-2, 1)); $this->assertEquals(new Name('bar'), $name->slice(-2, -1)); $this->assertNull($name->slice(-2, -2)); } public function testSliceOffsetTooLarge(): void { $this->expectException(\OutOfBoundsException::class); $this->expectExceptionMessage('Offset 4 is out of bounds'); (new Name('foo\bar\baz'))->slice(4); } public function testSliceOffsetTooSmall(): void { $this->expectException(\OutOfBoundsException::class); $this->expectExceptionMessage('Offset -4 is out of bounds'); (new Name('foo\bar\baz'))->slice(-4); } public function testSliceLengthTooLarge(): void { $this->expectException(\OutOfBoundsException::class); $this->expectExceptionMessage('Length 4 is out of bounds'); (new Name('foo\bar\baz'))->slice(0, 4); } public function testSliceLengthTooSmall(): void { $this->expectException(\OutOfBoundsException::class); $this->expectExceptionMessage('Length -4 is out of bounds'); (new Name('foo\bar\baz'))->slice(0, -4); } public function testSliceLengthTooLargeWithOffset(): void { $this->expectException(\OutOfBoundsException::class); $this->expectExceptionMessage('Length 3 is out of bounds'); (new Name('foo\bar\baz'))->slice(1, 3); } public function testConcat(): void { $this->assertEquals(new Name('foo\bar\baz'), Name::concat('foo', 'bar\baz')); $this->assertEquals( new Name\FullyQualified('foo\bar'), Name\FullyQualified::concat(['foo'], new Name('bar')) ); $attributes = ['foo' => 'bar']; $this->assertEquals( new Name\Relative('foo\bar\baz', $attributes), Name\Relative::concat(new Name\FullyQualified('foo\bar'), 'baz', $attributes) ); $this->assertEquals(new Name('foo'), Name::concat(null, 'foo')); $this->assertEquals(new Name('foo'), Name::concat('foo', null)); $this->assertNull(Name::concat(null, null)); } public function testNameTypes(): void { $name = new Name('foo'); $this->assertTrue($name->isUnqualified()); $this->assertFalse($name->isQualified()); $this->assertFalse($name->isFullyQualified()); $this->assertFalse($name->isRelative()); $this->assertSame('foo', $name->toCodeString()); $name = new Name('foo\bar'); $this->assertFalse($name->isUnqualified()); $this->assertTrue($name->isQualified()); $this->assertFalse($name->isFullyQualified()); $this->assertFalse($name->isRelative()); $this->assertSame('foo\bar', $name->toCodeString()); $name = new Name\FullyQualified('foo'); $this->assertFalse($name->isUnqualified()); $this->assertFalse($name->isQualified()); $this->assertTrue($name->isFullyQualified()); $this->assertFalse($name->isRelative()); $this->assertSame('\foo', $name->toCodeString()); $name = new Name\Relative('foo'); $this->assertFalse($name->isUnqualified()); $this->assertFalse($name->isQualified()); $this->assertFalse($name->isFullyQualified()); $this->assertTrue($name->isRelative()); $this->assertSame('namespace\foo', $name->toCodeString()); } public function testInvalidArg(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Expected string, array of parts or Name instance'); Name::concat('foo', new \stdClass()); } public function testInvalidEmptyString(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Name cannot be empty'); new Name(''); } public function testInvalidEmptyArray(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Name cannot be empty'); new Name([]); } /** @dataProvider provideTestIsSpecialClassName */ public function testIsSpecialClassName($name, $expected): void { $name = new Name($name); $this->assertSame($expected, $name->isSpecialClassName()); } public static function provideTestIsSpecialClassName() { return [ ['self', true], ['PARENT', true], ['Static', true], ['self\not', false], ['not\self', false], ]; } } ================================================ FILE: test/PhpParser/Node/ParamTest.php ================================================ assertFalse($node->isPromoted()); $this->assertFalse($node->isPrivate()); $this->assertFalse($node->isProtected()); $this->assertFalse($node->isPrivate()); $this->assertFalse($node->isReadonly()); $this->assertFalse($node->isPublicSet()); $this->assertFalse($node->isProtectedSet()); $this->assertFalse($node->isPrivateSet()); } /** * @dataProvider provideModifiers */ public function testModifiers(string $modifier): void { $node = new Param(new Variable('foo')); $node->flags = constant(Modifiers::class . '::' . strtoupper($modifier)); $this->assertTrue($node->isPromoted()); $this->assertTrue($node->{'is' . $modifier}()); } public static function provideModifiers() { return [ ['public'], ['protected'], ['private'], ['readonly'], ['final'], ]; } public function testSetVisibility() { $node = new Param(new Variable('foo')); $node->flags = Modifiers::PRIVATE_SET; $this->assertTrue($node->isPrivateSet()); $this->assertTrue($node->isPublic()); $node->flags = Modifiers::PROTECTED_SET; $this->assertTrue($node->isProtectedSet()); $this->assertTrue($node->isPublic()); $node->flags = Modifiers::PUBLIC_SET; $this->assertTrue($node->isPublicSet()); $this->assertTrue($node->isPublic()); } public function testPromotedPropertyWithoutVisibilityModifier(): void { $node = new Param(new Variable('foo')); $get = new PropertyHook('get', null); $node->hooks[] = $get; $this->assertTrue($node->isPromoted()); $this->assertTrue($node->isPublic()); } public function testNonPromotedPropertyIsNotPublic(): void { $node = new Param(new Variable('foo')); $this->assertFalse($node->isPublic()); } } ================================================ FILE: test/PhpParser/Node/PropertyHookTest.php ================================================ constant(Modifiers::class . '::' . strtoupper($modifier)), ] ); $this->assertTrue($node->{'is' . $modifier}()); } public function testNoModifiers(): void { $node = new PropertyHook('get', null); $this->assertFalse($node->isFinal()); } public static function provideModifiers() { return [ ['final'], ]; } public function testGetStmts(): void { $expr = new Variable('test'); $get = new PropertyHook('get', $expr); $this->assertEquals([new Return_($expr)], $get->getStmts()); $set = new PropertyHook('set', $expr, [], ['propertyName' => 'abc']); $this->assertEquals([ new Expression(new Assign(new PropertyFetch(new Variable('this'), 'abc'), $expr)) ], $set->getStmts()); } public function testGetStmtsSetHookFromParser(): void { $parser = (new ParserFactory())->createForNewestSupportedVersion(); $prettyPrinter = new Standard(); $stmts = $parser->parse(<<<'CODE' 123; } public function __construct(public $prop2 { set => 456; }) {} } CODE); $hook1 = $stmts[0]->stmts[0]->hooks[0]; $this->assertEquals('$this->prop1 = 123;', $prettyPrinter->prettyPrint($hook1->getStmts())); $hook2 = $stmts[0]->stmts[1]->params[0]->hooks[0]; $this->assertEquals('$this->prop2 = 456;', $prettyPrinter->prettyPrint($hook2->getStmts())); } public function testGetStmtsUnknownHook(): void { $expr = new Variable('test'); $hook = new PropertyHook('foobar', $expr); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Unknown property hook "foobar"'); $hook->getStmts(); } public function testGetStmtsSetHookWithoutPropertyName(): void { $expr = new Variable('test'); $set = new PropertyHook('set', $expr); $this->expectException(\LogicException::class); $this->expectExceptionMessage('Can only use getStmts() on a "set" hook if the "propertyName" attribute is set'); $set->getStmts(); } } ================================================ FILE: test/PhpParser/Node/Scalar/DNumberTest.php ================================================ createForNewestSupportedVersion(); $nodes = $parser->parse('assertInstanceOf(Echo_::class, $echo); /** @var Echo_ $echo */ $dnumber = $echo->exprs[0]; $this->assertInstanceOf(Float_::class, $dnumber); /** @var Float_ $dnumber */ $this->assertSame(1234.56, $dnumber->value); $this->assertSame('1_234.56', $dnumber->getAttribute('rawValue')); } } ================================================ FILE: test/PhpParser/Node/Scalar/MagicConstTest.php ================================================ assertSame($name, $magicConst->getName()); } public static function provideTestGetName() { return [ [new MagicConst\Class_(), '__CLASS__'], [new MagicConst\Dir(), '__DIR__'], [new MagicConst\File(), '__FILE__'], [new MagicConst\Function_(), '__FUNCTION__'], [new MagicConst\Line(), '__LINE__'], [new MagicConst\Method(), '__METHOD__'], [new MagicConst\Namespace_(), '__NAMESPACE__'], [new MagicConst\Trait_(), '__TRAIT__'], ]; } } ================================================ FILE: test/PhpParser/Node/Scalar/NumberTest.php ================================================ createForNewestSupportedVersion(); $nodes = $parser->parse('assertInstanceOf(Echo_::class, $echo); /** @var Echo_ $echo */ $lnumber = $echo->exprs[0]; $this->assertInstanceOf(Int_::class, $lnumber); /** @var Int_ $lnumber */ $this->assertSame(1234, $lnumber->value); $this->assertSame('1_234', $lnumber->getAttribute('rawValue')); } } ================================================ FILE: test/PhpParser/Node/Scalar/StringTest.php ================================================ createForNewestSupportedVersion(); $nodes = $parser->parse('assertInstanceOf(Echo_::class, $echo); /** @var Echo_ $echo */ $string = $echo->exprs[0]; $this->assertInstanceOf(String_::class, $string); /** @var String_ $string */ $this->assertSame('sequence A', $string->value); $this->assertSame('"sequence \\x41"', $string->getAttribute('rawValue')); } /** * @dataProvider provideTestParseEscapeSequences */ public function testParseEscapeSequences($expected, $string, $quote): void { $this->assertSame( $expected, String_::parseEscapeSequences($string, $quote) ); } /** * @dataProvider provideTestParse */ public function testCreate($expected, $string): void { $this->assertSame( $expected, String_::parse($string) ); } public static function provideTestParseEscapeSequences() { return [ ['"', '\\"', '"'], ['\\"', '\\"', '`'], ['\\"\\`', '\\"\\`', null], ["\\\$\n\r\t\f\v", '\\\\\$\n\r\t\f\v', null], ["\x1B", '\e', null], [chr(255), '\xFF', null], [chr(255), '\377', null], [chr(0), '\400', null], ["\0", '\0', null], ['\xFF', '\\\\xFF', null], ]; } public static function provideTestParse() { $tests = [ ['A', '\'A\''], ['A', 'b\'A\''], ['A', '"A"'], ['A', 'b"A"'], ['\\', '\'\\\\\''], ['\'', '\'\\\'\''], ]; foreach (self::provideTestParseEscapeSequences() as $i => $test) { // skip second and third tests, they aren't for double quotes if ($i !== 1 && $i !== 2) { $tests[] = [$test[0], '"' . $test[1] . '"']; } } return $tests; } } ================================================ FILE: test/PhpParser/Node/Stmt/ClassConstTest.php ================================================ assertTrue($node->{'is' . $modifier}()); } public function testNoModifiers(): void { $node = new ClassConst([], 0); $this->assertTrue($node->isPublic()); $this->assertFalse($node->isProtected()); $this->assertFalse($node->isPrivate()); $this->assertFalse($node->isFinal()); } public static function provideModifiers() { return [ ['public'], ['protected'], ['private'], ['final'], ]; } } ================================================ FILE: test/PhpParser/Node/Stmt/ClassMethodTest.php ================================================ constant(Modifiers::class . '::' . strtoupper($modifier)) ]); $this->assertTrue($node->{'is' . $modifier}()); } public function testNoModifiers(): void { $node = new ClassMethod('foo', ['type' => 0]); $this->assertTrue($node->isPublic()); $this->assertFalse($node->isProtected()); $this->assertFalse($node->isPrivate()); $this->assertFalse($node->isAbstract()); $this->assertFalse($node->isFinal()); $this->assertFalse($node->isStatic()); $this->assertFalse($node->isMagic()); } public static function provideModifiers() { return [ ['public'], ['protected'], ['private'], ['abstract'], ['final'], ['static'], ]; } /** * Checks that implicit public modifier detection for method is working * * @dataProvider implicitPublicModifiers * * @param string $modifier Node type modifier */ public function testImplicitPublic(string $modifier): void { $node = new ClassMethod('foo', [ 'type' => constant(Modifiers::class . '::' . strtoupper($modifier)) ]); $this->assertTrue($node->isPublic(), 'Node should be implicitly public'); } public static function implicitPublicModifiers() { return [ ['abstract'], ['final'], ['static'], ]; } /** * @dataProvider provideMagics * * @param string $name Node name */ public function testMagic(string $name): void { $node = new ClassMethod($name); $this->assertTrue($node->isMagic(), 'Method should be magic'); } public static function provideMagics() { return [ ['__construct'], ['__DESTRUCT'], ['__caLL'], ['__callstatic'], ['__get'], ['__set'], ['__isset'], ['__unset'], ['__sleep'], ['__wakeup'], ['__tostring'], ['__set_state'], ['__clone'], ['__invoke'], ['__debuginfo'], ]; } public function testFunctionLike(): void { $param = new Param(new Variable('a')); $type = new Name('Foo'); $return = new Return_(new Variable('a')); $method = new ClassMethod('test', [ 'byRef' => false, 'params' => [$param], 'returnType' => $type, 'stmts' => [$return], ]); $this->assertFalse($method->returnsByRef()); $this->assertSame([$param], $method->getParams()); $this->assertSame($type, $method->getReturnType()); $this->assertSame([$return], $method->getStmts()); $method = new ClassMethod('test', [ 'byRef' => true, 'stmts' => null, ]); $this->assertTrue($method->returnsByRef()); $this->assertNull($method->getStmts()); } } ================================================ FILE: test/PhpParser/Node/Stmt/ClassTest.php ================================================ Modifiers::ABSTRACT]); $this->assertTrue($class->isAbstract()); $class = new Class_('Foo'); $this->assertFalse($class->isAbstract()); } public function testIsFinal(): void { $class = new Class_('Foo', ['type' => Modifiers::FINAL]); $this->assertTrue($class->isFinal()); $class = new Class_('Foo'); $this->assertFalse($class->isFinal()); } public function testGetTraitUses(): void { $traitUses = [ new TraitUse([new Trait_('foo')]), new TraitUse([new Trait_('bar')]), ]; $class = new Class_('Foo', [ 'stmts' => [ $traitUses[0], new ClassMethod('fooBar'), $traitUses[1], ] ]); $this->assertSame($traitUses, $class->getTraitUses()); } public function testGetMethods(): void { $methods = [ new ClassMethod('foo'), new ClassMethod('bar'), new ClassMethod('fooBar'), ]; $class = new Class_('Foo', [ 'stmts' => [ new TraitUse([]), $methods[0], new ClassConst([]), $methods[1], new Property(0, []), $methods[2], ] ]); $this->assertSame($methods, $class->getMethods()); } public function testGetConstants(): void { $constants = [ new ClassConst([new \PhpParser\Node\Const_('foo', new String_('foo_value'))]), new ClassConst([new \PhpParser\Node\Const_('bar', new String_('bar_value'))]), ]; $class = new Class_('Foo', [ 'stmts' => [ new TraitUse([]), $constants[0], new ClassMethod('fooBar'), $constants[1], ] ]); $this->assertSame($constants, $class->getConstants()); } public function testGetProperties(): void { $properties = [ new Property(Modifiers::PUBLIC, [new PropertyItem('foo')]), new Property(Modifiers::PUBLIC, [new PropertyItem('bar')]), ]; $class = new Class_('Foo', [ 'stmts' => [ new TraitUse([]), $properties[0], new ClassConst([]), $properties[1], new ClassMethod('fooBar'), ] ]); $this->assertSame($properties, $class->getProperties()); } public function testGetProperty(): void { $properties = [ $fooProp = new Property(Modifiers::PUBLIC, [new PropertyItem('foo1')]), $barProp = new Property(Modifiers::PUBLIC, [new PropertyItem('BAR1')]), $fooBarProp = new Property(Modifiers::PUBLIC, [new PropertyItem('foo2'), new PropertyItem('bar2')]), ]; $class = new Class_('Foo', [ 'stmts' => [ new TraitUse([]), $properties[0], new ClassConst([]), $properties[1], new ClassMethod('fooBar'), $properties[2], ] ]); $this->assertSame($fooProp, $class->getProperty('foo1')); $this->assertSame($barProp, $class->getProperty('BAR1')); $this->assertSame($fooBarProp, $class->getProperty('foo2')); $this->assertSame($fooBarProp, $class->getProperty('bar2')); $this->assertNull($class->getProperty('bar1')); $this->assertNull($class->getProperty('nonExisting')); } public function testGetMethod(): void { $methodConstruct = new ClassMethod('__CONSTRUCT'); $methodTest = new ClassMethod('test'); $class = new Class_('Foo', [ 'stmts' => [ new ClassConst([]), $methodConstruct, new Property(0, []), $methodTest, ] ]); $this->assertSame($methodConstruct, $class->getMethod('__construct')); $this->assertSame($methodTest, $class->getMethod('test')); $this->assertNull($class->getMethod('nonExisting')); } } ================================================ FILE: test/PhpParser/Node/Stmt/InterfaceTest.php ================================================ [ new Node\Stmt\ClassConst([new Node\Const_('C1', new Node\Scalar\String_('C1'))]), $methods[0], new Node\Stmt\ClassConst([new Node\Const_('C2', new Node\Scalar\String_('C2'))]), $methods[1], new Node\Stmt\ClassConst([new Node\Const_('C3', new Node\Scalar\String_('C3'))]), ] ]); $this->assertSame($methods, $interface->getMethods()); } public function testGetConstants(): void { $constants = [ new ClassConst([new \PhpParser\Node\Const_('foo', new String_('foo_value'))]), new ClassConst([new \PhpParser\Node\Const_('bar', new String_('bar_value'))]), ]; $class = new Interface_('Foo', [ 'stmts' => [ new TraitUse([]), $constants[0], new ClassMethod('fooBar'), $constants[1], ] ]); $this->assertSame($constants, $class->getConstants()); } } ================================================ FILE: test/PhpParser/Node/Stmt/PropertyTest.php ================================================ assertTrue($node->{'is' . $modifier}()); } public function testNoModifiers(): void { $node = new Property(0, []); $this->assertTrue($node->isPublic()); $this->assertFalse($node->isProtected()); $this->assertFalse($node->isPrivate()); $this->assertFalse($node->isStatic()); $this->assertFalse($node->isReadonly()); $this->assertFalse($node->isPublicSet()); $this->assertFalse($node->isProtectedSet()); $this->assertFalse($node->isPrivateSet()); } public function testStaticImplicitlyPublic(): void { $node = new Property(Modifiers::STATIC, []); $this->assertTrue($node->isPublic()); $this->assertFalse($node->isProtected()); $this->assertFalse($node->isPrivate()); $this->assertTrue($node->isStatic()); $this->assertFalse($node->isReadonly()); } public static function provideModifiers() { return [ ['public'], ['protected'], ['private'], ['static'], ['readonly'], ]; } public function testSetVisibility() { $node = new Property(Modifiers::PRIVATE_SET, []); $this->assertTrue($node->isPrivateSet()); $node = new Property(Modifiers::PROTECTED_SET, []); $this->assertTrue($node->isProtectedSet()); $node = new Property(Modifiers::PUBLIC_SET, []); $this->assertTrue($node->isPublicSet()); } public function testIsFinal() { $node = new Property(Modifiers::FINAL, []); $this->assertTrue($node->isFinal()); } public function testIsAbstract() { $node = new Property(Modifiers::ABSTRACT, []); $this->assertTrue($node->isAbstract()); } } ================================================ FILE: test/PhpParser/NodeAbstractTest.php ================================================ subNode1 = $subNode1; $this->subNode2 = $subNode2; $this->notSubNode = $notSubNode; } public function getSubNodeNames(): array { return ['subNode1', 'subNode2']; } // This method is only overwritten because the node is located in an unusual namespace public function getType(): string { return 'Dummy'; } } class NodeAbstractTest extends \PHPUnit\Framework\TestCase { public static function provideNodes() { $attributes = [ 'startLine' => 10, 'endLine' => 11, 'startTokenPos' => 12, 'endTokenPos' => 13, 'startFilePos' => 14, 'endFilePos' => 15, 'comments' => [ new Comment('// Comment 1' . "\n"), new Comment\Doc('/** doc comment */'), new Comment('// Comment 2' . "\n"), ], ]; $node = new DummyNode('value1', 'value2', 'value3', $attributes); return [ [$attributes, $node], ]; } /** * @dataProvider provideNodes */ public function testConstruct(array $attributes, Node $node) { $this->assertSame('Dummy', $node->getType()); $this->assertSame(['subNode1', 'subNode2'], $node->getSubNodeNames()); $this->assertSame(10, $node->getLine()); $this->assertSame(10, $node->getStartLine()); $this->assertSame(11, $node->getEndLine()); $this->assertSame(12, $node->getStartTokenPos()); $this->assertSame(13, $node->getEndTokenPos()); $this->assertSame(14, $node->getStartFilePos()); $this->assertSame(15, $node->getEndFilePos()); $this->assertSame('/** doc comment */', $node->getDocComment()->getText()); $this->assertSame('value1', $node->subNode1); $this->assertSame('value2', $node->subNode2); $this->assertTrue(isset($node->subNode1)); $this->assertTrue(isset($node->subNode2)); $this->assertTrue(!isset($node->subNode3)); $this->assertSame($attributes, $node->getAttributes()); $this->assertSame($attributes['comments'], $node->getComments()); return $node; } /** * @dataProvider provideNodes */ public function testGetDocComment(array $attributes, Node $node): void { $this->assertSame('/** doc comment */', $node->getDocComment()->getText()); $comments = $node->getComments(); array_splice($comments, 1, 1, []); // remove doc comment $node->setAttribute('comments', $comments); $this->assertNull($node->getDocComment()); // Remove all comments. $node->setAttribute('comments', []); $this->assertNull($node->getDocComment()); } public function testSetDocComment(): void { $node = new DummyNode(null, null, null, []); // Add doc comment to node without comments $docComment = new Comment\Doc('/** doc */'); $node->setDocComment($docComment); $this->assertSame($docComment, $node->getDocComment()); // Replace it $docComment = new Comment\Doc('/** doc 2 */'); $node->setDocComment($docComment); $this->assertSame($docComment, $node->getDocComment()); // Add docmment to node with other comments $c1 = new Comment('/* foo */'); $c2 = new Comment('/* bar */'); $docComment = new Comment\Doc('/** baz */'); $node->setAttribute('comments', [$c1, $c2]); $node->setDocComment($docComment); $this->assertSame([$c1, $c2, $docComment], $node->getAttribute('comments')); // Replace doc comment that is not at the end. $newDocComment = new Comment\Doc('/** new baz */'); $node->setAttribute('comments', [$c1, $docComment, $c2]); $node->setDocComment($newDocComment); $this->assertSame([$c1, $newDocComment, $c2], $node->getAttribute('comments')); } /** * @dataProvider provideNodes */ public function testChange(array $attributes, DummyNode $node): void { // direct modification $node->subNode1 = 'newValue'; $this->assertSame('newValue', $node->subNode1); // indirect modification $subNode = &$node->subNode1; $subNode = 'newNewValue'; $this->assertSame('newNewValue', $node->subNode1); // removal unset($node->subNode1); $this->assertFalse(isset($node->subNode1)); } /** * @dataProvider provideNodes */ public function testIteration(array $attributes, Node $node): void { // Iteration is simple object iteration over properties, // not over subnodes $i = 0; foreach ($node as $key => $value) { if ($i === 0) { $this->assertSame('subNode1', $key); $this->assertSame('value1', $value); } elseif ($i === 1) { $this->assertSame('subNode2', $key); $this->assertSame('value2', $value); } elseif ($i === 2) { $this->assertSame('notSubNode', $key); $this->assertSame('value3', $value); } else { throw new \Exception(); } $i++; } $this->assertSame(3, $i); } public function testAttributes(): void { /** @var $node Node */ $node = $this->getMockForAbstractClass(NodeAbstract::class); $this->assertEmpty($node->getAttributes()); $node->setAttribute('key', 'value'); $this->assertTrue($node->hasAttribute('key')); $this->assertSame('value', $node->getAttribute('key')); $this->assertFalse($node->hasAttribute('doesNotExist')); $this->assertNull($node->getAttribute('doesNotExist')); $this->assertSame('default', $node->getAttribute('doesNotExist', 'default')); $node->setAttribute('null', null); $this->assertTrue($node->hasAttribute('null')); $this->assertNull($node->getAttribute('null')); $this->assertNull($node->getAttribute('null', 'default')); $this->assertSame( [ 'key' => 'value', 'null' => null, ], $node->getAttributes() ); $node->setAttributes( [ 'a' => 'b', 'c' => null, ] ); $this->assertSame( [ 'a' => 'b', 'c' => null, ], $node->getAttributes() ); } public function testJsonSerialization(): void { $code = <<<'PHP' =')) { $expected = $expected81; } $parser = new Parser\Php7(new Lexer()); $stmts = $parser->parse(canonicalize($code)); $json = json_encode($stmts, JSON_PRETTY_PRINT); $this->assertEquals(canonicalize($expected), canonicalize($json)); } } ================================================ FILE: test/PhpParser/NodeDumperTest.php ================================================ assertSame($this->canonicalize($dump), $this->canonicalize($dumper->dump($node))); } public static function provideTestDump() { return [ [ [], 'array( )' ], [ ['Foo', 'Bar', 'Key' => 'FooBar'], 'array( 0: Foo 1: Bar Key: FooBar )' ], [ new Node\Name(['Hallo', 'World']), 'Name( name: Hallo\World )' ], [ new Node\Expr\Array_([ new Node\ArrayItem(new Node\Scalar\String_('Foo')) ]), 'Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_String( value: Foo ) byRef: false unpack: false ) ) )' ], ]; } public function testDumpWithPositions(): void { $parser = (new ParserFactory())->createForHostVersion(); $dumper = new NodeDumper(['dumpPositions' => true]); $code = "parse($code); $dump = $dumper->dump($stmts, $code); $this->assertSame($this->canonicalize($expected), $this->canonicalize($dump)); } public function testError(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Can only dump nodes and arrays.'); $dumper = new NodeDumper(); $dumper->dump(new \stdClass()); } } ================================================ FILE: test/PhpParser/NodeFinderTest.php ================================================ var, $assign->expr->left, $assign->expr->right]; return [$stmts, $vars]; } public function testFind(): void { $finder = new NodeFinder(); list($stmts, $vars) = $this->getStmtsAndVars(); $varFilter = function (Node $node) { return $node instanceof Expr\Variable; }; $this->assertSame($vars, $finder->find($stmts, $varFilter)); $this->assertSame($vars, $finder->find($stmts[0], $varFilter)); $noneFilter = function () { return false; }; $this->assertSame([], $finder->find($stmts, $noneFilter)); } public function testFindInstanceOf(): void { $finder = new NodeFinder(); list($stmts, $vars) = $this->getStmtsAndVars(); $this->assertSame($vars, $finder->findInstanceOf($stmts, Expr\Variable::class)); $this->assertSame($vars, $finder->findInstanceOf($stmts[0], Expr\Variable::class)); $this->assertSame([], $finder->findInstanceOf($stmts, Expr\BinaryOp\Mul::class)); } public function testFindFirst(): void { $finder = new NodeFinder(); list($stmts, $vars) = $this->getStmtsAndVars(); $varFilter = function (Node $node) { return $node instanceof Expr\Variable; }; $this->assertSame($vars[0], $finder->findFirst($stmts, $varFilter)); $this->assertSame($vars[0], $finder->findFirst($stmts[0], $varFilter)); $noneFilter = function () { return false; }; $this->assertNull($finder->findFirst($stmts, $noneFilter)); } public function testFindFirstInstanceOf(): void { $finder = new NodeFinder(); list($stmts, $vars) = $this->getStmtsAndVars(); $this->assertSame($vars[0], $finder->findFirstInstanceOf($stmts, Expr\Variable::class)); $this->assertSame($vars[0], $finder->findFirstInstanceOf($stmts[0], Expr\Variable::class)); $this->assertNull($finder->findFirstInstanceOf($stmts, Expr\BinaryOp\Mul::class)); } } ================================================ FILE: test/PhpParser/NodeTraverserTest.php ================================================ addVisitor($visitor); $this->assertEquals($stmts, $traverser->traverse($stmts)); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $echoNode], ['enterNode', $str1Node], ['leaveNode', $str1Node], ['enterNode', $str2Node], ['leaveNode', $str2Node], ['leaveNode', $echoNode], ['afterTraverse', $stmts], ], $visitor->trace); } public function testModifying(): void { $str1Node = new String_('Foo'); $str2Node = new String_('Bar'); $printNode = new Expr\Print_($str1Node); // Visitor 2 performs changes, visitors 1 and 3 observe the changes. $visitor1 = new NodeVisitorForTesting(); $visitor2 = new NodeVisitorForTesting([ ['beforeTraverse', [], [$str1Node]], ['enterNode', $str1Node, $printNode], ['enterNode', $str1Node, $str2Node], ['leaveNode', $str2Node, $str1Node], ['leaveNode', $printNode, $str1Node], ['afterTraverse', [$str1Node], []], ]); $visitor3 = new NodeVisitorForTesting(); $traverser = new NodeTraverser($visitor1, $visitor2, $visitor3); // as all operations are reversed we end where we start $this->assertEquals([], $traverser->traverse([])); $this->assertEquals([ // Sees nodes before changes on entry. ['beforeTraverse', []], ['enterNode', $str1Node], ['enterNode', $str1Node], // Sees nodes after changes on leave. ['leaveNode', $str1Node], ['leaveNode', $str1Node], ['afterTraverse', []], ], $visitor1->trace); $this->assertEquals([ // Sees nodes after changes on entry. ['beforeTraverse', [$str1Node]], ['enterNode', $printNode], ['enterNode', $str2Node], // Sees nodes before changes on leave. ['leaveNode', $str2Node], ['leaveNode', $printNode], ['afterTraverse', [$str1Node]], ], $visitor3->trace); } public function testRemoveFromLeave(): void { $str1Node = new String_('Foo'); $str2Node = new String_('Bar'); $visitor = new NodeVisitorForTesting([ ['leaveNode', $str1Node, NodeVisitor::REMOVE_NODE], ]); $visitor2 = new NodeVisitorForTesting(); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor2); $traverser->addVisitor($visitor); $stmts = [$str1Node, $str2Node]; $this->assertEquals([$str2Node], $traverser->traverse($stmts)); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $str1Node], ['enterNode', $str2Node], ['leaveNode', $str2Node], ['afterTraverse', [$str2Node]], ], $visitor2->trace); } public function testRemoveFromEnter(): void { $str1Node = new String_('Foo'); $str2Node = new String_('Bar'); $visitor = new NodeVisitorForTesting([ ['enterNode', $str1Node, NodeVisitor::REMOVE_NODE], ]); $visitor2 = new NodeVisitorForTesting(); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $traverser->addVisitor($visitor2); $stmts = [$str1Node, $str2Node]; $this->assertEquals([$str2Node], $traverser->traverse($stmts)); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $str2Node], ['leaveNode', $str2Node], ['afterTraverse', [$str2Node]], ], $visitor2->trace); } public function testReturnArrayFromEnter(): void { $str1Node = new String_('Str1'); $str2Node = new String_('Str2'); $str3Node = new String_('Str3'); $str4Node = new String_('Str4'); $visitor = new NodeVisitorForTesting([ ['enterNode', $str1Node, [$str3Node, $str4Node]], ]); $visitor2 = new NodeVisitorForTesting(); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $traverser->addVisitor($visitor2); $stmts = [$str1Node, $str2Node]; $this->assertEquals([$str3Node, $str4Node, $str2Node], $traverser->traverse($stmts)); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $str2Node], ['leaveNode', $str2Node], ['afterTraverse', [$str3Node, $str4Node, $str2Node]], ], $visitor2->trace); } public function testMerge(): void { $strStart = new String_('Start'); $strMiddle = new String_('End'); $strEnd = new String_('Middle'); $strR1 = new String_('Replacement 1'); $strR2 = new String_('Replacement 2'); $visitor = new NodeVisitorForTesting([ ['leaveNode', $strMiddle, [$strR1, $strR2]], ]); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals( [$strStart, $strR1, $strR2, $strEnd], $traverser->traverse([$strStart, $strMiddle, $strEnd]) ); } public function testInvalidDeepArray(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Invalid node structure: Contains nested arrays'); $strNode = new String_('Foo'); $stmts = [[[$strNode]]]; $traverser = new NodeTraverser(); $this->assertEquals($stmts, $traverser->traverse($stmts)); } public function testDontTraverseChildren(): void { $strNode = new String_('str'); $printNode = new Expr\Print_($strNode); $varNode = new Expr\Variable('foo'); $mulNode = new Expr\BinaryOp\Mul($varNode, $varNode); $negNode = new Expr\UnaryMinus($mulNode); $stmts = [$printNode, $negNode]; $visitor1 = new NodeVisitorForTesting([ ['enterNode', $printNode, NodeVisitor::DONT_TRAVERSE_CHILDREN], ]); $visitor2 = new NodeVisitorForTesting([ ['enterNode', $mulNode, NodeVisitor::DONT_TRAVERSE_CHILDREN], ]); $expectedTrace = [ ['beforeTraverse', $stmts], ['enterNode', $printNode], ['leaveNode', $printNode], ['enterNode', $negNode], ['enterNode', $mulNode], ['leaveNode', $mulNode], ['leaveNode', $negNode], ['afterTraverse', $stmts], ]; $traverser = new NodeTraverser(); $traverser->addVisitor($visitor1); $traverser->addVisitor($visitor2); $this->assertEquals($stmts, $traverser->traverse($stmts)); $this->assertEquals($expectedTrace, $visitor1->trace); $this->assertEquals($expectedTrace, $visitor2->trace); } public function testDontTraverseCurrentAndChildren(): void { // print 'str'; -($foo * $foo); $strNode = new String_('str'); $printNode = new Expr\Print_($strNode); $varNode = new Expr\Variable('foo'); $mulNode = new Expr\BinaryOp\Mul($varNode, $varNode); $divNode = new Expr\BinaryOp\Div($varNode, $varNode); $negNode = new Expr\UnaryMinus($mulNode); $stmts = [$printNode, $negNode]; $visitor1 = new NodeVisitorForTesting([ ['enterNode', $printNode, NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN], ['enterNode', $mulNode, NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN], ['leaveNode', $mulNode, $divNode], ]); $visitor2 = new NodeVisitorForTesting(); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor1); $traverser->addVisitor($visitor2); $resultStmts = $traverser->traverse($stmts); $this->assertInstanceOf(Expr\BinaryOp\Div::class, $resultStmts[1]->expr); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $printNode], ['leaveNode', $printNode], ['enterNode', $negNode], ['enterNode', $mulNode], ['leaveNode', $mulNode], ['leaveNode', $negNode], ['afterTraverse', $resultStmts], ], $visitor1->trace); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $negNode], ['leaveNode', $negNode], ['afterTraverse', $resultStmts], ], $visitor2->trace); } public function testStopTraversal(): void { $varNode1 = new Expr\Variable('a'); $varNode2 = new Expr\Variable('b'); $varNode3 = new Expr\Variable('c'); $mulNode = new Expr\BinaryOp\Mul($varNode1, $varNode2); $printNode = new Expr\Print_($varNode3); $stmts = [$mulNode, $printNode]; // From enterNode() with array parent $visitor = new NodeVisitorForTesting([ ['enterNode', $mulNode, NodeVisitor::STOP_TRAVERSAL], ]); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals($stmts, $traverser->traverse($stmts)); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $mulNode], ['afterTraverse', $stmts], ], $visitor->trace); // From enterNode with Node parent $visitor = new NodeVisitorForTesting([ ['enterNode', $varNode1, NodeVisitor::STOP_TRAVERSAL], ]); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals($stmts, $traverser->traverse($stmts)); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $mulNode], ['enterNode', $varNode1], ['afterTraverse', $stmts], ], $visitor->trace); // From leaveNode with Node parent $visitor = new NodeVisitorForTesting([ ['leaveNode', $varNode1, NodeVisitor::STOP_TRAVERSAL], ]); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals($stmts, $traverser->traverse($stmts)); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $mulNode], ['enterNode', $varNode1], ['leaveNode', $varNode1], ['afterTraverse', $stmts], ], $visitor->trace); // From leaveNode with array parent $visitor = new NodeVisitorForTesting([ ['leaveNode', $mulNode, NodeVisitor::STOP_TRAVERSAL], ]); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals($stmts, $traverser->traverse($stmts)); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $mulNode], ['enterNode', $varNode1], ['leaveNode', $varNode1], ['enterNode', $varNode2], ['leaveNode', $varNode2], ['leaveNode', $mulNode], ['afterTraverse', $stmts], ], $visitor->trace); // Check that pending array modifications are still carried out $visitor = new NodeVisitorForTesting([ ['leaveNode', $mulNode, NodeVisitor::REMOVE_NODE], ['enterNode', $printNode, NodeVisitor::STOP_TRAVERSAL], ]); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals([$printNode], $traverser->traverse($stmts)); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $mulNode], ['enterNode', $varNode1], ['leaveNode', $varNode1], ['enterNode', $varNode2], ['leaveNode', $varNode2], ['leaveNode', $mulNode], ['enterNode', $printNode], ['afterTraverse', [$printNode]], ], $visitor->trace); } public function testReplaceWithNull(): void { $one = new Int_(1); $else1 = new Else_(); $else2 = new Else_(); $if1 = new If_($one, ['else' => $else1]); $if2 = new If_($one, ['else' => $else2]); $stmts = [$if1, $if2]; $visitor1 = new NodeVisitorForTesting([ ['enterNode', $else1, NodeVisitor::REPLACE_WITH_NULL], ['leaveNode', $else2, NodeVisitor::REPLACE_WITH_NULL], ]); $visitor2 = new NodeVisitorForTesting(); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor1); $traverser->addVisitor($visitor2); $newStmts = $traverser->traverse($stmts); $this->assertEquals([ new If_($one), new If_($one), ], $newStmts); $this->assertEquals([ ['beforeTraverse', $stmts], ['enterNode', $if1], ['enterNode', $one], // We never see the if1 Else node. ['leaveNode', $one], ['leaveNode', $if1], ['enterNode', $if2], ['enterNode', $one], ['leaveNode', $one], // We do see the if2 Else node, as it will only be replaced afterwards. ['enterNode', $else2], ['leaveNode', $else2], ['leaveNode', $if2], ['afterTraverse', $stmts], ], $visitor2->trace); } public function testRemovingVisitor(): void { $visitor1 = new class () extends NodeVisitorAbstract {}; $visitor2 = new class () extends NodeVisitorAbstract {}; $visitor3 = new class () extends NodeVisitorAbstract {}; $traverser = new NodeTraverser(); $traverser->addVisitor($visitor1); $traverser->addVisitor($visitor2); $traverser->addVisitor($visitor3); $getVisitors = (function () { return $this->visitors; })->bindTo($traverser, NodeTraverser::class); $preExpected = [$visitor1, $visitor2, $visitor3]; $this->assertSame($preExpected, $getVisitors()); $traverser->removeVisitor($visitor2); $postExpected = [$visitor1, $visitor3]; $this->assertSame($postExpected, $getVisitors()); } public function testNoCloneNodes(): void { $stmts = [new Node\Stmt\Echo_([new String_('Foo'), new String_('Bar')])]; $traverser = new NodeTraverser(); $this->assertSame($stmts, $traverser->traverse($stmts)); } /** * @dataProvider provideTestInvalidReturn */ public function testInvalidReturn($stmts, $visitor, $message): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage($message); $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $traverser->traverse($stmts); } public static function provideTestInvalidReturn() { $num = new Node\Scalar\Int_(42); $expr = new Node\Stmt\Expression($num); $stmts = [$expr]; $visitor1 = new NodeVisitorForTesting([ ['enterNode', $expr, 'foobar'], ]); $visitor2 = new NodeVisitorForTesting([ ['enterNode', $num, 'foobar'], ]); $visitor3 = new NodeVisitorForTesting([ ['leaveNode', $num, 'foobar'], ]); $visitor4 = new NodeVisitorForTesting([ ['leaveNode', $expr, 'foobar'], ]); $visitor5 = new NodeVisitorForTesting([ ['leaveNode', $num, [new Node\Scalar\Float_(42.0)]], ]); $visitor6 = new NodeVisitorForTesting([ ['leaveNode', $expr, false], ]); $visitor7 = new NodeVisitorForTesting([ ['enterNode', $expr, new Node\Scalar\Int_(42)], ]); $visitor8 = new NodeVisitorForTesting([ ['enterNode', $num, new Node\Stmt\Return_()], ]); $visitor9 = new NodeVisitorForTesting([ ['enterNode', $expr, NodeVisitor::REPLACE_WITH_NULL], ]); $visitor10 = new NodeVisitorForTesting([ ['leaveNode', $expr, NodeVisitor::REPLACE_WITH_NULL], ]); return [ [$stmts, $visitor1, 'enterNode() returned invalid value of type string'], [$stmts, $visitor2, 'enterNode() returned invalid value of type string'], [$stmts, $visitor3, 'leaveNode() returned invalid value of type string'], [$stmts, $visitor4, 'leaveNode() returned invalid value of type string'], [$stmts, $visitor5, 'leaveNode() may only return an array if the parent structure is an array'], [$stmts, $visitor6, 'leaveNode() returned invalid value of type bool'], [$stmts, $visitor7, 'Trying to replace statement (Stmt_Expression) with expression (Scalar_Int). Are you missing a Stmt_Expression wrapper?'], [$stmts, $visitor8, 'Trying to replace expression (Scalar_Int) with statement (Stmt_Return)'], [$stmts, $visitor9, 'REPLACE_WITH_NULL can not be used if the parent structure is an array'], [$stmts, $visitor10, 'REPLACE_WITH_NULL can not be used if the parent structure is an array'], ]; } } ================================================ FILE: test/PhpParser/NodeVisitor/FindingVisitorTest.php ================================================ addVisitor($visitor); $assign = new Expr\Assign(new Expr\Variable('a'), new Expr\BinaryOp\Concat( new Expr\Variable('b'), new Expr\Variable('c') )); $stmts = [new Node\Stmt\Expression($assign)]; $traverser->traverse($stmts); $this->assertSame([ $assign->var, $assign->expr->left, $assign->expr->right, ], $visitor->getFoundNodes()); } public function testFindAll(): void { $traverser = new NodeTraverser(); $visitor = new FindingVisitor(function (Node $node) { return true; // All nodes }); $traverser->addVisitor($visitor); $assign = new Expr\Assign(new Expr\Variable('a'), new Expr\BinaryOp\Concat( new Expr\Variable('b'), new Expr\Variable('c') )); $stmts = [new Node\Stmt\Expression($assign)]; $traverser->traverse($stmts); $this->assertSame([ $stmts[0], $assign, $assign->var, $assign->expr, $assign->expr->left, $assign->expr->right, ], $visitor->getFoundNodes()); } } ================================================ FILE: test/PhpParser/NodeVisitor/FirstFindingVisitorTest.php ================================================ addVisitor($visitor); $assign = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b')); $stmts = [new Node\Stmt\Expression($assign)]; $traverser->traverse($stmts); $this->assertSame($assign->var, $visitor->getFoundNode()); } public function testFindNone(): void { $traverser = new NodeTraverser(); $visitor = new FirstFindingVisitor(function (Node $node) { return $node instanceof Node\Expr\BinaryOp; }); $traverser->addVisitor($visitor); $assign = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b')); $stmts = [new Node\Stmt\Expression($assign)]; $traverser->traverse($stmts); $this->assertNull($visitor->getFoundNode()); } } ================================================ FILE: test/PhpParser/NodeVisitor/NameResolverTest.php ================================================ parseAndResolve($code); $this->assertSame( $this->canonicalize($expectedCode), $prettyPrinter->prettyPrint($stmts) ); } /** * @covers \PhpParser\NodeVisitor\NameResolver */ public function testResolveLocations(): void { $code = <<<'EOC' $a; fn(A $a): A => $a; fn(?A $a): ?A => $a; #[X] const EXAMPLE = true; A::b(); A::$b; A::B; new A; $a instanceof A; namespace\a(); namespace\A; try { $someThing; } catch (A $a) { $someThingElse; } EOC; $expectedCode = <<<'EOC' namespace NS; #[\NS\X] class A extends \NS\B implements \NS\C, \NS\D { use \NS\E, \NS\F, \NS\G { f as private g; \NS\E::h as i; \NS\E::j insteadof \NS\F, \NS\G; } #[\NS\X] public float $php = 7.4; public ?\NS\Foo $person; protected static ?bool $probability; public \NS\A|\NS\B|int $prop; #[\NS\X] const C = 1; public const \NS\X A = \NS\X::Bar; public const \NS\X\Foo B = \NS\X\Foo::Bar; public const \X\Foo C = \X\Foo::Bar; public \NS\Foo $foo { #[\NS\X] set( #[\NS\X] \NS\Bar $v ) { } } public function __construct(public \NS\Foo $bar { #[\NS\X] set( #[\NS\X] \NS\Bar $v ) { } }) { } } #[\NS\X] interface A extends \NS\C, \NS\D { public function a(\NS\A $a): \NS\A; public function b(\NS\A|\NS\B|int $a): \NS\A|\NS\B|int; public function c(\NS\A&\NS\B $a): \NS\A&\NS\B; } #[\NS\X] enum E : int { #[\NS\X] case A = 1; } #[\NS\X] trait A { } #[\NS\X] function f( #[\NS\X] \NS\A $a ): \NS\A { } function f2(array $a): array { } function fn3(?\NS\A $a): ?\NS\A { } function fn4(?array $a): ?array { } #[\NS\X] function (\NS\A $a): \NS\A { }; #[\NS\X] fn(array $a): array => $a; fn(\NS\A $a): \NS\A => $a; fn(?\NS\A $a): ?\NS\A => $a; #[\NS\X] const EXAMPLE = true; \NS\A::b(); \NS\A::$b; \NS\A::B; new \NS\A(); $a instanceof \NS\A; \NS\a(); \NS\A; try { $someThing; } catch (\NS\A $a) { $someThingElse; } EOC; $prettyPrinter = new PhpParser\PrettyPrinter\Standard(); $stmts = $this->parseAndResolve($code); $this->assertSame( $this->canonicalize($expectedCode), $prettyPrinter->prettyPrint($stmts) ); } public function testNoResolveSpecialName(): void { $stmts = [new Node\Expr\New_(new Name('self'))]; $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver()); $this->assertEquals($stmts, $traverser->traverse($stmts)); } public function testAddDeclarationNamespacedName(): void { $nsStmts = [ new Stmt\Class_('A'), new Stmt\Interface_('B'), new Stmt\Function_('C'), new Stmt\Const_([ new Node\Const_('D', new Node\Scalar\Int_(42)) ]), new Stmt\Trait_('E'), new Expr\New_(new Stmt\Class_(null)), new Stmt\Enum_('F'), ]; $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver()); $stmts = $traverser->traverse([new Stmt\Namespace_(new Name('NS'), $nsStmts)]); $this->assertSame('NS\\A', (string) $stmts[0]->stmts[0]->namespacedName); $this->assertSame('NS\\B', (string) $stmts[0]->stmts[1]->namespacedName); $this->assertSame('NS\\C', (string) $stmts[0]->stmts[2]->namespacedName); $this->assertSame('NS\\D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); $this->assertSame('NS\\E', (string) $stmts[0]->stmts[4]->namespacedName); $this->assertNull($stmts[0]->stmts[5]->class->namespacedName); $this->assertSame('NS\\F', (string) $stmts[0]->stmts[6]->namespacedName); $stmts = $traverser->traverse([new Stmt\Namespace_(null, $nsStmts)]); $this->assertSame('A', (string) $stmts[0]->stmts[0]->namespacedName); $this->assertSame('B', (string) $stmts[0]->stmts[1]->namespacedName); $this->assertSame('C', (string) $stmts[0]->stmts[2]->namespacedName); $this->assertSame('D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); $this->assertSame('E', (string) $stmts[0]->stmts[4]->namespacedName); $this->assertNull($stmts[0]->stmts[5]->class->namespacedName); $this->assertSame('F', (string) $stmts[0]->stmts[6]->namespacedName); } public function testAddRuntimeResolvedNamespacedName(): void { $stmts = [ new Stmt\Namespace_(new Name('NS'), [ new Expr\FuncCall(new Name('foo')), new Expr\ConstFetch(new Name('FOO')), ]), new Stmt\Namespace_(null, [ new Expr\FuncCall(new Name('foo')), new Expr\ConstFetch(new Name('FOO')), ]), ]; $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver()); $stmts = $traverser->traverse($stmts); $this->assertSame('NS\\foo', (string) $stmts[0]->stmts[0]->name->getAttribute('namespacedName')); $this->assertSame('NS\\FOO', (string) $stmts[0]->stmts[1]->name->getAttribute('namespacedName')); $this->assertFalse($stmts[1]->stmts[0]->name->hasAttribute('namespacedName')); $this->assertFalse($stmts[1]->stmts[1]->name->hasAttribute('namespacedName')); } /** * @dataProvider provideTestError */ public function testError(Node $stmt, $errorMsg): void { $this->expectException(\PhpParser\Error::class); $this->expectExceptionMessage($errorMsg); $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver()); $traverser->traverse([$stmt]); } public static function provideTestError() { return [ [ new Stmt\Use_([ new Node\UseItem(new Name('A\B'), 'B', 0, ['startLine' => 1]), new Node\UseItem(new Name('C\D'), 'B', 0, ['startLine' => 2]), ], Stmt\Use_::TYPE_NORMAL), 'Cannot use C\D as B because the name is already in use on line 2' ], [ new Stmt\Use_([ new Node\UseItem(new Name('a\b'), 'b', 0, ['startLine' => 1]), new Node\UseItem(new Name('c\d'), 'B', 0, ['startLine' => 2]), ], Stmt\Use_::TYPE_FUNCTION), 'Cannot use function c\d as B because the name is already in use on line 2' ], [ new Stmt\Use_([ new Node\UseItem(new Name('A\B'), 'B', 0, ['startLine' => 1]), new Node\UseItem(new Name('C\D'), 'B', 0, ['startLine' => 2]), ], Stmt\Use_::TYPE_CONSTANT), 'Cannot use const C\D as B because the name is already in use on line 2' ], [ new Expr\New_(new Name\FullyQualified('self', ['startLine' => 3])), "'\\self' is an invalid class name on line 3" ], [ new Expr\New_(new Name\Relative('self', ['startLine' => 3])), "'\\self' is an invalid class name on line 3" ], [ new Expr\New_(new Name\FullyQualified('PARENT', ['startLine' => 3])), "'\\PARENT' is an invalid class name on line 3" ], [ new Expr\New_(new Name\Relative('STATIC', ['startLine' => 3])), "'\\STATIC' is an invalid class name on line 3" ], ]; } public function testClassNameIsCaseInsensitive(): void { $source = <<<'EOC' parse($source); $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver()); $stmts = $traverser->traverse($stmts); $stmt = $stmts[0]; $assign = $stmt->stmts[1]->expr; $this->assertSame('Bar\\Baz', $assign->expr->class->name); } public function testSpecialClassNamesAreCaseInsensitive(): void { $source = <<<'EOC' parse($source); $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver()); $stmts = $traverser->traverse($stmts); $classStmt = $stmts[0]; $methodStmt = $classStmt->stmts[0]->stmts[0]; $this->assertSame('SELF', (string) $methodStmt->stmts[0]->expr->class); $this->assertSame('PARENT', (string) $methodStmt->stmts[1]->expr->class); $this->assertSame('STATIC', (string) $methodStmt->stmts[2]->expr->class); } public function testAddOriginalNames(): void { $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver(null, ['preserveOriginalNames' => true])); $n1 = new Name('Bar'); $n2 = new Name('bar'); $origStmts = [ new Stmt\Namespace_(new Name('Foo'), [ new Expr\ClassConstFetch($n1, 'FOO'), new Expr\FuncCall($n2), ]) ]; $stmts = $traverser->traverse($origStmts); $this->assertSame($n1, $stmts[0]->stmts[0]->class->getAttribute('originalName')); $this->assertSame($n2, $stmts[0]->stmts[1]->name->getAttribute('originalName')); } public function testAttributeOnlyMode(): void { $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver(null, ['replaceNodes' => false])); $n1 = new Name('Bar'); $n2 = new Name('bar'); $origStmts = [ new Stmt\Namespace_(new Name('Foo'), [ new Expr\ClassConstFetch($n1, 'FOO'), new Expr\FuncCall($n2), ]) ]; $traverser->traverse($origStmts); $this->assertEquals( new Name\FullyQualified('Foo\Bar'), $n1->getAttribute('resolvedName')); $this->assertFalse($n2->hasAttribute('resolvedName')); $this->assertEquals( new Name\FullyQualified('Foo\bar'), $n2->getAttribute('namespacedName')); } private function parseAndResolve(string $code): array { $parser = new PhpParser\Parser\Php8(new PhpParser\Lexer\Emulative()); $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver()); $stmts = $parser->parse($code); return $traverser->traverse($stmts); } } ================================================ FILE: test/PhpParser/NodeVisitor/NodeConnectingVisitorTest.php ================================================ createForNewestSupportedVersion()->parse( 'addVisitor(new NodeConnectingVisitor()); $ast = $traverser->traverse($ast); $node = (new NodeFinder())->findFirstInstanceof($ast, Else_::class); $this->assertSame(If_::class, get_class($node->getAttribute('parent'))); $this->assertSame(ConstFetch::class, get_class($node->getAttribute('previous'))); $node = (new NodeFinder())->findFirstInstanceof($ast, ConstFetch::class); $this->assertSame(Else_::class, get_class($node->getAttribute('next'))); } public function testWeakReferences(): void { $ast = (new ParserFactory())->createForNewestSupportedVersion()->parse( 'addVisitor(new NodeConnectingVisitor(true)); $ast = $traverser->traverse($ast); $node = (new NodeFinder())->findFirstInstanceof($ast, Else_::class); $this->assertInstanceOf(\WeakReference::class, $node->getAttribute('weak_parent')); $this->assertSame(If_::class, get_class($node->getAttribute('weak_parent')->get())); $this->assertInstanceOf(\WeakReference::class, $node->getAttribute('weak_previous')); $this->assertSame(ConstFetch::class, get_class($node->getAttribute('weak_previous')->get())); $node = (new NodeFinder())->findFirstInstanceof($ast, ConstFetch::class); $this->assertInstanceOf(\WeakReference::class, $node->getAttribute('weak_next')); $this->assertSame(Else_::class, get_class($node->getAttribute('weak_next')->get())); } } ================================================ FILE: test/PhpParser/NodeVisitor/ParentConnectingVisitorTest.php ================================================ createForNewestSupportedVersion()->parse( 'addVisitor(new ParentConnectingVisitor()); $ast = $traverser->traverse($ast); $node = (new NodeFinder())->findFirstInstanceof($ast, ClassMethod::class); $this->assertSame('C', $node->getAttribute('parent')->name->toString()); } public function testWeakReferences(): void { $ast = (new ParserFactory())->createForNewestSupportedVersion()->parse( 'addVisitor(new ParentConnectingVisitor(true)); $ast = $traverser->traverse($ast); $node = (new NodeFinder())->findFirstInstanceof($ast, ClassMethod::class); $weakReference = $node->getAttribute('weak_parent'); $this->assertInstanceOf(\WeakReference::class, $weakReference); $this->assertSame('C', $weakReference->get()->name->toString()); } } ================================================ FILE: test/PhpParser/NodeVisitorForTesting.php ================================================ returns = $returns; $this->returnsPos = 0; } public function beforeTraverse(array $nodes): ?array { return $this->traceEvent('beforeTraverse', $nodes); } public function enterNode(Node $node) { return $this->traceEvent('enterNode', $node); } public function leaveNode(Node $node) { return $this->traceEvent('leaveNode', $node); } public function afterTraverse(array $nodes): ?array { return $this->traceEvent('afterTraverse', $nodes); } private function traceEvent(string $method, $param) { $this->trace[] = [$method, $param]; if ($this->returnsPos < count($this->returns)) { $currentReturn = $this->returns[$this->returnsPos]; if ($currentReturn[0] === $method && $currentReturn[1] === $param) { $this->returnsPos++; return $currentReturn[2]; } } return null; } public function __destruct() { if ($this->returnsPos !== count($this->returns)) { throw new \Exception("Expected event did not occur"); } } } ================================================ FILE: test/PhpParser/Parser/Php7Test.php ================================================ assertInstanceOf(Php8::class, $factory->createForNewestSupportedVersion()); $this->assertInstanceOf(Parser::class, $factory->createForHostVersion()); } } ================================================ FILE: test/PhpParser/ParserTestAbstract.php ================================================ expectException(Error::class); $this->expectExceptionMessage('Syntax error, unexpected EOF on line 1'); $parser = $this->getParser(new Lexer()); $parser->parse('expectException(Error::class); $this->expectExceptionMessage('Cannot use foo as self because \'self\' is a special class name on line 1'); $parser = $this->getParser(new Lexer()); $parser->parse('expectException(Error::class); $this->expectExceptionMessage('Unterminated comment on line 1'); $parser = $this->getParser(new Lexer()); $parser->parse('getParser($lexer); $stmts = $parser->parse($code); /** @var Stmt\Function_ $fn */ $fn = $stmts[0]; $this->assertInstanceOf(Stmt\Function_::class, $fn); $this->assertEquals([ 'comments' => [ new Comment\Doc('/** Doc comment */', 2, 6, 1, 2, 23, 1), ], 'startLine' => 3, 'endLine' => 7, 'startTokenPos' => 3, 'endTokenPos' => 21, 'startFilePos' => 25, 'endFilePos' => 86, ], $fn->getAttributes()); $param = $fn->params[0]; $this->assertInstanceOf(Node\Param::class, $param); $this->assertEquals([ 'startLine' => 3, 'endLine' => 3, 'startTokenPos' => 7, 'endTokenPos' => 7, 'startFilePos' => 39, 'endFilePos' => 40, ], $param->getAttributes()); /** @var Stmt\Echo_ $echo */ $echo = $fn->stmts[0]; $this->assertInstanceOf(Stmt\Echo_::class, $echo); $this->assertEquals([ 'comments' => [ new Comment("// Line", 4, 49, 12, 4, 55, 12), new Comment("// Comments", 5, 61, 14, 5, 71, 14), ], 'startLine' => 6, 'endLine' => 6, 'startTokenPos' => 16, 'endTokenPos' => 19, 'startFilePos' => 77, 'endFilePos' => 84, ], $echo->getAttributes()); /** @var \PhpParser\Node\Expr\Variable $var */ $var = $echo->exprs[0]; $this->assertInstanceOf(Expr\Variable::class, $var); $this->assertEquals([ 'startLine' => 6, 'endLine' => 6, 'startTokenPos' => 18, 'endTokenPos' => 18, 'startFilePos' => 82, 'endFilePos' => 83, ], $var->getAttributes()); } public function testInvalidToken(): void { $this->expectException(\RangeException::class); $this->expectExceptionMessage('The lexer returned an invalid token (id=999, value=foobar)'); $lexer = new InvalidTokenLexer(); $parser = $this->getParser($lexer); $parser->parse('dummy'); } /** * @dataProvider provideTestExtraAttributes */ public function testExtraAttributes($code, $expectedAttributes): void { $parser = $this->getParser(new Lexer\Emulative()); $stmts = $parser->parse("expr : $stmts[0]; $attributes = $node->getAttributes(); foreach ($expectedAttributes as $name => $value) { $this->assertSame($value, $attributes[$name]); } } public static function provideTestExtraAttributes() { return [ ['0', ['kind' => Scalar\Int_::KIND_DEC]], ['9', ['kind' => Scalar\Int_::KIND_DEC]], ['07', ['kind' => Scalar\Int_::KIND_OCT]], ['0xf', ['kind' => Scalar\Int_::KIND_HEX]], ['0XF', ['kind' => Scalar\Int_::KIND_HEX]], ['0b1', ['kind' => Scalar\Int_::KIND_BIN]], ['0B1', ['kind' => Scalar\Int_::KIND_BIN]], ['0o7', ['kind' => Scalar\Int_::KIND_OCT]], ['0O7', ['kind' => Scalar\Int_::KIND_OCT]], ['[]', ['kind' => Expr\Array_::KIND_SHORT]], ['array()', ['kind' => Expr\Array_::KIND_LONG]], ["'foo'", ['kind' => String_::KIND_SINGLE_QUOTED]], ["b'foo'", ['kind' => String_::KIND_SINGLE_QUOTED]], ["B'foo'", ['kind' => String_::KIND_SINGLE_QUOTED]], ['"foo"', ['kind' => String_::KIND_DOUBLE_QUOTED]], ['b"foo"', ['kind' => String_::KIND_DOUBLE_QUOTED]], ['B"foo"', ['kind' => String_::KIND_DOUBLE_QUOTED]], ['"foo$bar"', ['kind' => String_::KIND_DOUBLE_QUOTED]], ['b"foo$bar"', ['kind' => String_::KIND_DOUBLE_QUOTED]], ['B"foo$bar"', ['kind' => String_::KIND_DOUBLE_QUOTED]], ["<<<'STR'\nSTR\n", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'STR', 'docIndentation' => '']], ["<< String_::KIND_HEREDOC, 'docLabel' => 'STR', 'docIndentation' => '']], ["<<<\"STR\"\nSTR\n", ['kind' => String_::KIND_HEREDOC, 'docLabel' => 'STR', 'docIndentation' => '']], ["b<<<'STR'\nSTR\n", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'STR', 'docIndentation' => '']], ["B<<<'STR'\nSTR\n", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'STR', 'docIndentation' => '']], ["<<< \t 'STR'\nSTR\n", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'STR', 'docIndentation' => '']], ["<<<'\xff'\n\xff\n", ['kind' => String_::KIND_NOWDOC, 'docLabel' => "\xff", 'docIndentation' => '']], ["<<<\"STR\"\n\$a\nSTR\n", ['kind' => String_::KIND_HEREDOC, 'docLabel' => 'STR', 'docIndentation' => '']], ["b<<<\"STR\"\n\$a\nSTR\n", ['kind' => String_::KIND_HEREDOC, 'docLabel' => 'STR', 'docIndentation' => '']], ["B<<<\"STR\"\n\$a\nSTR\n", ['kind' => String_::KIND_HEREDOC, 'docLabel' => 'STR', 'docIndentation' => '']], ["<<< \t \"STR\"\n\$a\nSTR\n", ['kind' => String_::KIND_HEREDOC, 'docLabel' => 'STR', 'docIndentation' => '']], ["<< String_::KIND_HEREDOC, 'docLabel' => 'STR', 'docIndentation' => ' ']], ["<< String_::KIND_HEREDOC, 'docLabel' => 'STR', 'docIndentation' => "\t"]], ["<<<'STR'\n Foo\n STR\n", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'STR', 'docIndentation' => ' ']], ["die", ['kind' => Expr\Exit_::KIND_DIE]], ["die('done')", ['kind' => Expr\Exit_::KIND_DIE]], ["exit", ['kind' => Expr\Exit_::KIND_EXIT]], ["exit(1)", ['kind' => Expr\Exit_::KIND_EXIT]], ["?>Foo", ['hasLeadingNewline' => false]], ["?>\nFoo", ['hasLeadingNewline' => true]], ["namespace Foo;", ['kind' => Stmt\Namespace_::KIND_SEMICOLON]], ["namespace Foo {}", ['kind' => Stmt\Namespace_::KIND_BRACED]], ["namespace {}", ['kind' => Stmt\Namespace_::KIND_BRACED]], ["(float) 5.0", ['kind' => Expr\Cast\Double::KIND_FLOAT]], ["(double) 5.0", ['kind' => Expr\Cast\Double::KIND_DOUBLE]], ["(real) 5.0", ['kind' => Expr\Cast\Double::KIND_REAL]], [" ( REAL ) 5.0", ['kind' => Expr\Cast\Double::KIND_REAL]], ]; } public function testListKindAttribute(): void { $parser = $this->getParser(new Lexer\Emulative()); $stmts = $parser->parse('assertSame($stmts[0]->expr->var->getAttribute('kind'), Expr\List_::KIND_LIST); $this->assertSame($stmts[0]->expr->var->items[0]->value->getAttribute('kind'), Expr\List_::KIND_LIST); $this->assertSame($stmts[1]->expr->var->getAttribute('kind'), Expr\List_::KIND_ARRAY); $this->assertSame($stmts[1]->expr->var->items[0]->value->getAttribute('kind'), Expr\List_::KIND_ARRAY); } public function testGetTokens(): void { $lexer = new Lexer(); $parser = $this->getParser($lexer); $parser->parse('assertEquals([ new Token(\T_OPEN_TAG, 'getTokens()); } } class InvalidTokenLexer extends Lexer { public function tokenize(string $code, ?ErrorHandler $errorHandler = null): array { return [ new Token(999, 'foobar', 42), ]; } } ================================================ FILE: test/PhpParser/PhpVersionTest.php ================================================ assertSame(80200, $version->id); $version = PhpVersion::fromString('8.2'); $this->assertSame(80200, $version->id); $version = PhpVersion::fromString('8.2.14'); $this->assertSame(80200, $version->id); $version = PhpVersion::fromString('8.2.14rc1'); $this->assertSame(80200, $version->id); } public function testInvalidVersion(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Invalid PHP version "8"'); PhpVersion::fromString('8'); } public function testEquals(): void { $php74 = PhpVersion::fromComponents(7, 4); $php81 = PhpVersion::fromComponents(8, 1); $php82 = PhpVersion::fromComponents(8, 2); $this->assertTrue($php81->equals($php81)); $this->assertFalse($php81->equals($php82)); $this->assertTrue($php81->older($php82)); $this->assertFalse($php81->older($php81)); $this->assertFalse($php81->older($php74)); $this->assertFalse($php81->newerOrEqual($php82)); $this->assertTrue($php81->newerOrEqual($php81)); $this->assertTrue($php81->newerOrEqual($php74)); } } ================================================ FILE: test/PhpParser/PrettyPrinterTest.php ================================================ createForVersion($parserVersion !== null ? PhpVersion::fromString($parserVersion) : PhpVersion::getNewestSupported()); $prettyPrinter = new Standard([ 'phpVersion' => $printerVersion !== null ? PhpVersion::fromString($printerVersion) : null, 'indent' => $indent, ]); return [$parser, $prettyPrinter]; } protected function doTestPrettyPrintMethod($method, $name, $code, $expected, $modeLine) { [$parser, $prettyPrinter] = $this->createParserAndPrinter($this->parseModeLine($modeLine)); $output = canonicalize($prettyPrinter->$method($parser->parse($code))); $this->assertSame($expected, $output, $name); } /** * @dataProvider provideTestPrettyPrint */ public function testPrettyPrint($name, $code, $expected, $mode): void { $this->doTestPrettyPrintMethod('prettyPrint', $name, $code, $expected, $mode); } /** * @dataProvider provideTestPrettyPrintFile */ public function testPrettyPrintFile($name, $code, $expected, $mode): void { $this->doTestPrettyPrintMethod('prettyPrintFile', $name, $code, $expected, $mode); } public static function provideTestPrettyPrint() { return self::getTests(__DIR__ . '/../code/prettyPrinter', 'test'); } public static function provideTestPrettyPrintFile() { return self::getTests(__DIR__ . '/../code/prettyPrinter', 'file-test'); } public function testPrettyPrintExpr(): void { $prettyPrinter = new Standard(); $expr = new Expr\BinaryOp\Mul( new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b')), new Expr\Variable('c') ); $this->assertEquals('($a + $b) * $c', $prettyPrinter->prettyPrintExpr($expr)); $expr = new Expr\Closure([ 'stmts' => [new Stmt\Return_(new String_("a\nb"))] ]); $this->assertEquals("function () {\n return 'a\nb';\n}", $prettyPrinter->prettyPrintExpr($expr)); } public function testCommentBeforeInlineHTML(): void { $prettyPrinter = new PrettyPrinter\Standard(); $comment = new Comment\Doc("/**\n * This is a comment\n */"); $stmts = [new Stmt\InlineHTML('Hello World!', ['comments' => [$comment]])]; $expected = "\nHello World!"; $this->assertSame($expected, $prettyPrinter->prettyPrintFile($stmts)); } public function testArraySyntaxDefault(): void { $prettyPrinter = new Standard(['shortArraySyntax' => true]); $expr = new Expr\Array_([ new Node\ArrayItem(new String_('val'), new String_('key')) ]); $expected = "['key' => 'val']"; $this->assertSame($expected, $prettyPrinter->prettyPrintExpr($expr)); } /** * @dataProvider provideTestKindAttributes */ public function testKindAttributes($node, $expected): void { $prttyPrinter = new PrettyPrinter\Standard(); $result = $prttyPrinter->prettyPrintExpr($node); $this->assertSame($expected, $result); } public static function provideTestKindAttributes() { $nowdoc = ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'STR']; $heredoc = ['kind' => String_::KIND_HEREDOC, 'docLabel' => 'STR']; return [ // Defaults to single quoted [new String_('foo'), "'foo'"], // Explicit single/double quoted [new String_('foo', ['kind' => String_::KIND_SINGLE_QUOTED]), "'foo'"], [new String_('foo', ['kind' => String_::KIND_DOUBLE_QUOTED]), '"foo"'], // Fallback from doc string if no label [new String_('foo', ['kind' => String_::KIND_NOWDOC]), "'foo'"], [new String_('foo', ['kind' => String_::KIND_HEREDOC]), '"foo"'], // Fallback if string contains label [new String_("A\nB\nC", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'A']), "'A\nB\nC'"], [new String_("A\nB\nC", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'B']), "'A\nB\nC'"], [new String_("A\nB\nC", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'C']), "'A\nB\nC'"], [new String_("STR;", $nowdoc), "'STR;'"], [new String_("STR,", $nowdoc), "'STR,'"], [new String_(" STR", $nowdoc), "' STR'"], [new String_("\tSTR", $nowdoc), "'\tSTR'"], [new String_("STR\x80", $heredoc), '"STR\x80"'], // Doc string if label not contained (or not in ending position) [new String_("foo", $nowdoc), "<<<'STR'\nfoo\nSTR"], [new String_("foo", $heredoc), "<<prettyPrintExpr($node); $this->assertSame($expected, $result); } public static function provideTestUnnaturalLiterals() { return [ [new Int_(-1), '-1'], [new Int_(-PHP_INT_MAX - 1), '(-' . PHP_INT_MAX . '-1)'], [new Int_(-1, ['kind' => Int_::KIND_BIN]), '-0b1'], [new Int_(-1, ['kind' => Int_::KIND_OCT]), '-01'], [new Int_(-1, ['kind' => Int_::KIND_HEX]), '-0x1'], [new Float_(\INF), '1.0E+1000'], [new Float_(-\INF), '-1.0E+1000'], [new Float_(-\NAN), '\NAN'], ]; } /** @dataProvider provideTestCustomRawValue */ public function printCustomRawValue($node, $expected): void { $prettyPrinter = new PrettyPrinter\Standard(); $result = $prettyPrinter->prettyPrintExpr($node); $this->assertSame($expected, $result); } public static function provideTestCustomRawValue() { return [ // Decimal with separator [new Int_(1000, ['rawValue' => '10_00', 'shouldPrintRawValue' => true]), '10_00'], // Hexadecimal with separator [new Int_(0xDEADBEEF, ['kind' => Int_::KIND_HEX, 'rawValue' => '0xDEAD_BEEF', 'shouldPrintRawValue' => true]), '0xDEAD_BEEF'], // Binary with separator [new Int_(0b11110000, ['kind' => Int_::KIND_BIN, 'rawValue' => '0b1111_0000', 'shouldPrintRawValue' => true]), '0b1111_0000'], // Octal with separator [new Int_(0755, ['kind' => Int_::KIND_OCT, 'rawValue' => '0755_000', 'shouldPrintRawValue' => true]), '0755_000'], // Without flag set, should use default formatting [new Int_(1000, ['rawValue' => '10_00', 'shouldPrintRawValue' => false]), '1000'], ]; } public function testPrettyPrintWithError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot pretty-print AST with Error nodes'); $stmts = [new Stmt\Expression( new Expr\PropertyFetch(new Expr\Variable('a'), new Expr\Error()) )]; $prettyPrinter = new PrettyPrinter\Standard(); $prettyPrinter->prettyPrint($stmts); } public function testPrettyPrintWithErrorInClassConstFetch(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot pretty-print AST with Error nodes'); $stmts = [new Stmt\Expression( new Expr\ClassConstFetch(new Name('Foo'), new Expr\Error()) )]; $prettyPrinter = new PrettyPrinter\Standard(); $prettyPrinter->prettyPrint($stmts); } /** * @dataProvider provideTestFormatPreservingPrint */ public function testFormatPreservingPrint($name, $code, $modification, $expected, $modeLine): void { [$parser, $printer] = $this->createParserAndPrinter($this->parseModeLine($modeLine)); $traverser = new NodeTraverser(new NodeVisitor\CloningVisitor()); $oldStmts = $parser->parse($code); $oldTokens = $parser->getTokens(); $newStmts = $traverser->traverse($oldStmts); /** @var callable $fn */ eval(<<printFormatPreserving($newStmts, $oldStmts, $oldTokens); $this->assertSame(canonicalize($expected), canonicalize($newCode), $name); } public static function provideTestFormatPreservingPrint() { return self::getTests(__DIR__ . '/../code/formatPreservation', 'test', 3); } /** * @dataProvider provideTestRoundTripPrint */ public function testRoundTripPrint($name, $code, $expected, $modeLine): void { /** * This test makes sure that the format-preserving pretty printer round-trips for all * the pretty printer tests (i.e. returns the input if no changes occurred). */ [$parser, $printer] = $this->createParserAndPrinter($this->parseModeLine($modeLine)); $traverser = new NodeTraverser(new NodeVisitor\CloningVisitor()); try { $oldStmts = $parser->parse($code); } catch (Error $e) { // Can't do a format-preserving print on a file with errors return; } $oldTokens = $parser->getTokens(); $newStmts = $traverser->traverse($oldStmts); $newCode = $printer->printFormatPreserving($newStmts, $oldStmts, $oldTokens); $this->assertSame(canonicalize($code), canonicalize($newCode), $name); } public static function provideTestRoundTripPrint() { return array_merge( self::getTests(__DIR__ . '/../code/prettyPrinter', 'test'), self::getTests(__DIR__ . '/../code/parser', 'test') ); } public function testWindowsNewline(): void { $prettyPrinter = new Standard([ 'newline' => "\r\n", 'phpVersion' => PhpVersion::fromComponents(7, 2), ]); $stmts = [ new Stmt\If_(new Int_(1), [ 'stmts' => [ new Stmt\Echo_([new String_('Hello')]), new Stmt\Echo_([new String_('World')]), ], ]), ]; $code = $prettyPrinter->prettyPrint($stmts); $this->assertSame("if (1) {\r\n echo 'Hello';\r\n echo 'World';\r\n}", $code); $code = $prettyPrinter->prettyPrintFile($stmts); $this->assertSame("prettyPrintFile($stmts); $this->assertSame("Hello world", $code); $stmts = [ new Stmt\Expression(new String_('Test', [ 'kind' => String_::KIND_NOWDOC, 'docLabel' => 'STR' ])), new Stmt\Expression(new String_('Test 2', [ 'kind' => String_::KIND_HEREDOC, 'docLabel' => 'STR' ])), new Stmt\Expression(new InterpolatedString([new InterpolatedStringPart('Test 3')], [ 'kind' => String_::KIND_HEREDOC, 'docLabel' => 'STR' ])), ]; $code = $prettyPrinter->prettyPrint($stmts); $this->assertSame( "<<<'STR'\r\nTest\r\nSTR;\r\n<<expectException(\LogicException::class); $this->expectExceptionMessage('Option "newline" must be one of "\n" or "\r\n"'); new PrettyPrinter\Standard(['newline' => 'foo']); } public function testInvalidIndent(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Option "indent" must either be all spaces or a single tab'); new PrettyPrinter\Standard(['indent' => "\t "]); } } ================================================ FILE: test/PhpParser/TokenTest.php ================================================ assertSame(',', $token->getTokenName()); $token = new Token(\T_WHITESPACE, ' '); $this->assertSame('T_WHITESPACE', $token->getTokenName()); } public function testIs(): void { $token = new Token(\ord(','), ','); $this->assertTrue($token->is(\ord(','))); $this->assertFalse($token->is(\ord(';'))); $this->assertTrue($token->is(',')); $this->assertFalse($token->is(';')); $this->assertTrue($token->is([\ord(','), \ord(';')])); $this->assertFalse($token->is([\ord('!'), \ord(';')])); $this->assertTrue($token->is([',', ';'])); $this->assertFalse($token->is(['!', ';'])); } /** @dataProvider provideTestIsIgnorable */ public function testIsIgnorable(int $id, string $text, bool $isIgnorable): void { $token = new Token($id, $text); $this->assertSame($isIgnorable, $token->isIgnorable()); } public static function provideTestIsIgnorable() { return [ [\T_STRING, 'foo', false], [\T_WHITESPACE, ' ', true], [\T_COMMENT, '// foo', true], [\T_DOC_COMMENT, '/** foo */', true], [\T_OPEN_TAG, 'assertSame(',', (string) $token); $token = new Token(\T_STRING, 'foo'); $this->assertSame('foo', (string) $token); } } ================================================ FILE: test/bootstrap.php ================================================ getPathname(); yield $fileName => file_get_contents($fileName); } } ================================================ FILE: test/code/formatPreservation/addingPropertyType.test ================================================ Adding property type ----- stmts[0]->type = new Node\Identifier('string'); ----- stmts[0]->type = new Node\Identifier('int'); ----- expr; $new->class->extends = null; $new->args[] = new Expr\Variable('y'); ----- expr; $new->class->name = new Node\Identifier('Anon1'); ----- 'foo', 'b' => 'bar', ]; ----- $node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c')); $node->setAttribute('comments', [new Comment\Doc(<<expr->expr; $array->items[] = $node; ----- 'foo', 'b' => 'bar', /** * A doc comment */ 'c' => 'baz', ]; ----- 'foo', 'b' => 'bar', ]; ----- $node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c')); $node->setAttribute('comments', [new Comment("/* Block comment */")]); $array = $stmts[0]->expr->expr; $array->items[] = $node; ----- 'foo', 'b' => 'bar', /* Block comment */ 'c' => 'baz', ]; ----- 'foo', 'b' => 'bar', ]; ----- $node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c')); $node->setAttribute('comments', [new Comment("// Line comment")]); $array = $stmts[0]->expr->expr; $array->items[] = $node; ----- 'foo', 'b' => 'bar', // Line comment 'c' => 'baz', ]; ----- 'foo', ]; ----- $node = new Expr\ArrayItem(new Scalar\String_('bar'), new Scalar\String_('b')); $node->setAttribute('comments', [new Comment("// Line comment")]); $array = $stmts[0]->expr->expr; $array->items[] = $node; ----- 'foo', // Line comment 'b' => 'bar', ]; ----- setAttribute('comments', [new Comment("// Line comment")]); $array = $stmts[0]->expr->expr; $array->items[] = $node; ----- 'foo', ]; ================================================ FILE: test/code/formatPreservation/array_spread.test ================================================ Array spread ----- expr->expr; $array->items[] = new Expr\ArrayItem(new Expr\Variable('b')); ----- expr->expr; $array->items[] = new Expr\ArrayItem(new Expr\Variable('c'), null, false, [], true); ----- $a; ----- $stmts[0]->expr->expr = new Expr\Variable('b'); ----- $b; ----- $a; ----- $stmts[0]->expr->params[] = new Node\Param(new Expr\Variable('b')); ----- $a; ----- $a; ----- // TODO: Format preserving currently not supported $stmts[0]->expr->params = []; ----- $a; ----- $a; ----- $stmts[0]->expr->returnType = new Node\Identifier('bool'); ----- $a; ----- $a; ----- $stmts[0]->expr->returnType = null; ----- $a; ----- $a; static fn($a) : int => $a; ----- $stmts[0]->expr->static = true; $stmts[1]->expr->static = false; ----- $a; fn($a) : int => $a; ----- $a; fn&($a) : int => $a; ----- // TODO: Format preserving currently not supported $stmts[0]->expr->byRef = true; $stmts[1]->expr->byRef = false; ----- $a; fn($a): int => $a; ================================================ FILE: test/code/formatPreservation/attributes.test ================================================ Attributes ----- 42; ----- $attrGroup = new Node\AttributeGroup([ new Node\Attribute(new Node\Name('B'), []), ]); $stmts[0]->attrGroups[] = $attrGroup; $stmts[0]->stmts[0]->attrGroups[] = $attrGroup; $stmts[0]->stmts[0]->params[0]->attrGroups[] = $attrGroup; $stmts[0]->stmts[1]->attrGroups[] = $attrGroup; $stmts[0]->stmts[2]->attrGroups[] = $attrGroup; $stmts[1]->attrGroups[] = $attrGroup; $stmts[2]->attrGroups[] = $attrGroup; $stmts[3]->attrGroups[] = $attrGroup; $stmts[4]->expr->class->attrGroups[] = $attrGroup; $stmts[5]->expr->attrGroups[] = $attrGroup; $stmts[6]->expr->attrGroups[] = $attrGroup; ----- 42; ----- 42; ----- $attrGroup = new Node\AttributeGroup([ new Node\Attribute(new Node\Name('A'), []), ]); $attrGroup2 = new Node\AttributeGroup([ new Node\Attribute(new Node\Name('B'), []), ]); $stmts[0]->attrGroups[] = $attrGroup; $stmts[0]->attrGroups[] = $attrGroup2; $stmts[0]->stmts[0]->attrGroups[] = $attrGroup; $stmts[0]->stmts[0]->attrGroups[] = $attrGroup2; $stmts[0]->stmts[1]->attrGroups[] = $attrGroup; $stmts[0]->stmts[2]->attrGroups[] = $attrGroup; $stmts[1]->attrGroups[] = $attrGroup; $stmts[2]->attrGroups[] = $attrGroup; $stmts[3]->attrGroups[] = $attrGroup; $stmts[4]->expr->class->attrGroups[] = $attrGroup; $stmts[5]->expr->attrGroups[] = $attrGroup; $stmts[6]->expr->attrGroups[] = $attrGroup; ----- 42; ----- attrGroups[0]->attrs[] = $attr; $stmts[1]->attrGroups[0]->attrs[] = $attr; ----- exprs[0]->left->right->value = 42; ----- name = new Node\Identifier('bar'); ----- byRef = true; ----- byRef = true; ----- stmts[0]; $stmts[0]->stmts[0] = $stmts[1]; $stmts[1] = $tmp; ----- stmts[0]; $stmts[1]->stmts[0] = $stmts[2]; $stmts[2] = $tmp; // Same test, but also removing first statement, triggering fallback array_splice($stmts, 0, 1, []); ----- exprs[0] = new Expr\ConstFetch(new Node\Name('C')); ----- exprs[0]->parts[0] = new Expr\Variable('bar'); $stmts[1]->exprs[0]->parts[0] = new Expr\Variable('bar'); ----- stmts[] = new Stmt\Expression(new Expr\Variable('c')); ----- stmts[] = new Stmt\Expression(new Expr\Variable('c')); ----- stmts[0]->stmts[] = new Stmt\Expression(new Node\Expr\Variable('foo')); ----- stmts[0]->stmts[] = new Stmt\Expression(new Node\Expr\Variable('foo')); ----- stmts[0]->stmts[0]->setAttribute('comments', [new Comment("/* I'm a new comment */")]); ----- stmts[0]->stmts[0]->setAttribute('comments', [new Comment("// I'm a new comment")]); ----- expr->static = true; ----- setAttribute('comments', []); ----- getComments(); $comments[] = new Comment("// foo"); $stmts[1]->setAttribute('comments', $comments); ----- stmts[0]; $method->setAttribute('comments', [new Comment\Doc("/**\n *\n */")]); ----- setDocComment(new Comment\Doc("/** foo */")); ----- attrGroups[] = $attrGroup; $stmts[1]->attrGroups[] = $attrGroup; ----- attrGroups[0]->attrs[] = $attr; $stmts[1]->attrGroups[0]->attrs[] = $attr; ----- implements[] = new Node\Name('Iface'); $stmts[0]->implements[] = new Node\Name('Iface2'); $stmts[1]->extends[] = new Node\Name('Iface'); $stmts[1]->extends[] = new Node\Name('Iface2'); ----- 42; ----- $stmts[0]->params[] = new Node\Param(new Node\Expr\Variable('a')); $stmts[0]->params[] = new Node\Param(new Node\Expr\Variable('b')); $stmts[1]->stmts[0]->params[] = new Node\Param(new Node\Expr\Variable('a')); $stmts[1]->stmts[0]->params[] = new Node\Param(new Node\Expr\Variable('b')); $stmts[2]->expr->params[] = new Node\Param(new Node\Expr\Variable('a')); $stmts[2]->expr->params[] = new Node\Param(new Node\Expr\Variable('b')); $stmts[2]->expr->uses[] = new Node\Expr\Variable('c'); $stmts[2]->expr->uses[] = new Node\Expr\Variable('d'); $stmts[3]->expr->params[] = new Node\Param(new Node\Expr\Variable('a')); $stmts[3]->expr->params[] = new Node\Param(new Node\Expr\Variable('b')); ----- 42; ----- bar(); Foo ::bar (); new Foo (); new class () extends Foo {}; ----- $stmts[0]->expr->args[] = new Node\Expr\Variable('a'); $stmts[0]->expr->args[] = new Node\Expr\Variable('b'); $stmts[1]->expr->args[] = new Node\Expr\Variable('a'); $stmts[1]->expr->args[] = new Node\Expr\Variable('b'); $stmts[2]->expr->args[] = new Node\Expr\Variable('a'); $stmts[2]->expr->args[] = new Node\Expr\Variable('b'); $stmts[3]->expr->args[] = new Node\Expr\Variable('a'); $stmts[3]->expr->args[] = new Node\Expr\Variable('b'); $stmts[4]->expr->args[] = new Node\Expr\Variable('a'); $stmts[4]->expr->args[] = new Node\Expr\Variable('b'); ----- bar($a, $b); Foo ::bar ($a, $b); new Foo ($a, $b); new class ($a, $b) extends Foo {}; ----- expr->args[] = new Node\Expr\Variable('a'); $stmts[1]->expr->args[] = new Node\Expr\Variable('a'); $stmts[2]->expr->args[] = new Node\Expr\Variable('a'); $stmts[3]->expr->args[] = new Node\Expr\Variable('a'); $stmts[4]->expr->args[] = new Node\Expr\Variable('a'); $stmts[5]->expr->args[] = new Node\Expr\Variable('a'); $stmts[6]->expr->args[] = new Node\Expr\Variable('a'); ----- scalarType = null; ----- stmts[0]->expr = null; ----- scalarType = new Node\Identifier('int'); ----- scalarType = new Node\Identifier('int'); ----- stmts[0]->expr = new Scalar\LNumber(1); ----- stmts[] = new Node\Stmt\EnumCase('C'); ----- implements[] = new Node\Name('Z'); ----- implements[] = new Node\Name('Y'); ----- expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b')); // The parens here are "correct", because add is left assoc $stmts[1]->expr->right = new Expr\BinaryOp\Plus(new Expr\Variable('b'), new Expr\Variable('c')); // No parens necessary $stmts[2]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b')); // Parens for RHS not strictly necessary due to assign speciality $stmts[3]->expr->cond = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b')); $stmts[3]->expr->if = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b')); $stmts[3]->expr->else = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b')); // Already has parens $stmts[4]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b')); $stmts[5]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b')); ----- bar; $foo -> bar; $foo -> bar; $foo -> bar; $foo -> bar; self :: $foo; self :: $foo; new Foo(); $x instanceof Foo; Foo :: bar; Foo :: $bar; Foo :: bar(); Foo :: bar; ----- $stmts[0]->expr->name = new Expr\Variable('a'); $stmts[1]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b')); $stmts[2]->expr->var = new Expr\Variable('bar'); $stmts[3]->expr->var = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b')); $stmts[4]->expr->name = new Node\Identifier('foo'); // In this case the braces are not strictly necessary. However, on PHP 5 they may be required // depending on where the property fetch node itself occurs. $stmts[5]->expr->name = new Expr\Variable('bar'); $stmts[6]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b')); $stmts[7]->expr->name = new Node\VarLikeIdentifier('bar'); $stmts[8]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b')); $stmts[9]->expr->class = new Scalar\String_('Foo'); $stmts[10]->expr->class = new Scalar\String_('Foo'); $stmts[11]->expr->class = new Expr\ConstFetch(new Node\Name('FOO')); $stmts[12]->expr->class = new Expr\ConstFetch(new Node\Name('FOO')); $stmts[13]->expr->class = new Expr\ConstFetch(new Node\Name('FOO')); $stmts[14]->expr->name = new Expr\Variable('bar'); ----- bar; ($a . $b) -> bar; $foo -> foo; $foo -> {$bar}; $foo -> {$a . $b}; self :: $bar; self :: ${$a . $b}; new ('Foo')(); $x instanceof ('Foo'); (FOO) :: bar; (FOO) :: $bar; (FOO) :: bar(); Foo :: {$bar}; ================================================ FILE: test/code/formatPreservation/group_use.test ================================================ Group use should include trailing semicolon ----- $stmts]); ----- !!indent=" " $stmts]); ----- !!indent="\t" stmts[] = new Stmt\Expression(new Expr\Variable('y')); ----- !!indent="\t" expr; $stmts[0]->expr = new Expr\StaticCall(new Node\Name\FullyQualified('Compat'), $call->name, $call->args); ----- cond, $stmts[0]->stmts); ----- FoosetAttribute('origNode', null); ----- FooBarstmts[2] = $stmts[0]->stmts[1]; ----- BarBarstmts[1] = $stmts[0]->stmts[2]; ----- Barstmts[2]); ----- BarBarstmts, 0, 1, []); ----- BarBarstmts, 1, 1, []); ----- returnType = new Node\Name('Foo'); $stmts[0]->params[0]->type = new Node\Identifier('int'); $stmts[0]->params[1]->type = new Node\Identifier('array'); $stmts[0]->params[1]->default = new Expr\ConstFetch(new Node\Name('null')); $stmts[1]->expr->dim = new Expr\Variable('a'); $stmts[2]->expr->items[0]->key = new Scalar\String_('X'); $stmts[3]->expr->returnType = new Node\Name('Bar'); $stmts[4]->expr->if = new Expr\Variable('z'); $stmts[5]->expr->key = new Expr\Variable('k'); $stmts[6]->expr->value = new Expr\Variable('v'); $stmts[7]->num = new Scalar\LNumber(2); $stmts[8]->num = new Scalar\LNumber(2); $stmts[9]->expr = new Expr\Variable('x'); $stmts[10]->extends = new Node\Name\FullyQualified('Bar'); $stmts[10]->stmts[0]->returnType = new Node\Name('Y'); $stmts[10]->stmts[1]->props[0]->default = new Scalar\DNumber(42.0); $stmts[10]->stmts[2]->type = new Node\Identifier('int'); $stmts[11]->keyVar = new Expr\Variable('z'); $stmts[12]->vars[0]->default = new Scalar\String_('abc'); $stmts[13]->finally = new Stmt\Finally_([]); $stmts[14]->else = new Stmt\Else_([]); ----- & $value ]; function (): Bar {}; $x ? $z : $y; yield $k => $v ; yield $v ; break 2 ; continue 2 ; return $x ; class X extends \Bar { public function y(): Y {} private $x = 42.0 ; const int X = 1; } foreach ( $x as $z => $y ) {} static $var = 'abc' ; try { } catch (X $y) { } finally { } if ($cond) { // Foo } elseif ($cond2) { // Bar } else { } ----- name = new Node\Name('Foo'); ----- catches[0]->var = new Expr\Variable('e'); ----- stmts[] = new Stmt\Expression(new Expr\Variable('baz')); ----- params[] = new Node\Param(new Expr\Variable('param2')); ----- catches[0]->types[] = new Node\Name('Bar'); ----- params, new Node\Param(new Expr\Variable('param0'))); ----- params[] = new Node\Param(new Expr\Variable('param0')); ----- elseifs[] = new Stmt\ElseIf_(new Expr\Variable('cond3'), []); ----- catches[] = new Stmt\Catch_([new Node\Name('Bar')], new Expr\Variable('bar'), []); ----- setAttribute('comments', [new Comment('// Test')]); $stmts[] = $node; ----- setAttribute('comments', [new Comment('// Test'), new Comment('// Test 2')]); $stmts[0]->stmts[] = $node; ----- name->name = 'Xyz'; ----- stmts, $node); ----- setAttribute('comments', [new Comment('// Test')]); array_unshift($stmts[0]->stmts, $node); ----- setAttribute('comments', [new Comment('// Test')]); array_unshift($stmts[0]->stmts, $node); ----- setAttribute('comments', [new Comment('// Test')]); array_unshift($stmts[0]->stmts, $node); $stmts[0]->stmts[1]->setAttribute('comments', [new Comment('// Bar foo')]); ----- setAttribute('comments', [new Comment('// Test')]); array_unshift($stmts[0]->stmts, $node); $stmts[0]->stmts[1]->setAttribute('comments', []); ----- stmts, new Stmt\Expression(new Expr\Variable('a')), new Stmt\Expression(new Expr\Variable('b'))); ----- stmts = [ new Stmt\Expression(new Expr\Variable('a')), new Stmt\Expression(new Expr\Variable('b')), ]; ----- expr->expr->items, new Expr\ArrayItem(new Scalar\LNumber(42))); $stmts[0]->expr->expr->items[] = new Expr\ArrayItem(new Scalar\LNumber(24)); ----- expr->expr->items[] = new Expr\ArrayItem(new Scalar\LNumber(24)); ----- returnType->types[] = new Node\Name('C'); ----- returnType->types[] = new Node\Name('C'); ----- stmts; array_splice($fnStmts, 0, 1, $fnStmts[0]->stmts); ----- expr->var->items, 1, 0, [null]); ----- stmts[] = new Stmt\Expression(new Expr\Variable('c')); ----- foo = new Foo; $this->foo->a() ->b(); ----- $outerCall = $stmts[1]->expr; $innerCall = $outerCall->var; $var = $innerCall->var; $stmts[1]->expr = $innerCall; $stmts[2] = new Stmt\Expression(new Expr\MethodCall($var, $outerCall->name)); ----- foo = new Foo; $this->foo->a(); $this->foo->b(); ================================================ FILE: test/code/formatPreservation/listRemoval.test ================================================ Removing from list nodes ----- params); ----- params); $stmts[0]->params[] = new Node\Param(new Expr\Variable('x')); $stmts[0]->params[] = new Node\Param(new Expr\Variable('y')); ----- returnType->types); ----- catches[2]; unset($stmts[0]->catches[2]); $stmts[0]->catches = array_values($stmts[0]->catches); array_splice($stmts[0]->catches, 1, 0, [$catch]); ----- catches[2]); $stmts[0]->catches = array_values($stmts[0]->catches); ----- stmts[2] = new Node\Stmt\ClassMethod('getBar'); $stmts[0]->stmts[3] = new Node\Stmt\ClassMethod('getBaz'); ----- stmts[0]->traits[0]); ----- 'one' }; ----- $stmts[0]->expr->expr->arms[] = new Node\MatchArm(null, new Scalar\String_('two')); ----- 'one', default => 'two' }; ----- 'test', }; ----- $stmts[0]->expr->expr->arms[0]->conds[] = new Scalar\LNumber(3); ----- 'test', }; ----- 'one', 2 => 'two', 3 => 'three', }; ----- array_splice($stmts[0]->expr->expr->arms, 1, 1, []); ----- 'one', 3 => 'three', }; ----- 'test', }; ----- $stmts[0]->expr->expr->arms[0]->conds = [new Scalar\LNumber(1)]; ----- 'test', }; ----- 'test', }; ----- $stmts[0]->expr->expr->arms[0]->conds = null; ----- 'test', }; ================================================ FILE: test/code/formatPreservation/modifierChange.test ================================================ Modifier change ----- flags = Stmt\Class_::MODIFIER_ABSTRACT; $stmts[1]->flags = 0; $stmts[1]->stmts[0]->flags = Stmt\Class_::MODIFIER_PRIVATE; $stmts[1]->stmts[1]->flags = Stmt\Class_::MODIFIER_PROTECTED; $stmts[1]->stmts[2]->flags |= Stmt\Class_::MODIFIER_FINAL; ----- params[0]->flags = Stmt\Class_::MODIFIER_PRIVATE; $stmts[0]->params[1]->flags = 0; $stmts[0]->params[2]->flags = Stmt\Class_::MODIFIER_PUBLIC; ----- expr->class->flags = Modifiers::READONLY; $stmts[1]->expr->class->flags = 0; ----- stmts[0]->flags = Modifiers::PROTECTED; $stmts[0]->stmts[1]->flags = Modifiers::PROTECTED; ----- expr->args[0]->name = null; ----- expr->args[0]->name = new Node\Identifier('a'); ----- expr->args[0]->name = new Node\Identifier('XYZ'); ----- [new Comment('//Some comment here')]]); ----- 42; } } ----- $stmts[0]->stmts[0]->hooks[] = new Node\PropertyHook('set', new Scalar\Int_(123)); ----- 42; set => 123; } } ----- 42; } ) {} } ----- $stmts[0]->stmts[0]->params[0]->hooks[] = new Node\PropertyHook('set', new Scalar\Int_(123)); ----- 42; set => 123; } ) {} } ----- stmts[0]->hooks[0]->body[] = new Stmt\Expression(new Expr\Variable('b')); ----- 42; } } ----- $stmts[0]->stmts[0]->hooks[0]->flags = Modifiers::FINAL; ----- 42; } } ----- 42; } } ----- $stmts[0]->stmts[0]->hooks[0]->body = [new Stmt\Return_(new Scalar\Int_(24))]; ----- stmts[0]->hooks[0]->body = new Scalar\Int_(24); $stmts[0]->stmts[1]->hooks[0]->body = [new Stmt\Return_(new Scalar\Int_(24))]; ----- 24; } public $prop2 { &get { return 24; } } } ================================================ FILE: test/code/formatPreservation/removalViaNull.test ================================================ Removing subnodes by setting them to null ----- $b , $c => & $d]; yield $foo => $bar; yield $bar; break 2 ; continue 2 ; foreach( $array as $key => $value ) {} if ($x) { } else {} return $val ; static $x = $y ; try {} catch (X $y) {} finally {} ----- $stmts[0]->returnType = null; $stmts[0]->params[0]->default = null; $stmts[0]->params[1]->type = null; $stmts[1]->expr->returnType = null; $stmts[2]->extends = null; $stmts[2]->stmts[0]->returnType = null; $stmts[2]->stmts[1]->props[0]->default = null; $stmts[2]->stmts[2]->adaptations[0]->newName = null; $stmts[2]->stmts[3]->type = null; $stmts[3]->expr->dim = null; $stmts[4]->expr->expr = null; $stmts[5]->expr->if = null; $stmts[6]->expr->items[1]->key = null; $stmts[7]->expr->key = null; $stmts[8]->expr->value = null; $stmts[9]->num = null; $stmts[10]->num = null; $stmts[11]->keyVar = null; $stmts[12]->else = null; $stmts[13]->expr = null; $stmts[14]->vars[0]->default = null; $stmts[15]->finally = null; ----- $b , & $d]; yield $bar; yield; break; continue; foreach( $array as $value ) {} if ($x) { } return; static $x ; try {} catch (X $y) {} ----- name = null; ----- catches[0]->var = null; ----- stmts[0]->type = null; ----- expr->parts[0]->setAttribute('origNode', null); ----- ----- array( 0: Stmt_Nop( comments: array( 0: /** doc */ 1: /* foobar */ 2: // foo 3: // bar ) ) ) ----- ; ----- !!positions Syntax error, unexpected ';', expecting T_STRING or T_VARIABLE or '{' or '$' from 3:1 to 3:1 array( 0: Stmt_Expression[2:1 - 3:1]( expr: Expr_PropertyFetch[2:1 - 2:6]( var: Expr_Variable[2:1 - 2:4]( name: foo ) name: Expr_Error[3:1 - 2:6]( ) ) ) ) ----- } ----- !!positions Syntax error, unexpected '}', expecting T_STRING or T_VARIABLE or '{' or '$' from 4:1 to 4:1 array( 0: Stmt_Function[2:1 - 4:1]( attrGroups: array( ) byRef: false name: Identifier[2:10 - 2:12]( name: foo ) params: array( ) returnType: null stmts: array( 0: Stmt_Expression[3:5 - 3:10]( expr: Expr_PropertyFetch[3:5 - 3:10]( var: Expr_Variable[3:5 - 3:8]( name: bar ) name: Expr_Error[4:1 - 3:10]( ) ) ) ) ) ) ----- value $oopsAnotherValue->get() ]; $array = [ $value $oopsAnotherValue ]; $array = [ 'key' => $value $oopsAnotherValue ]; ----- Syntax error, unexpected T_VARIABLE, expecting ',' or ']' or ')' from 3:18 to 3:34 Syntax error, unexpected T_VARIABLE, expecting ',' or ']' or ')' from 6:12 to 6:28 Syntax error, unexpected T_VARIABLE, expecting ',' or ']' or ')' from 9:21 to 9:37 array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: array ) expr: Expr_Array( items: array( 0: ArrayItem( key: null value: Expr_PropertyFetch( var: Expr_Variable( name: this ) name: Identifier( name: value ) ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Expr_MethodCall( var: Expr_Variable( name: oopsAnotherValue ) name: Identifier( name: get ) args: array( ) ) byRef: false unpack: false ) ) ) ) ) 1: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: array ) expr: Expr_Array( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: value ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Expr_Variable( name: oopsAnotherValue ) byRef: false unpack: false ) ) ) ) ) 2: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: array ) expr: Expr_Array( items: array( 0: ArrayItem( key: Scalar_String( value: key ) value: Expr_Variable( name: value ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Expr_Variable( name: oopsAnotherValue ) byRef: false unpack: false ) ) ) ) ) ) ----- foo = $s; } } class B { const X = 1 } ----- Syntax error, unexpected T_PUBLIC, expecting ';' or '{' from 6:5 to 6:10 Syntax error, unexpected '}', expecting ';' from 12:1 to 12:1 array( 0: Stmt_Class( attrGroups: array( ) flags: 0 name: Identifier( name: A ) extends: null implements: array( ) stmts: array( 0: Stmt_Property( attrGroups: array( ) flags: PRIVATE (4) type: null props: array( 0: PropertyItem( name: VarLikeIdentifier( name: foo ) default: null ) ) hooks: array( ) comments: array( 0: /** @var ?string */ ) ) 1: Stmt_ClassMethod( attrGroups: array( ) flags: PUBLIC (1) byRef: false name: Identifier( name: __construct ) params: array( 0: Param( attrGroups: array( ) flags: 0 type: Identifier( name: string ) byRef: false variadic: false var: Expr_Variable( name: s ) default: null hooks: array( ) ) ) returnType: null stmts: array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_PropertyFetch( var: Expr_Variable( name: this ) name: Identifier( name: foo ) ) expr: Expr_Variable( name: s ) ) ) ) ) ) ) 1: Stmt_Class( attrGroups: array( ) flags: 0 name: Identifier( name: B ) extends: null implements: array( ) stmts: array( 0: Stmt_ClassConst( attrGroups: array( ) flags: 0 type: null consts: array( 0: Const( name: Identifier( name: X ) value: Scalar_Int( value: 1 ) ) ) ) ) ) ) ================================================ FILE: test/code/parser/expr/alternative_array_syntax.test ================================================ Alternative array syntax ----- b{'c'}; $a->b(){'c'}; A::$b{'c'}; A{0}; A::B{0}; new $array{'className'}; new $a->b{'c'}(); ----- !!version=7.4 array( 0: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_Variable( name: a ) dim: Scalar_String( value: b ) ) ) 1: Stmt_Expression( expr: Expr_FuncCall( name: Expr_ArrayDimFetch( var: Expr_Variable( name: a ) dim: Scalar_String( value: b ) ) args: array( ) ) ) 2: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) dim: Scalar_String( value: c ) ) ) 3: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_MethodCall( var: Expr_Variable( name: a ) name: Identifier( name: b ) args: array( ) ) dim: Scalar_String( value: c ) ) ) 4: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_StaticPropertyFetch( class: Name( name: A ) name: VarLikeIdentifier( name: b ) ) dim: Scalar_String( value: c ) ) ) 5: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_ConstFetch( name: Name( name: A ) ) dim: Scalar_Int( value: 0 ) ) ) 6: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_ClassConstFetch( class: Name( name: A ) name: Identifier( name: B ) ) dim: Scalar_Int( value: 0 ) ) ) 7: Stmt_Expression( expr: Expr_New( class: Expr_ArrayDimFetch( var: Expr_Variable( name: array ) dim: Scalar_String( value: className ) ) args: array( ) ) ) 8: Stmt_Expression( expr: Expr_New( class: Expr_ArrayDimFetch( var: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) dim: Scalar_String( value: c ) ) args: array( ) ) ) ) ----- b{'c'}; $a->b(){'c'}; A::$b{'c'}; A{0}; A::B{0}; new $array{'className'}; new $a->b{'c'}(); ----- Syntax error, unexpected '{' from 3:3 to 3:3 Syntax error, unexpected '{' from 4:3 to 4:3 Syntax error, unexpected '{' from 5:6 to 5:6 Syntax error, unexpected '{' from 6:8 to 6:8 Syntax error, unexpected '{' from 7:6 to 7:6 Syntax error, unexpected '{' from 8:2 to 8:2 Syntax error, unexpected '{' from 9:5 to 9:5 Syntax error, unexpected '{' from 10:11 to 10:11 Syntax error, unexpected '{' from 11:10 to 11:10 array( 0: Stmt_Expression( expr: Expr_Variable( name: a ) ) 1: Stmt_Block( stmts: array( 0: Stmt_Expression( expr: Scalar_String( value: b ) ) ) ) 2: Stmt_Expression( expr: Expr_Variable( name: a ) ) 3: Stmt_Block( stmts: array( 0: Stmt_Expression( expr: Scalar_String( value: b ) ) ) ) 4: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) ) 5: Stmt_Block( stmts: array( 0: Stmt_Expression( expr: Scalar_String( value: c ) ) ) ) 6: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: a ) name: Identifier( name: b ) args: array( ) ) ) 7: Stmt_Block( stmts: array( 0: Stmt_Expression( expr: Scalar_String( value: c ) ) ) ) 8: Stmt_Expression( expr: Expr_StaticPropertyFetch( class: Name( name: A ) name: VarLikeIdentifier( name: b ) ) ) 9: Stmt_Block( stmts: array( 0: Stmt_Expression( expr: Scalar_String( value: c ) ) ) ) 10: Stmt_Expression( expr: Expr_ConstFetch( name: Name( name: A ) ) ) 11: Stmt_Block( stmts: array( 0: Stmt_Expression( expr: Scalar_Int( value: 0 ) ) ) ) 12: Stmt_Expression( expr: Expr_ClassConstFetch( class: Name( name: A ) name: Identifier( name: B ) ) ) 13: Stmt_Block( stmts: array( 0: Stmt_Expression( expr: Scalar_Int( value: 0 ) ) ) ) 14: Stmt_Expression( expr: Expr_New( class: Expr_Variable( name: array ) args: array( ) ) ) 15: Stmt_Block( stmts: array( 0: Stmt_Expression( expr: Scalar_String( value: className ) ) ) ) 16: Stmt_Expression( expr: Expr_New( class: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) args: array( ) ) ) 17: Stmt_Block( stmts: array( 0: Stmt_Expression( expr: Scalar_String( value: c ) ) ) ) ) ================================================ FILE: test/code/parser/expr/arrayDef.test ================================================ Array definitions ----- 'd', 'e' => &$f); // short array syntax []; [1, 2, 3]; ['a' => 'b']; ----- array( 0: Stmt_Expression( expr: Expr_Array( items: array( ) ) ) 1: Stmt_Expression( expr: Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_String( value: a ) byRef: false unpack: false ) ) ) ) 2: Stmt_Expression( expr: Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_String( value: a ) byRef: false unpack: false ) ) ) ) 3: Stmt_Expression( expr: Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_String( value: a ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Scalar_String( value: b ) byRef: false unpack: false ) ) ) ) 4: Stmt_Expression( expr: Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_String( value: a ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Expr_Variable( name: b ) byRef: true unpack: false ) 2: ArrayItem( key: Scalar_String( value: c ) value: Scalar_String( value: d ) byRef: false unpack: false ) 3: ArrayItem( key: Scalar_String( value: e ) value: Expr_Variable( name: f ) byRef: true unpack: false ) ) ) ) 5: Stmt_Expression( expr: Expr_Array( items: array( ) ) comments: array( 0: // short array syntax ) ) 6: Stmt_Expression( expr: Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_Int( value: 1 ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Scalar_Int( value: 2 ) byRef: false unpack: false ) 2: ArrayItem( key: null value: Scalar_Int( value: 3 ) byRef: false unpack: false ) ) ) ) 7: Stmt_Expression( expr: Expr_Array( items: array( 0: ArrayItem( key: Scalar_String( value: a ) value: Scalar_String( value: b ) byRef: false unpack: false ) ) ) ) ) ================================================ FILE: test/code/parser/expr/arrayDestructuring.test ================================================ Array destructuring ----- $b, 'b' => $a] = $baz; ----- array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: a ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Expr_Variable( name: b ) byRef: false unpack: false ) ) ) expr: Expr_Array( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: c ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Expr_Variable( name: d ) byRef: false unpack: false ) ) ) ) ) 1: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: null 1: ArrayItem( key: null value: Expr_Variable( name: a ) byRef: false unpack: false ) 2: null 3: null 4: ArrayItem( key: null value: Expr_Variable( name: b ) byRef: false unpack: false ) 5: null ) ) expr: Expr_Variable( name: foo ) ) ) 2: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: null 1: ArrayItem( key: null value: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: a ) byRef: false unpack: false ) 1: null 2: ArrayItem( key: null value: Expr_Variable( name: x ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) 2: ArrayItem( key: null value: Expr_Variable( name: b ) byRef: false unpack: false ) ) ) expr: Expr_Variable( name: bar ) ) ) 3: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: Scalar_String( value: a ) value: Expr_Variable( name: b ) byRef: false unpack: false ) 1: ArrayItem( key: Scalar_String( value: b ) value: Expr_Variable( name: a ) byRef: false unpack: false ) ) ) expr: Expr_Variable( name: baz ) ) ) ) ================================================ FILE: test/code/parser/expr/arrayEmptyElemens.test ================================================ Array with empty elements ----- $a; fn($x = 42) => $x; static fn(&$x) => $x; fn&($x) => $x; fn($x, ...$rest) => $rest; fn(): int => $x; fn($a, $b) => $a and $b; fn($a, $b) => $a && $b; ----- array( 0: Stmt_Expression( expr: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: Identifier( name: bool ) byRef: false variadic: false var: Expr_Variable( name: a ) default: null hooks: array( ) ) ) returnType: null expr: Expr_Variable( name: a ) ) ) 1: Stmt_Expression( expr: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: x ) default: Scalar_Int( value: 42 ) hooks: array( ) ) ) returnType: null expr: Expr_Variable( name: x ) ) ) 2: Stmt_Expression( expr: Expr_ArrowFunction( attrGroups: array( ) static: true byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: true variadic: false var: Expr_Variable( name: x ) default: null hooks: array( ) ) ) returnType: null expr: Expr_Variable( name: x ) ) ) 3: Stmt_Expression( expr: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: true params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: x ) default: null hooks: array( ) ) ) returnType: null expr: Expr_Variable( name: x ) ) ) 4: Stmt_Expression( expr: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: x ) default: null hooks: array( ) ) 1: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: true var: Expr_Variable( name: rest ) default: null hooks: array( ) ) ) returnType: null expr: Expr_Variable( name: rest ) ) ) 5: Stmt_Expression( expr: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( ) returnType: Identifier( name: int ) expr: Expr_Variable( name: x ) ) ) 6: Stmt_Expression( expr: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: a ) default: null hooks: array( ) ) 1: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: b ) default: null hooks: array( ) ) ) returnType: null expr: Expr_BinaryOp_LogicalAnd( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) ) 7: Stmt_Expression( expr: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: a ) default: null hooks: array( ) ) 1: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: b ) default: null hooks: array( ) ) ) returnType: null expr: Expr_BinaryOp_BooleanAnd( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) ) ) ================================================ FILE: test/code/parser/expr/assign.test ================================================ Assignments ----- >= $b; $a **= $b; $a ??= $b; // chained assign $a = $b *= $c **= $d; // by ref assign $a =& $b; // list() assign list($a) = $b; list($a, , $b) = $c; list($a, list(, $c), $d) = $e; // inc/dec ++$a; $a++; --$a; $a--; ----- array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) comments: array( 0: // simple assign ) ) 1: Stmt_Expression( expr: Expr_AssignOp_BitwiseAnd( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) comments: array( 0: // combined assign ) ) 2: Stmt_Expression( expr: Expr_AssignOp_BitwiseOr( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 3: Stmt_Expression( expr: Expr_AssignOp_BitwiseXor( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 4: Stmt_Expression( expr: Expr_AssignOp_Concat( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 5: Stmt_Expression( expr: Expr_AssignOp_Div( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 6: Stmt_Expression( expr: Expr_AssignOp_Minus( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 7: Stmt_Expression( expr: Expr_AssignOp_Mod( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 8: Stmt_Expression( expr: Expr_AssignOp_Mul( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 9: Stmt_Expression( expr: Expr_AssignOp_Plus( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 10: Stmt_Expression( expr: Expr_AssignOp_ShiftLeft( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 11: Stmt_Expression( expr: Expr_AssignOp_ShiftRight( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 12: Stmt_Expression( expr: Expr_AssignOp_Pow( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 13: Stmt_Expression( expr: Expr_AssignOp_Coalesce( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) ) 14: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: a ) expr: Expr_AssignOp_Mul( var: Expr_Variable( name: b ) expr: Expr_AssignOp_Pow( var: Expr_Variable( name: c ) expr: Expr_Variable( name: d ) ) ) ) comments: array( 0: // chained assign ) ) 15: Stmt_Expression( expr: Expr_AssignRef( var: Expr_Variable( name: a ) expr: Expr_Variable( name: b ) ) comments: array( 0: // by ref assign ) ) 16: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: a ) byRef: false unpack: false ) ) ) expr: Expr_Variable( name: b ) ) comments: array( 0: // list() assign ) ) 17: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: a ) byRef: false unpack: false ) 1: null 2: ArrayItem( key: null value: Expr_Variable( name: b ) byRef: false unpack: false ) ) ) expr: Expr_Variable( name: c ) ) ) 18: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: a ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Expr_List( items: array( 0: null 1: ArrayItem( key: null value: Expr_Variable( name: c ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) 2: ArrayItem( key: null value: Expr_Variable( name: d ) byRef: false unpack: false ) ) ) expr: Expr_Variable( name: e ) ) ) 19: Stmt_Expression( expr: Expr_PreInc( var: Expr_Variable( name: a ) ) comments: array( 0: // inc/dec ) ) 20: Stmt_Expression( expr: Expr_PostInc( var: Expr_Variable( name: a ) ) ) 21: Stmt_Expression( expr: Expr_PreDec( var: Expr_Variable( name: a ) ) ) 22: Stmt_Expression( expr: Expr_PostDec( var: Expr_Variable( name: a ) ) ) ) ================================================ FILE: test/code/parser/expr/assignNewByRef.test ================================================ Assigning new by reference (PHP 5 only) ----- $b; $a >= $b; $a == $b; $a === $b; $a != $b; $a !== $b; $a <=> $b; $a instanceof B; $a instanceof $b; ----- array( 0: Stmt_Expression( expr: Expr_BinaryOp_Smaller( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 1: Stmt_Expression( expr: Expr_BinaryOp_SmallerOrEqual( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 2: Stmt_Expression( expr: Expr_BinaryOp_Greater( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 3: Stmt_Expression( expr: Expr_BinaryOp_GreaterOrEqual( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 4: Stmt_Expression( expr: Expr_BinaryOp_Equal( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 5: Stmt_Expression( expr: Expr_BinaryOp_Identical( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 6: Stmt_Expression( expr: Expr_BinaryOp_NotEqual( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 7: Stmt_Expression( expr: Expr_BinaryOp_NotIdentical( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 8: Stmt_Expression( expr: Expr_BinaryOp_Spaceship( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 9: Stmt_Expression( expr: Expr_Instanceof( expr: Expr_Variable( name: a ) class: Name( name: B ) ) ) 10: Stmt_Expression( expr: Expr_Instanceof( expr: Expr_Variable( name: a ) class: Expr_Variable( name: b ) ) ) ) ================================================ FILE: test/code/parser/expr/concatPrecedence.test ================================================ Precedence of concatenation in PHP 7 and PHP 8 ----- 0; const T_20 = 1 >= 0; const T_21 = 1 === 1; const T_22 = 1 !== 1; const T_23 = 0 != "0"; const T_24 = 1 == "1"; const T_25 = 1 + 2 * 3; const T_26 = "1" + 2 + "3"; const T_27 = 2 ** 3; const T_28 = [1, 2, 3][1]; const T_29 = 12 - 13; const T_30 = 12 ^ 13; const T_31 = 12 & 13; const T_32 = 12 | 13; const T_33 = 12 % 3; const T_34 = 100 >> 4; const T_35 = !false; ----- array( 0: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_1 ) value: Expr_BinaryOp_ShiftLeft( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 1 ) ) ) ) ) 1: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_2 ) value: Expr_BinaryOp_Div( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 2 ) ) ) ) ) 2: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_3 ) value: Expr_BinaryOp_Plus( left: Scalar_Float( value: 1.5 ) right: Scalar_Float( value: 1.5 ) ) ) ) ) 3: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_4 ) value: Expr_BinaryOp_Concat( left: Scalar_String( value: foo ) right: Scalar_String( value: bar ) ) ) ) ) 4: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_5 ) value: Expr_BinaryOp_Mul( left: Expr_BinaryOp_Plus( left: Scalar_Float( value: 1.5 ) right: Scalar_Float( value: 1.5 ) ) right: Scalar_Int( value: 2 ) ) ) ) ) 5: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_6 ) value: Expr_BinaryOp_Concat( left: Expr_BinaryOp_Concat( left: Expr_BinaryOp_Concat( left: Scalar_String( value: foo ) right: Scalar_Int( value: 2 ) ) right: Scalar_Int( value: 3 ) ) right: Scalar_Float( value: 4 ) ) ) ) ) 6: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_7 ) value: Scalar_MagicConst_Line( ) ) ) ) 7: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_8 ) value: Scalar_String( value: This is a test string ) ) ) ) 8: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_9 ) value: Expr_BitwiseNot( expr: Expr_UnaryMinus( expr: Scalar_Int( value: 1 ) ) ) ) ) ) 9: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_10 ) value: Expr_BinaryOp_Plus( left: Expr_Ternary( cond: Expr_UnaryMinus( expr: Scalar_Int( value: 1 ) ) if: null else: Scalar_Int( value: 1 ) ) right: Expr_Ternary( cond: Scalar_Int( value: 0 ) if: Scalar_Int( value: 2 ) else: Scalar_Int( value: 3 ) ) ) ) ) ) 10: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_11 ) value: Expr_BinaryOp_BooleanAnd( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 0 ) ) ) ) ) 11: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_12 ) value: Expr_BinaryOp_LogicalAnd( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 1 ) ) ) ) ) 12: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_13 ) value: Expr_BinaryOp_BooleanOr( left: Scalar_Int( value: 0 ) right: Scalar_Int( value: 0 ) ) ) ) ) 13: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_14 ) value: Expr_BinaryOp_LogicalOr( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 0 ) ) ) ) ) 14: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_15 ) value: Expr_BinaryOp_LogicalXor( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 1 ) ) ) ) ) 15: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_16 ) value: Expr_BinaryOp_LogicalXor( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 0 ) ) ) ) ) 16: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_17 ) value: Expr_BinaryOp_Smaller( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 0 ) ) ) ) ) 17: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_18 ) value: Expr_BinaryOp_SmallerOrEqual( left: Scalar_Int( value: 0 ) right: Scalar_Int( value: 0 ) ) ) ) ) 18: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_19 ) value: Expr_BinaryOp_Greater( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 0 ) ) ) ) ) 19: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_20 ) value: Expr_BinaryOp_GreaterOrEqual( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 0 ) ) ) ) ) 20: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_21 ) value: Expr_BinaryOp_Identical( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 1 ) ) ) ) ) 21: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_22 ) value: Expr_BinaryOp_NotIdentical( left: Scalar_Int( value: 1 ) right: Scalar_Int( value: 1 ) ) ) ) ) 22: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_23 ) value: Expr_BinaryOp_NotEqual( left: Scalar_Int( value: 0 ) right: Scalar_String( value: 0 ) ) ) ) ) 23: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_24 ) value: Expr_BinaryOp_Equal( left: Scalar_Int( value: 1 ) right: Scalar_String( value: 1 ) ) ) ) ) 24: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_25 ) value: Expr_BinaryOp_Plus( left: Scalar_Int( value: 1 ) right: Expr_BinaryOp_Mul( left: Scalar_Int( value: 2 ) right: Scalar_Int( value: 3 ) ) ) ) ) ) 25: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_26 ) value: Expr_BinaryOp_Plus( left: Expr_BinaryOp_Plus( left: Scalar_String( value: 1 ) right: Scalar_Int( value: 2 ) ) right: Scalar_String( value: 3 ) ) ) ) ) 26: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_27 ) value: Expr_BinaryOp_Pow( left: Scalar_Int( value: 2 ) right: Scalar_Int( value: 3 ) ) ) ) ) 27: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_28 ) value: Expr_ArrayDimFetch( var: Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_Int( value: 1 ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Scalar_Int( value: 2 ) byRef: false unpack: false ) 2: ArrayItem( key: null value: Scalar_Int( value: 3 ) byRef: false unpack: false ) ) ) dim: Scalar_Int( value: 1 ) ) ) ) ) 28: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_29 ) value: Expr_BinaryOp_Minus( left: Scalar_Int( value: 12 ) right: Scalar_Int( value: 13 ) ) ) ) ) 29: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_30 ) value: Expr_BinaryOp_BitwiseXor( left: Scalar_Int( value: 12 ) right: Scalar_Int( value: 13 ) ) ) ) ) 30: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_31 ) value: Expr_BinaryOp_BitwiseAnd( left: Scalar_Int( value: 12 ) right: Scalar_Int( value: 13 ) ) ) ) ) 31: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_32 ) value: Expr_BinaryOp_BitwiseOr( left: Scalar_Int( value: 12 ) right: Scalar_Int( value: 13 ) ) ) ) ) 32: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_33 ) value: Expr_BinaryOp_Mod( left: Scalar_Int( value: 12 ) right: Scalar_Int( value: 3 ) ) ) ) ) 33: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_34 ) value: Expr_BinaryOp_ShiftRight( left: Scalar_Int( value: 100 ) right: Scalar_Int( value: 4 ) ) ) ) ) 34: Stmt_Const( attrGroups: array( ) consts: array( 0: Const( name: Identifier( name: T_35 ) value: Expr_BooleanNot( expr: Expr_ConstFetch( name: Name( name: false ) ) ) ) ) ) ) ================================================ FILE: test/code/parser/expr/dynamicClassConst.test ================================================ Dynamic class constant fetch ----- b['c'](); // array dereferencing a()['b']; ----- array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: a ) args: array( ) ) comments: array( 0: // function name variations ) ) 1: Stmt_Expression( expr: Expr_FuncCall( name: Expr_Variable( name: a ) args: array( ) ) ) 2: Stmt_Expression( expr: Expr_FuncCall( name: Expr_Variable( name: Scalar_String( value: a ) ) args: array( ) ) ) 3: Stmt_Expression( expr: Expr_FuncCall( name: Expr_Variable( name: Expr_Variable( name: a ) ) args: array( ) ) ) 4: Stmt_Expression( expr: Expr_FuncCall( name: Expr_Variable( name: Expr_Variable( name: Expr_Variable( name: a ) ) ) args: array( ) ) ) 5: Stmt_Expression( expr: Expr_FuncCall( name: Expr_ArrayDimFetch( var: Expr_Variable( name: a ) dim: Scalar_String( value: b ) ) args: array( ) ) ) 6: Stmt_Expression( expr: Expr_FuncCall( name: Expr_ArrayDimFetch( var: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) dim: Scalar_String( value: c ) ) args: array( ) ) ) 7: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_FuncCall( name: Name( name: a ) args: array( ) ) dim: Scalar_String( value: b ) ) comments: array( 0: // array dereferencing ) ) ) ================================================ FILE: test/code/parser/expr/fetchAndCall/namedArgs.test ================================================ Named arguments ----- b; (new A)->b(); (new A)['b']; (new A)['b']['c']; ----- array( 0: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_New( class: Name( name: A ) args: array( ) ) name: Identifier( name: b ) ) ) 1: Stmt_Expression( expr: Expr_MethodCall( var: Expr_New( class: Name( name: A ) args: array( ) ) name: Identifier( name: b ) args: array( ) ) ) 2: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_New( class: Name( name: A ) args: array( ) ) dim: Scalar_String( value: b ) ) ) 3: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_ArrayDimFetch( var: Expr_New( class: Name( name: A ) args: array( ) ) dim: Scalar_String( value: b ) ) dim: Scalar_String( value: c ) ) ) ) ================================================ FILE: test/code/parser/expr/fetchAndCall/objectAccess.test ================================================ Object access ----- b; $a->b['c']; // method call variations $a->b(); $a->{'b'}(); $a->$b(); $a->$b['c'](); // array dereferencing $a->b()['c']; ----- array( 0: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) comments: array( 0: // property fetch variations ) ) 1: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) dim: Scalar_String( value: c ) ) ) 2: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: a ) name: Identifier( name: b ) args: array( ) ) comments: array( 0: // method call variations ) ) 3: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: a ) name: Scalar_String( value: b ) args: array( ) ) ) 4: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: a ) name: Expr_Variable( name: b ) args: array( ) ) ) 5: Stmt_Expression( expr: Expr_FuncCall( name: Expr_ArrayDimFetch( var: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Expr_Variable( name: b ) ) dim: Scalar_String( value: c ) ) args: array( ) ) ) 6: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_MethodCall( var: Expr_Variable( name: a ) name: Identifier( name: b ) args: array( ) ) dim: Scalar_String( value: c ) ) comments: array( 0: // array dereferencing ) ) ) ================================================ FILE: test/code/parser/expr/fetchAndCall/simpleArrayAccess.test ================================================ Simple array access ----- foo(...); A::foo(...); // These are invalid, but accepted on the parser level. new Foo(...); $this?->foo(...); #[Foo(...)] function foo() {} ----- array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: foo ) args: array( 0: VariadicPlaceholder( ) ) ) ) 1: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: this ) name: Identifier( name: foo ) args: array( 0: VariadicPlaceholder( ) ) ) ) 2: Stmt_Expression( expr: Expr_StaticCall( class: Name( name: A ) name: Identifier( name: foo ) args: array( 0: VariadicPlaceholder( ) ) ) ) 3: Stmt_Expression( expr: Expr_New( class: Name( name: Foo ) args: array( 0: VariadicPlaceholder( ) ) ) comments: array( 0: // These are invalid, but accepted on the parser level. ) ) 4: Stmt_Expression( expr: Expr_NullsafeMethodCall( var: Expr_Variable( name: this ) name: Identifier( name: foo ) args: array( 0: VariadicPlaceholder( ) ) ) ) 5: Stmt_Function( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: Foo ) args: array( 0: VariadicPlaceholder( ) ) ) ) ) ) byRef: false name: Identifier( name: foo ) params: array( ) returnType: null stmts: array( ) ) ) ================================================ FILE: test/code/parser/expr/includeAndEval.test ================================================ Include and eval ----- &$v) = $x; [&$v] = $x; ['k' => &$v] = $x; ----- array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: v ) byRef: true unpack: false ) ) ) expr: Expr_Variable( name: x ) ) ) 1: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: Scalar_String( value: k ) value: Expr_Variable( name: v ) byRef: true unpack: false ) ) ) expr: Expr_Variable( name: x ) ) ) 2: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: v ) byRef: true unpack: false ) ) ) expr: Expr_Variable( name: x ) ) ) 3: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: Scalar_String( value: k ) value: Expr_Variable( name: v ) byRef: true unpack: false ) ) ) expr: Expr_Variable( name: x ) ) ) ) ================================================ FILE: test/code/parser/expr/listWithKeys.test ================================================ List destructing with keys ----- $b) = ['a' => 'b']; list('a' => list($b => $c), 'd' => $e) = $x; ----- array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: Scalar_String( value: a ) value: Expr_Variable( name: b ) byRef: false unpack: false ) ) ) expr: Expr_Array( items: array( 0: ArrayItem( key: Scalar_String( value: a ) value: Scalar_String( value: b ) byRef: false unpack: false ) ) ) ) ) 1: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( 0: ArrayItem( key: Scalar_String( value: a ) value: Expr_List( items: array( 0: ArrayItem( key: Expr_Variable( name: b ) value: Expr_Variable( name: c ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) 1: ArrayItem( key: Scalar_String( value: d ) value: Expr_Variable( name: e ) byRef: false unpack: false ) ) ) expr: Expr_Variable( name: x ) ) ) ) ================================================ FILE: test/code/parser/expr/logic.test ================================================ Logical operators ----- 'Foo', 1 => 'Bar', }; ----- array( 0: Stmt_Echo( exprs: array( 0: Expr_Match( cond: Scalar_Int( value: 1 ) arms: array( 0: MatchArm( conds: array( 0: Scalar_Int( value: 0 ) ) body: Scalar_String( value: Foo ) ) 1: MatchArm( conds: array( 0: Scalar_Int( value: 1 ) ) body: Scalar_String( value: Bar ) ) ) ) ) ) ) ----- 'Foo', }; ----- array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: value ) expr: Expr_Match( cond: Scalar_Int( value: 1 ) arms: array( 0: MatchArm( conds: array( 0: Scalar_Int( value: 0 ) 1: Scalar_Int( value: 1 ) ) body: Scalar_String( value: Foo ) comments: array( 0: // list of conditions ) ) ) ) ) ) ) ----- $lhs + $rhs, }; ----- array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: result ) expr: Expr_Match( cond: Expr_Variable( name: operator ) arms: array( 0: MatchArm( conds: array( 0: Expr_ClassConstFetch( class: Name( name: BinaryOperator ) name: Identifier( name: ADD ) ) ) body: Expr_BinaryOp_Plus( left: Expr_Variable( name: lhs ) right: Expr_Variable( name: rhs ) ) ) ) ) ) ) ) ----- '1', default => 'default' }; ----- array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: value ) expr: Expr_Match( cond: Expr_Variable( name: char ) arms: array( 0: MatchArm( conds: array( 0: Scalar_Int( value: 1 ) ) body: Scalar_String( value: 1 ) ) 1: MatchArm( conds: null body: Scalar_String( value: default ) ) ) ) ) ) ) ----- 'Foo', default, => 'Bar', }; ----- array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: value ) expr: Expr_Match( cond: Scalar_Int( value: 1 ) arms: array( 0: MatchArm( conds: array( 0: Scalar_Int( value: 0 ) 1: Scalar_Int( value: 1 ) ) body: Scalar_String( value: Foo ) ) 1: MatchArm( conds: null body: Scalar_String( value: Bar ) ) ) ) ) ) ) ================================================ FILE: test/code/parser/expr/math.test ================================================ Mathematical operators ----- > $b; $a ** $b; // associativity $a * $b * $c; $a * ($b * $c); // precedence $a + $b * $c; ($a + $b) * $c; // pow is special $a ** $b ** $c; ($a ** $b) ** $c; ----- array( 0: Stmt_Expression( expr: Expr_BitwiseNot( expr: Expr_Variable( name: a ) ) comments: array( 0: // unary ops ) ) 1: Stmt_Expression( expr: Expr_UnaryPlus( expr: Expr_Variable( name: a ) ) ) 2: Stmt_Expression( expr: Expr_UnaryMinus( expr: Expr_Variable( name: a ) ) ) 3: Stmt_Expression( expr: Expr_BinaryOp_BitwiseAnd( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) comments: array( 0: // binary ops ) ) 4: Stmt_Expression( expr: Expr_BinaryOp_BitwiseOr( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 5: Stmt_Expression( expr: Expr_BinaryOp_BitwiseXor( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 6: Stmt_Expression( expr: Expr_BinaryOp_Concat( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 7: Stmt_Expression( expr: Expr_BinaryOp_Div( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 8: Stmt_Expression( expr: Expr_BinaryOp_Minus( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 9: Stmt_Expression( expr: Expr_BinaryOp_Mod( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 10: Stmt_Expression( expr: Expr_BinaryOp_Mul( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 11: Stmt_Expression( expr: Expr_BinaryOp_Plus( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 12: Stmt_Expression( expr: Expr_BinaryOp_ShiftLeft( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 13: Stmt_Expression( expr: Expr_BinaryOp_ShiftRight( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 14: Stmt_Expression( expr: Expr_BinaryOp_Pow( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) 15: Stmt_Expression( expr: Expr_BinaryOp_Mul( left: Expr_BinaryOp_Mul( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) right: Expr_Variable( name: c ) ) comments: array( 0: // associativity ) ) 16: Stmt_Expression( expr: Expr_BinaryOp_Mul( left: Expr_Variable( name: a ) right: Expr_BinaryOp_Mul( left: Expr_Variable( name: b ) right: Expr_Variable( name: c ) ) ) ) 17: Stmt_Expression( expr: Expr_BinaryOp_Plus( left: Expr_Variable( name: a ) right: Expr_BinaryOp_Mul( left: Expr_Variable( name: b ) right: Expr_Variable( name: c ) ) ) comments: array( 0: // precedence ) ) 18: Stmt_Expression( expr: Expr_BinaryOp_Mul( left: Expr_BinaryOp_Plus( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) right: Expr_Variable( name: c ) ) ) 19: Stmt_Expression( expr: Expr_BinaryOp_Pow( left: Expr_Variable( name: a ) right: Expr_BinaryOp_Pow( left: Expr_Variable( name: b ) right: Expr_Variable( name: c ) ) ) comments: array( 0: // pow is special ) ) 20: Stmt_Expression( expr: Expr_BinaryOp_Pow( left: Expr_BinaryOp_Pow( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) right: Expr_Variable( name: c ) ) ) ) ================================================ FILE: test/code/parser/expr/new.test ================================================ New ----- b(); new $a->b->c(); new $a->b['c'](); // test regression introduces by new dereferencing syntax (new A); ----- array( 0: Stmt_Expression( expr: Expr_New( class: Name( name: A ) args: array( ) ) ) 1: Stmt_Expression( expr: Expr_New( class: Name( name: A ) args: array( 0: Arg( name: null value: Expr_Variable( name: b ) byRef: false unpack: false ) ) ) ) 2: Stmt_Expression( expr: Expr_New( class: Expr_Variable( name: a ) args: array( ) ) comments: array( 0: // class name variations ) ) 3: Stmt_Expression( expr: Expr_New( class: Expr_ArrayDimFetch( var: Expr_Variable( name: a ) dim: Scalar_String( value: b ) ) args: array( ) ) ) 4: Stmt_Expression( expr: Expr_New( class: Expr_StaticPropertyFetch( class: Name( name: A ) name: VarLikeIdentifier( name: b ) ) args: array( ) ) ) 5: Stmt_Expression( expr: Expr_New( class: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) args: array( ) ) comments: array( 0: // DNCR object access ) ) 6: Stmt_Expression( expr: Expr_New( class: Expr_PropertyFetch( var: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) name: Identifier( name: c ) ) args: array( ) ) ) 7: Stmt_Expression( expr: Expr_New( class: Expr_ArrayDimFetch( var: Expr_PropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) dim: Scalar_String( value: c ) ) args: array( ) ) ) 8: Stmt_Expression( expr: Expr_New( class: Name( name: A ) args: array( ) ) comments: array( 0: // test regression introduces by new dereferencing syntax ) ) ) ================================================ FILE: test/code/parser/expr/newDeref.test ================================================ New dereference without parentheses ----- foo; new A()->foo(); new A()::FOO; new A()::foo(); new A()::$foo; new A()[0]; new A()(); new class {}->foo; new class {}->foo(); new class {}::FOO; new class {}::foo(); new class {}::$foo; new class {}[0]; new class {}(); ----- array( 0: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_New( class: Name( name: A ) args: array( ) ) name: Identifier( name: foo ) ) ) 1: Stmt_Expression( expr: Expr_MethodCall( var: Expr_New( class: Name( name: A ) args: array( ) ) name: Identifier( name: foo ) args: array( ) ) ) 2: Stmt_Expression( expr: Expr_ClassConstFetch( class: Expr_New( class: Name( name: A ) args: array( ) ) name: Identifier( name: FOO ) ) ) 3: Stmt_Expression( expr: Expr_StaticCall( class: Expr_New( class: Name( name: A ) args: array( ) ) name: Identifier( name: foo ) args: array( ) ) ) 4: Stmt_Expression( expr: Expr_StaticPropertyFetch( class: Expr_New( class: Name( name: A ) args: array( ) ) name: VarLikeIdentifier( name: foo ) ) ) 5: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_New( class: Name( name: A ) args: array( ) ) dim: Scalar_Int( value: 0 ) ) ) 6: Stmt_Expression( expr: Expr_FuncCall( name: Expr_New( class: Name( name: A ) args: array( ) ) args: array( ) ) ) 7: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_New( class: Stmt_Class( attrGroups: array( ) flags: 0 name: null extends: null implements: array( ) stmts: array( ) ) args: array( ) ) name: Identifier( name: foo ) ) ) 8: Stmt_Expression( expr: Expr_MethodCall( var: Expr_New( class: Stmt_Class( attrGroups: array( ) flags: 0 name: null extends: null implements: array( ) stmts: array( ) ) args: array( ) ) name: Identifier( name: foo ) args: array( ) ) ) 9: Stmt_Expression( expr: Expr_ClassConstFetch( class: Expr_New( class: Stmt_Class( attrGroups: array( ) flags: 0 name: null extends: null implements: array( ) stmts: array( ) ) args: array( ) ) name: Identifier( name: FOO ) ) ) 10: Stmt_Expression( expr: Expr_StaticCall( class: Expr_New( class: Stmt_Class( attrGroups: array( ) flags: 0 name: null extends: null implements: array( ) stmts: array( ) ) args: array( ) ) name: Identifier( name: foo ) args: array( ) ) ) 11: Stmt_Expression( expr: Expr_StaticPropertyFetch( class: Expr_New( class: Stmt_Class( attrGroups: array( ) flags: 0 name: null extends: null implements: array( ) stmts: array( ) ) args: array( ) ) name: VarLikeIdentifier( name: foo ) ) ) 12: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_New( class: Stmt_Class( attrGroups: array( ) flags: 0 name: null extends: null implements: array( ) stmts: array( ) ) args: array( ) ) dim: Scalar_Int( value: 0 ) ) ) 13: Stmt_Expression( expr: Expr_FuncCall( name: Expr_New( class: Stmt_Class( attrGroups: array( ) flags: 0 name: null extends: null implements: array( ) stmts: array( ) ) args: array( ) ) args: array( ) ) ) ) ================================================ FILE: test/code/parser/expr/newWithoutClass.test ================================================ New without a class ----- b; $a?->b($c); new $a?->b; "{$a?->b}"; "$a?->b"; ----- array( 0: Stmt_Expression( expr: Expr_NullsafePropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) ) 1: Stmt_Expression( expr: Expr_NullsafeMethodCall( var: Expr_Variable( name: a ) name: Identifier( name: b ) args: array( 0: Arg( name: null value: Expr_Variable( name: c ) byRef: false unpack: false ) ) ) ) 2: Stmt_Expression( expr: Expr_New( class: Expr_NullsafePropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) args: array( ) ) ) 3: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_NullsafePropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) ) ) ) 4: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_NullsafePropertyFetch( var: Expr_Variable( name: a ) name: Identifier( name: b ) ) ) ) ) ) ================================================ FILE: test/code/parser/expr/pipe.test ================================================ Pipe operator ----- $b |> $c; $a . $b |> $c . $d; $a |> $b == $c; $c == $a |> $b; $a |> (fn($x) => $x) |> (fn($y) => $y); $a |> fn($x) => $x |> fn($y) => $y; ----- Arrow functions on the right hand side of |> must be parenthesized from 7:23 to 7:34 Arrow functions on the right hand side of |> must be parenthesized from 7:7 to 7:34 array( 0: Stmt_Expression( expr: Expr_BinaryOp_Pipe( left: Expr_BinaryOp_Pipe( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) right: Expr_Variable( name: c ) ) ) 1: Stmt_Expression( expr: Expr_BinaryOp_Pipe( left: Expr_BinaryOp_Concat( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) right: Expr_BinaryOp_Concat( left: Expr_Variable( name: c ) right: Expr_Variable( name: d ) ) ) ) 2: Stmt_Expression( expr: Expr_BinaryOp_Equal( left: Expr_BinaryOp_Pipe( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) right: Expr_Variable( name: c ) ) ) 3: Stmt_Expression( expr: Expr_BinaryOp_Equal( left: Expr_Variable( name: c ) right: Expr_BinaryOp_Pipe( left: Expr_Variable( name: a ) right: Expr_Variable( name: b ) ) ) ) 4: Stmt_Expression( expr: Expr_BinaryOp_Pipe( left: Expr_BinaryOp_Pipe( left: Expr_Variable( name: a ) right: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: x ) default: null hooks: array( ) ) ) returnType: null expr: Expr_Variable( name: x ) ) ) right: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: y ) default: null hooks: array( ) ) ) returnType: null expr: Expr_Variable( name: y ) ) ) ) 5: Stmt_Expression( expr: Expr_BinaryOp_Pipe( left: Expr_Variable( name: a ) right: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: x ) default: null hooks: array( ) ) ) returnType: null expr: Expr_BinaryOp_Pipe( left: Expr_Variable( name: x ) right: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: y ) default: null hooks: array( ) ) ) returnType: null expr: Expr_Variable( name: y ) ) ) ) ) ) ) ================================================ FILE: test/code/parser/expr/print.test ================================================ Print ----- bar($a, $b, ); Foo::bar($a, $b, ); new Foo($a, $b, ); unset($a, $b, ); isset($a, $b, ); ----- array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: foo ) args: array( 0: Arg( name: null value: Expr_Variable( name: a ) byRef: false unpack: false ) 1: Arg( name: null value: Expr_Variable( name: b ) byRef: false unpack: false ) ) ) ) 1: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: foo ) name: Identifier( name: bar ) args: array( 0: Arg( name: null value: Expr_Variable( name: a ) byRef: false unpack: false ) 1: Arg( name: null value: Expr_Variable( name: b ) byRef: false unpack: false ) ) ) ) 2: Stmt_Expression( expr: Expr_StaticCall( class: Name( name: Foo ) name: Identifier( name: bar ) args: array( 0: Arg( name: null value: Expr_Variable( name: a ) byRef: false unpack: false ) 1: Arg( name: null value: Expr_Variable( name: b ) byRef: false unpack: false ) ) ) ) 3: Stmt_Expression( expr: Expr_New( class: Name( name: Foo ) args: array( 0: Arg( name: null value: Expr_Variable( name: a ) byRef: false unpack: false ) 1: Arg( name: null value: Expr_Variable( name: b ) byRef: false unpack: false ) ) ) ) 4: Stmt_Unset( vars: array( 0: Expr_Variable( name: a ) 1: Expr_Variable( name: b ) ) ) 5: Stmt_Expression( expr: Expr_Isset( vars: array( 0: Expr_Variable( name: a ) 1: Expr_Variable( name: b ) ) ) ) ) ================================================ FILE: test/code/parser/expr/uvs/constDeref.test ================================================ Dereferencing of constants ----- length; A->length(); A[0]; A[0][1][2]; A::B[0]; A::B[0][1][2]; A::B->length; A::B->length(); A::B::C; A::B::$c; A::B::c(); __FUNCTION__[0]; __FUNCTION__->length; __FUNCIONT__->length(); ----- array( 0: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_ConstFetch( name: Name( name: A ) ) name: Identifier( name: length ) ) ) 1: Stmt_Expression( expr: Expr_MethodCall( var: Expr_ConstFetch( name: Name( name: A ) ) name: Identifier( name: length ) args: array( ) ) ) 2: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_ConstFetch( name: Name( name: A ) ) dim: Scalar_Int( value: 0 ) ) ) 3: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_ArrayDimFetch( var: Expr_ArrayDimFetch( var: Expr_ConstFetch( name: Name( name: A ) ) dim: Scalar_Int( value: 0 ) ) dim: Scalar_Int( value: 1 ) ) dim: Scalar_Int( value: 2 ) ) ) 4: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_ClassConstFetch( class: Name( name: A ) name: Identifier( name: B ) ) dim: Scalar_Int( value: 0 ) ) ) 5: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_ArrayDimFetch( var: Expr_ArrayDimFetch( var: Expr_ClassConstFetch( class: Name( name: A ) name: Identifier( name: B ) ) dim: Scalar_Int( value: 0 ) ) dim: Scalar_Int( value: 1 ) ) dim: Scalar_Int( value: 2 ) ) ) 6: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_ClassConstFetch( class: Name( name: A ) name: Identifier( name: B ) ) name: Identifier( name: length ) ) ) 7: Stmt_Expression( expr: Expr_MethodCall( var: Expr_ClassConstFetch( class: Name( name: A ) name: Identifier( name: B ) ) name: Identifier( name: length ) args: array( ) ) ) 8: Stmt_Expression( expr: Expr_ClassConstFetch( class: Expr_ClassConstFetch( class: Name( name: A ) name: Identifier( name: B ) ) name: Identifier( name: C ) ) ) 9: Stmt_Expression( expr: Expr_StaticPropertyFetch( class: Expr_ClassConstFetch( class: Name( name: A ) name: Identifier( name: B ) ) name: VarLikeIdentifier( name: c ) ) ) 10: Stmt_Expression( expr: Expr_StaticCall( class: Expr_ClassConstFetch( class: Name( name: A ) name: Identifier( name: B ) ) name: Identifier( name: c ) args: array( ) ) ) 11: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Scalar_MagicConst_Function( ) dim: Scalar_Int( value: 0 ) ) ) 12: Stmt_Expression( expr: Expr_PropertyFetch( var: Scalar_MagicConst_Function( ) name: Identifier( name: length ) ) ) 13: Stmt_Expression( expr: Expr_MethodCall( var: Expr_ConstFetch( name: Name( name: __FUNCIONT__ ) ) name: Identifier( name: length ) args: array( ) ) ) ) ================================================ FILE: test/code/parser/expr/uvs/globalNonSimpleVarError.test ================================================ Non-simple variables are forbidden in PHP 7 ----- bar; ----- Syntax error, unexpected T_OBJECT_OPERATOR, expecting ';' from 2:13 to 2:14 array( 0: Stmt_Global( vars: array( 0: Expr_Variable( name: Expr_Variable( name: foo ) ) ) ) 1: Stmt_Expression( expr: Expr_ConstFetch( name: Name( name: bar ) ) ) ) ================================================ FILE: test/code/parser/expr/uvs/indirectCall.test ================================================ UVS indirect calls ----- 'b']->a); isset("str"->a); ----- array( 0: Stmt_Expression( expr: Expr_Isset( vars: array( 0: Expr_ArrayDimFetch( var: Expr_BinaryOp_Plus( left: Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_Int( value: 0 ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Scalar_Int( value: 1 ) byRef: false unpack: false ) ) ) right: Expr_Array( items: array( ) ) ) dim: Scalar_Int( value: 0 ) ) ) ) ) 1: Stmt_Expression( expr: Expr_Isset( vars: array( 0: Expr_PropertyFetch( var: Expr_Array( items: array( 0: ArrayItem( key: Scalar_String( value: a ) value: Scalar_String( value: b ) byRef: false unpack: false ) ) ) name: Identifier( name: a ) ) ) ) ) 2: Stmt_Expression( expr: Expr_Isset( vars: array( 0: Expr_PropertyFetch( var: Scalar_String( value: str ) name: Identifier( name: a ) ) ) ) ) ) ================================================ FILE: test/code/parser/expr/uvs/misc.test ================================================ Uniform variable syntax in PHP 7 (misc) ----- length(); "foo$bar"[0]; "foo$bar"->length(); (clone $obj)->b[0](1); [0, 1][0] = 1; ----- array( 0: Stmt_Expression( expr: Expr_MethodCall( var: Scalar_String( value: string ) name: Identifier( name: length ) args: array( ) ) ) 1: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Scalar_InterpolatedString( parts: array( 0: InterpolatedStringPart( value: foo ) 1: Expr_Variable( name: bar ) ) ) dim: Scalar_Int( value: 0 ) ) ) 2: Stmt_Expression( expr: Expr_MethodCall( var: Scalar_InterpolatedString( parts: array( 0: InterpolatedStringPart( value: foo ) 1: Expr_Variable( name: bar ) ) ) name: Identifier( name: length ) args: array( ) ) ) 3: Stmt_Expression( expr: Expr_FuncCall( name: Expr_ArrayDimFetch( var: Expr_PropertyFetch( var: Expr_Clone( expr: Expr_Variable( name: obj ) ) name: Identifier( name: b ) ) dim: Scalar_Int( value: 0 ) ) args: array( 0: Arg( name: null value: Scalar_Int( value: 1 ) byRef: false unpack: false ) ) ) ) 4: Stmt_Expression( expr: Expr_Assign( var: Expr_ArrayDimFetch( var: Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_Int( value: 0 ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Scalar_Int( value: 1 ) byRef: false unpack: false ) ) ) dim: Scalar_Int( value: 0 ) ) expr: Scalar_Int( value: 1 ) ) ) ) ================================================ FILE: test/code/parser/expr/uvs/new.test ================================================ UVS new expressions ----- className; new Test::$className; new $test::$className; new $weird[0]->foo::$className; ----- array( 0: Stmt_Expression( expr: Expr_New( class: Expr_Variable( name: className ) args: array( ) ) ) 1: Stmt_Expression( expr: Expr_New( class: Expr_ArrayDimFetch( var: Expr_Variable( name: array ) dim: Scalar_String( value: className ) ) args: array( ) ) ) 2: Stmt_Expression( expr: Expr_New( class: Expr_PropertyFetch( var: Expr_Variable( name: obj ) name: Identifier( name: className ) ) args: array( ) ) ) 3: Stmt_Expression( expr: Expr_New( class: Expr_StaticPropertyFetch( class: Name( name: Test ) name: VarLikeIdentifier( name: className ) ) args: array( ) ) ) 4: Stmt_Expression( expr: Expr_New( class: Expr_StaticPropertyFetch( class: Expr_Variable( name: test ) name: VarLikeIdentifier( name: className ) ) args: array( ) ) ) 5: Stmt_Expression( expr: Expr_New( class: Expr_StaticPropertyFetch( class: Expr_PropertyFetch( var: Expr_ArrayDimFetch( var: Expr_Variable( name: weird ) dim: Scalar_Int( value: 0 ) ) name: Identifier( name: foo ) ) name: VarLikeIdentifier( name: className ) ) args: array( ) ) ) ) ================================================ FILE: test/code/parser/expr/uvs/newInstanceofExpr.test ================================================ Arbitrary expressions in new and instanceof ----- c test EOS; b<<B"; "$A[B]"; "$A[0]"; "$A[1234]"; "$A[9223372036854775808]"; "$A[000]"; "$A[0x0]"; "$A[0b0]"; "$A[$B]"; "{$A}"; "{$A['B']}"; "${A}"; "${A['B']}"; "${$A}"; "\{$A}"; "\{ $A }"; "\\{$A}"; "\\{ $A }"; "{$$A}[B]"; "$$A[B]"; "A $B C"; b"$A"; B"$A"; ----- array( 0: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_Variable( name: A ) ) ) ) 1: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_PropertyFetch( var: Expr_Variable( name: A ) name: Identifier( name: B ) ) ) ) ) 2: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Scalar_String( value: B ) ) ) ) ) 3: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Scalar_Int( value: 0 ) ) ) ) ) 4: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Scalar_Int( value: 1234 ) ) ) ) ) 5: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Scalar_String( value: 9223372036854775808 ) ) ) ) ) 6: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Scalar_String( value: 000 ) ) ) ) ) 7: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Scalar_String( value: 0x0 ) ) ) ) ) 8: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Scalar_String( value: 0b0 ) ) ) ) ) 9: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Expr_Variable( name: B ) ) ) ) ) 10: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_Variable( name: A ) ) ) ) 11: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Scalar_String( value: B ) ) ) ) ) 12: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_Variable( name: A ) ) ) ) 13: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Scalar_String( value: B ) ) ) ) ) 14: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_Variable( name: Expr_Variable( name: A ) ) ) ) ) 15: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: InterpolatedStringPart( value: \{ ) 1: Expr_Variable( name: A ) 2: InterpolatedStringPart( value: } ) ) ) ) 16: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: InterpolatedStringPart( value: \{ ) 1: Expr_Variable( name: A ) 2: InterpolatedStringPart( value: } ) ) ) ) 17: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: InterpolatedStringPart( value: \ ) 1: Expr_Variable( name: A ) ) ) ) 18: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: InterpolatedStringPart( value: \{ ) 1: Expr_Variable( name: A ) 2: InterpolatedStringPart( value: } ) ) ) ) 19: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_Variable( name: Expr_Variable( name: A ) ) 1: InterpolatedStringPart( value: [B] ) ) ) ) 20: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: InterpolatedStringPart( value: $ ) 1: Expr_ArrayDimFetch( var: Expr_Variable( name: A ) dim: Scalar_String( value: B ) ) ) ) ) 21: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: InterpolatedStringPart( value: A ) 1: Expr_Variable( name: B ) 2: InterpolatedStringPart( value: C ) ) ) ) 22: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_Variable( name: A ) ) ) ) 23: Stmt_Expression( expr: Scalar_InterpolatedString( parts: array( 0: Expr_Variable( name: A ) ) ) ) ) ================================================ FILE: test/code/parser/scalar/explicitOctal.test ================================================ Explicit octal syntax ----- float overflows // (all are actually the same number, just in different representations) 18446744073709551615; 0xFFFFFFFFFFFFFFFF; 0xEEEEEEEEEEEEEEEE; 01777777777777777777777; 0177777777777777777777787; 0b1111111111111111111111111111111111111111111111111111111111111111; ----- array( 0: Stmt_Expression( expr: Scalar_Float( value: 0 ) ) 1: Stmt_Expression( expr: Scalar_Float( value: 0 ) ) 2: Stmt_Expression( expr: Scalar_Float( value: 0 ) ) 3: Stmt_Expression( expr: Scalar_Float( value: 0 ) ) 4: Stmt_Expression( expr: Scalar_Float( value: 0 ) ) 5: Stmt_Expression( expr: Scalar_Float( value: 0 ) ) 6: Stmt_Expression( expr: Scalar_Float( value: 0 ) ) 7: Stmt_Expression( expr: Scalar_Float( value: 302000000000 ) ) 8: Stmt_Expression( expr: Scalar_Float( value: 3.002E+102 ) ) 9: Stmt_Expression( expr: Scalar_Float( value: INF ) ) 10: Stmt_Expression( expr: Scalar_Float( value: 1.844674407371E+19 ) comments: array( 0: // various integer -> float overflows 1: // (all are actually the same number, just in different representations) ) ) 11: Stmt_Expression( expr: Scalar_Float( value: 1.844674407371E+19 ) ) 12: Stmt_Expression( expr: Scalar_Float( value: 1.7216961135462E+19 ) ) 13: Stmt_Expression( expr: Scalar_Float( value: 1.844674407371E+19 ) ) 14: Stmt_Expression( expr: Scalar_Float( value: 1.844674407371E+19 ) ) 15: Stmt_Expression( expr: Scalar_Float( value: 1.844674407371E+19 ) ) ) ================================================ FILE: test/code/parser/scalar/int.test ================================================ Different integer syntaxes ----- array(); $t->public(); Test::list(); Test::protected(); $t->class; $t->private; Test::TRAIT; Test::FINAL; class Foo { use TraitA, TraitB { TraitA::catch insteadof namespace\TraitB; TraitA::list as foreach; TraitB::throw as protected public; TraitB::self as protected; exit as die; \TraitC::exit as bye; namespace\TraitC::exit as byebye; TraitA:: // /** doc comment */ # catch /* comment */ // comment # comment insteadof TraitB; } } ----- array( 0: Stmt_Class( attrGroups: array( ) flags: 0 name: Identifier( name: Test ) extends: null implements: array( ) stmts: array( 0: Stmt_ClassMethod( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: array ) params: array( ) returnType: null stmts: array( ) ) 1: Stmt_ClassMethod( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: public ) params: array( ) returnType: null stmts: array( ) ) 2: Stmt_ClassMethod( attrGroups: array( ) flags: STATIC (8) byRef: false name: Identifier( name: list ) params: array( ) returnType: null stmts: array( ) ) 3: Stmt_ClassMethod( attrGroups: array( ) flags: STATIC (8) byRef: false name: Identifier( name: protected ) params: array( ) returnType: null stmts: array( ) ) 4: Stmt_Property( attrGroups: array( ) flags: PUBLIC (1) type: null props: array( 0: PropertyItem( name: VarLikeIdentifier( name: class ) default: null ) ) hooks: array( ) ) 5: Stmt_Property( attrGroups: array( ) flags: PUBLIC (1) type: null props: array( 0: PropertyItem( name: VarLikeIdentifier( name: private ) default: null ) ) hooks: array( ) ) 6: Stmt_ClassConst( attrGroups: array( ) flags: 0 type: null consts: array( 0: Const( name: Identifier( name: TRAIT ) value: Scalar_Int( value: 3 ) ) 1: Const( name: Identifier( name: FINAL ) value: Scalar_Int( value: 4 ) ) ) ) 7: Stmt_ClassConst( attrGroups: array( ) flags: 0 type: null consts: array( 0: Const( name: Identifier( name: __CLASS__ ) value: Scalar_Int( value: 1 ) ) 1: Const( name: Identifier( name: __TRAIT__ ) value: Scalar_Int( value: 2 ) ) 2: Const( name: Identifier( name: __FUNCTION__ ) value: Scalar_Int( value: 3 ) ) 3: Const( name: Identifier( name: __METHOD__ ) value: Scalar_Int( value: 4 ) ) 4: Const( name: Identifier( name: __LINE__ ) value: Scalar_Int( value: 5 ) ) 5: Const( name: Identifier( name: __FILE__ ) value: Scalar_Int( value: 6 ) ) 6: Const( name: Identifier( name: __DIR__ ) value: Scalar_Int( value: 7 ) ) 7: Const( name: Identifier( name: __NAMESPACE__ ) value: Scalar_Int( value: 8 ) ) ) ) 8: Stmt_Nop( comments: array( 0: // __halt_compiler does not work ) ) ) ) 1: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: t ) expr: Expr_New( class: Name( name: Test ) args: array( ) ) ) ) 2: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: t ) name: Identifier( name: array ) args: array( ) ) ) 3: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: t ) name: Identifier( name: public ) args: array( ) ) ) 4: Stmt_Expression( expr: Expr_StaticCall( class: Name( name: Test ) name: Identifier( name: list ) args: array( ) ) ) 5: Stmt_Expression( expr: Expr_StaticCall( class: Name( name: Test ) name: Identifier( name: protected ) args: array( ) ) ) 6: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_Variable( name: t ) name: Identifier( name: class ) ) ) 7: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_Variable( name: t ) name: Identifier( name: private ) ) ) 8: Stmt_Expression( expr: Expr_ClassConstFetch( class: Name( name: Test ) name: Identifier( name: TRAIT ) ) ) 9: Stmt_Expression( expr: Expr_ClassConstFetch( class: Name( name: Test ) name: Identifier( name: FINAL ) ) ) 10: Stmt_Class( attrGroups: array( ) flags: 0 name: Identifier( name: Foo ) extends: null implements: array( ) stmts: array( 0: Stmt_TraitUse( traits: array( 0: Name( name: TraitA ) 1: Name( name: TraitB ) ) adaptations: array( 0: Stmt_TraitUseAdaptation_Precedence( trait: Name( name: TraitA ) method: Identifier( name: catch ) insteadof: array( 0: Name_Relative( name: TraitB ) ) ) 1: Stmt_TraitUseAdaptation_Alias( trait: Name( name: TraitA ) method: Identifier( name: list ) newModifier: null newName: Identifier( name: foreach ) ) 2: Stmt_TraitUseAdaptation_Alias( trait: Name( name: TraitB ) method: Identifier( name: throw ) newModifier: PROTECTED (2) newName: Identifier( name: public ) ) 3: Stmt_TraitUseAdaptation_Alias( trait: Name( name: TraitB ) method: Identifier( name: self ) newModifier: PROTECTED (2) newName: null ) 4: Stmt_TraitUseAdaptation_Alias( trait: null method: Identifier( name: exit ) newModifier: null newName: Identifier( name: die ) ) 5: Stmt_TraitUseAdaptation_Alias( trait: Name_FullyQualified( name: TraitC ) method: Identifier( name: exit ) newModifier: null newName: Identifier( name: bye ) ) 6: Stmt_TraitUseAdaptation_Alias( trait: Name_Relative( name: TraitC ) method: Identifier( name: exit ) newModifier: null newName: Identifier( name: byebye ) ) 7: Stmt_TraitUseAdaptation_Precedence( trait: Name( name: TraitA ) method: Identifier( name: catch comments: array( 0: // 1: /** doc comment */ 2: # ) ) insteadof: array( 0: Name( name: TraitB ) ) ) ) ) ) ) ) ================================================ FILE: test/code/parser/stmt/attributes.test ================================================ Attributes ----- 0; $a = #[A12] static function() {}; $b = #[A13] static fn() => 0; ----- array( 0: Stmt_Function( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A1 ) args: array( ) ) 1: Attribute( name: Name( name: A2 ) args: array( ) ) 2: Attribute( name: Name( name: A3 ) args: array( 0: Arg( name: null value: Scalar_Int( value: 0 ) byRef: false unpack: false ) ) ) 3: Attribute( name: Name( name: A4 ) args: array( 0: Arg( name: Identifier( name: x ) value: Scalar_Int( value: 1 ) byRef: false unpack: false ) ) ) ) ) ) byRef: false name: Identifier( name: a ) params: array( ) returnType: null stmts: array( ) ) 1: Stmt_Class( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A5 ) args: array( ) ) ) ) ) flags: 0 name: Identifier( name: C ) extends: null implements: array( ) stmts: array( 0: Stmt_ClassMethod( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A6 ) args: array( ) ) ) ) ) flags: PUBLIC (1) byRef: false name: Identifier( name: m ) params: array( 0: Param( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A7 ) args: array( ) ) ) ) ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: param ) default: null hooks: array( ) ) ) returnType: null stmts: array( ) ) 1: Stmt_Property( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A14 ) args: array( ) ) ) ) ) flags: PUBLIC (1) type: null props: array( 0: PropertyItem( name: VarLikeIdentifier( name: prop ) default: null ) ) hooks: array( ) ) ) ) 2: Stmt_Interface( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A8 ) args: array( ) ) ) ) ) name: Identifier( name: I ) extends: array( ) stmts: array( ) ) 3: Stmt_Trait( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A9 ) args: array( ) ) ) ) ) name: Identifier( name: T ) stmts: array( ) ) 4: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: x ) expr: Expr_Closure( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A10 ) args: array( ) ) ) ) ) static: false byRef: false params: array( ) uses: array( ) returnType: null stmts: array( ) ) ) ) 5: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: y ) expr: Expr_ArrowFunction( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A11 ) args: array( ) ) ) ) ) static: false byRef: false params: array( ) returnType: null expr: Scalar_Int( value: 0 ) ) ) ) 6: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: a ) expr: Expr_Closure( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A12 ) args: array( ) ) ) ) ) static: true byRef: false params: array( ) uses: array( ) returnType: null stmts: array( ) ) ) ) 7: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: b ) expr: Expr_ArrowFunction( attrGroups: array( 0: AttributeGroup( attrs: array( 0: Attribute( name: Name( name: A13 ) args: array( ) ) ) ) ) static: true byRef: false params: array( ) returnType: null expr: Scalar_Int( value: 0 ) ) ) ) ) ================================================ FILE: test/code/parser/stmt/blocklessStatement.test ================================================ Blockless statements for if/for/etc ----- 42; set => $value; } abstract $prop3 { &get; set; } public $prop4 { final get { return 42; } set(string $value) { } } } ----- array( 0: Stmt_Class( attrGroups: array( ) flags: 0 name: Identifier( name: Test ) extends: null implements: array( ) stmts: array( 0: Stmt_Property( attrGroups: array( ) flags: PUBLIC (1) type: null props: array( 0: PropertyItem( name: VarLikeIdentifier( name: prop ) default: null ) ) hooks: array( 0: PropertyHook( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: get ) params: array( ) body: array( 0: Stmt_Return( expr: Scalar_Int( value: 42 ) ) ) ) 1: PropertyHook( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: set ) params: array( ) body: array( 0: Stmt_Echo( exprs: array( 0: Expr_Variable( name: value ) ) ) ) ) ) ) 1: Stmt_Property( attrGroups: array( ) flags: PRIVATE (4) type: null props: array( 0: PropertyItem( name: VarLikeIdentifier( name: prop2 ) default: null ) ) hooks: array( 0: PropertyHook( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: get ) params: array( ) body: Scalar_Int( value: 42 ) ) 1: PropertyHook( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: set ) params: array( ) body: Expr_Variable( name: value ) ) ) ) 2: Stmt_Property( attrGroups: array( ) flags: ABSTRACT (16) type: null props: array( 0: PropertyItem( name: VarLikeIdentifier( name: prop3 ) default: null ) ) hooks: array( 0: PropertyHook( attrGroups: array( ) flags: 0 byRef: true name: Identifier( name: get ) params: array( ) body: null ) 1: PropertyHook( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: set ) params: array( ) body: null ) ) ) 3: Stmt_Property( attrGroups: array( ) flags: PUBLIC (1) type: null props: array( 0: PropertyItem( name: VarLikeIdentifier( name: prop4 ) default: null ) ) hooks: array( 0: PropertyHook( attrGroups: array( ) flags: FINAL (32) byRef: false name: Identifier( name: get ) params: array( ) body: array( 0: Stmt_Return( expr: Scalar_Int( value: 42 ) ) ) ) 1: PropertyHook( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: set ) params: array( 0: Param( attrGroups: array( ) flags: 0 type: Identifier( name: string ) byRef: false variadic: false var: Expr_Variable( name: value ) default: null hooks: array( ) ) ) body: array( ) ) ) ) ) ) ) ----- 42; } } ----- get hook must not have a parameter list from 4:12 to 4:12 array( 0: Stmt_Class( attrGroups: array( ) flags: 0 name: Identifier( name: Test ) extends: null implements: array( ) stmts: array( 0: Stmt_Property( attrGroups: array( ) flags: PUBLIC (1) type: null props: array( 0: PropertyItem( name: VarLikeIdentifier( name: prop ) default: null ) ) hooks: array( 0: PropertyHook( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: get ) params: array( ) body: Scalar_Int( value: 42 ) ) ) ) ) ) ) ----- bar; } } ----- Unknown hook "FOO", expected "get" or "set" from 3:20 to 3:22 array( 0: Stmt_Class( attrGroups: array( ) flags: 0 name: Identifier( name: Test ) extends: null implements: array( ) stmts: array( 0: Stmt_Property( attrGroups: array( ) flags: PUBLIC (1) type: null props: array( 0: PropertyItem( name: VarLikeIdentifier( name: prop ) default: null ) ) hooks: array( 0: PropertyHook( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: FOO ) params: array( ) body: Expr_ConstFetch( name: Name( name: bar ) ) ) ) ) ) ) ) ----- $value; }, public $g = 1 { get => 2; }, final $i, ) {} } ----- array( 0: Stmt_Class( attrGroups: array( ) flags: 0 name: Identifier( name: Point ) extends: null implements: array( ) stmts: array( 0: Stmt_ClassMethod( attrGroups: array( ) flags: PUBLIC (1) byRef: false name: Identifier( name: __construct ) params: array( 0: Param( attrGroups: array( ) flags: PUBLIC (1) type: Identifier( name: float ) byRef: false variadic: false var: Expr_Variable( name: x ) default: Scalar_Float( value: 0 ) hooks: array( ) ) 1: Param( attrGroups: array( ) flags: PROTECTED (2) type: Identifier( name: array ) byRef: false variadic: false var: Expr_Variable( name: y ) default: Expr_Array( items: array( ) ) hooks: array( ) ) 2: Param( attrGroups: array( ) flags: PRIVATE (4) type: Identifier( name: string ) byRef: false variadic: false var: Expr_Variable( name: z ) default: Scalar_String( value: hello ) hooks: array( ) ) 3: Param( attrGroups: array( ) flags: PUBLIC | READONLY (65) type: Identifier( name: int ) byRef: false variadic: false var: Expr_Variable( name: a ) default: Scalar_Int( value: 0 ) hooks: array( ) ) 4: Param( attrGroups: array( ) flags: PUBLIC (1) type: null byRef: false variadic: false var: Expr_Variable( name: h ) default: null hooks: array( 0: PropertyHook( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: set ) params: array( ) body: Expr_Variable( name: value ) ) ) ) 5: Param( attrGroups: array( ) flags: PUBLIC (1) type: null byRef: false variadic: false var: Expr_Variable( name: g ) default: Scalar_Int( value: 1 ) hooks: array( 0: PropertyHook( attrGroups: array( ) flags: 0 byRef: false name: Identifier( name: get ) params: array( ) body: Scalar_Int( value: 2 ) ) ) ) 6: Param( attrGroups: array( ) flags: FINAL (32) type: null byRef: false variadic: false var: Expr_Variable( name: i ) default: null hooks: array( ) ) ) returnType: null stmts: array( ) ) ) ) ) ================================================ FILE: test/code/parser/stmt/class/readonly.test ================================================ Readonly class ----- $foo, "bar" => $bar ]); clone($x, $array); clone($x, $array, $extraParameter, $trailingComma, ); clone(object: $x, withProperties: [ "foo" => $foo, "bar" => $bar ]); clone($x, withProperties: [ "foo" => $foo, "bar" => $bar ]); clone(object: $x); clone(object: $x, [ "foo" => $foo, "bar" => $bar ]); clone(...["object" => $x, "withProperties" => [ "foo" => $foo, "bar" => $bar ]]); clone(...); ----- array( 0: Stmt_Function( attrGroups: array( ) byRef: false name: Identifier( name: clone ) params: array( 0: Param( attrGroups: array( ) flags: 0 type: Identifier( name: object ) byRef: false variadic: false var: Expr_Variable( name: object ) default: null hooks: array( ) ) 1: Param( attrGroups: array( ) flags: 0 type: Identifier( name: array ) byRef: false variadic: false var: Expr_Variable( name: withProperties ) default: Expr_Array( items: array( ) ) hooks: array( ) ) ) returnType: Identifier( name: object ) stmts: array( ) ) 1: Stmt_Expression( expr: Expr_Clone( expr: Expr_Variable( name: x ) ) ) 2: Stmt_Expression( expr: Expr_Clone( expr: Expr_Variable( name: x ) ) ) 3: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: clone ) args: array( 0: Arg( name: null value: Expr_Variable( name: x ) byRef: false unpack: false ) ) ) ) 4: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: clone ) args: array( 0: Arg( name: null value: Expr_Variable( name: x ) byRef: false unpack: false ) 1: Arg( name: null value: Expr_Array( items: array( 0: ArrayItem( key: Scalar_String( value: foo ) value: Expr_Variable( name: foo ) byRef: false unpack: false ) 1: ArrayItem( key: Scalar_String( value: bar ) value: Expr_Variable( name: bar ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) ) ) ) 5: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: clone ) args: array( 0: Arg( name: null value: Expr_Variable( name: x ) byRef: false unpack: false ) 1: Arg( name: null value: Expr_Variable( name: array ) byRef: false unpack: false ) ) ) ) 6: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: clone ) args: array( 0: Arg( name: null value: Expr_Variable( name: x ) byRef: false unpack: false ) 1: Arg( name: null value: Expr_Variable( name: array ) byRef: false unpack: false ) 2: Arg( name: null value: Expr_Variable( name: extraParameter ) byRef: false unpack: false ) 3: Arg( name: null value: Expr_Variable( name: trailingComma ) byRef: false unpack: false ) ) ) ) 7: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: clone ) args: array( 0: Arg( name: Identifier( name: object ) value: Expr_Variable( name: x ) byRef: false unpack: false ) 1: Arg( name: Identifier( name: withProperties ) value: Expr_Array( items: array( 0: ArrayItem( key: Scalar_String( value: foo ) value: Expr_Variable( name: foo ) byRef: false unpack: false ) 1: ArrayItem( key: Scalar_String( value: bar ) value: Expr_Variable( name: bar ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) ) ) ) 8: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: clone ) args: array( 0: Arg( name: null value: Expr_Variable( name: x ) byRef: false unpack: false ) 1: Arg( name: Identifier( name: withProperties ) value: Expr_Array( items: array( 0: ArrayItem( key: Scalar_String( value: foo ) value: Expr_Variable( name: foo ) byRef: false unpack: false ) 1: ArrayItem( key: Scalar_String( value: bar ) value: Expr_Variable( name: bar ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) ) ) ) 9: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: clone ) args: array( 0: Arg( name: Identifier( name: object ) value: Expr_Variable( name: x ) byRef: false unpack: false ) ) ) ) 10: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: clone ) args: array( 0: Arg( name: Identifier( name: object ) value: Expr_Variable( name: x ) byRef: false unpack: false ) 1: Arg( name: null value: Expr_Array( items: array( 0: ArrayItem( key: Scalar_String( value: foo ) value: Expr_Variable( name: foo ) byRef: false unpack: false ) 1: ArrayItem( key: Scalar_String( value: bar ) value: Expr_Variable( name: bar ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) ) ) ) 11: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: clone ) args: array( 0: Arg( name: null value: Expr_Array( items: array( 0: ArrayItem( key: Scalar_String( value: object ) value: Expr_Variable( name: x ) byRef: false unpack: false ) 1: ArrayItem( key: Scalar_String( value: withProperties ) value: Expr_Array( items: array( 0: ArrayItem( key: Scalar_String( value: foo ) value: Expr_Variable( name: foo ) byRef: false unpack: false ) 1: ArrayItem( key: Scalar_String( value: bar ) value: Expr_Variable( name: bar ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) ) ) byRef: false unpack: true ) ) ) ) 12: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: clone ) args: array( 0: VariadicPlaceholder( ) ) ) ) ) ================================================ FILE: test/code/parser/stmt/function/conditional.test ================================================ Conditional function definition ----- 'baz'] ) {} ----- array( 0: Stmt_Function( attrGroups: array( ) byRef: false name: Identifier( name: a ) params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: b ) default: Expr_ConstFetch( name: Name( name: null ) ) hooks: array( ) ) 1: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: c ) default: Scalar_String( value: foo ) hooks: array( ) ) 2: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: d ) default: Expr_ClassConstFetch( class: Name( name: A ) name: Identifier( name: B ) ) hooks: array( ) ) 3: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: f ) default: Expr_UnaryPlus( expr: Scalar_Int( value: 1 ) ) hooks: array( ) ) 4: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: g ) default: Expr_UnaryMinus( expr: Scalar_Float( value: 1 ) ) hooks: array( ) ) 5: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: h ) default: Expr_Array( items: array( ) ) hooks: array( ) ) 6: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: i ) default: Expr_Array( items: array( ) ) hooks: array( ) ) 7: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: j ) default: Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_String( value: foo ) byRef: false unpack: false ) ) ) hooks: array( ) ) 8: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: k ) default: Expr_Array( items: array( 0: ArrayItem( key: null value: Scalar_String( value: foo ) byRef: false unpack: false ) 1: ArrayItem( key: Scalar_String( value: bar ) value: Scalar_String( value: baz ) byRef: false unpack: false ) ) ) hooks: array( ) ) ) returnType: null stmts: array( ) ) ) ================================================ FILE: test/code/parser/stmt/function/disjointNormalFormTypes.test ================================================ DNF types ----- $bar; ----- array( 0: Stmt_Expression( expr: Expr_ArrowFunction( attrGroups: array( ) static: false byRef: false params: array( 0: Param( attrGroups: array( ) flags: 0 type: null byRef: false variadic: false var: Expr_Variable( name: foo ) default: null hooks: array( ) ) ) returnType: null expr: Expr_Variable( name: bar ) ) ) ) ================================================ FILE: test/code/parser/stmt/function/readonlyFunction.test ================================================ readonly function ----- $value; // expressions $data = yield; $data = (yield $value); $data = (yield $key => $value); // yield in language constructs with their own parentheses if (yield $foo); elseif (yield $foo); if (yield $foo): elseif (yield $foo): endif; while (yield $foo); do {} while (yield $foo); switch (yield $foo) {} die(yield $foo); // yield in function calls func(yield $foo); $foo->func(yield $foo); new Foo(yield $foo); yield from $foo; yield from $foo and yield from $bar; yield from $foo + $bar; } ----- array( 0: Stmt_Function( attrGroups: array( ) byRef: false name: Identifier( name: gen ) params: array( ) returnType: null stmts: array( 0: Stmt_Expression( expr: Expr_Yield( key: null value: null ) comments: array( 0: // statements ) ) 1: Stmt_Expression( expr: Expr_Yield( key: null value: Expr_Variable( name: value ) ) ) 2: Stmt_Expression( expr: Expr_Yield( key: Expr_Variable( name: key ) value: Expr_Variable( name: value ) ) ) 3: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: data ) expr: Expr_Yield( key: null value: null ) ) comments: array( 0: // expressions ) ) 4: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: data ) expr: Expr_Yield( key: null value: Expr_Variable( name: value ) ) ) ) 5: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: data ) expr: Expr_Yield( key: Expr_Variable( name: key ) value: Expr_Variable( name: value ) ) ) ) 6: Stmt_If( cond: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) stmts: array( ) elseifs: array( 0: Stmt_ElseIf( cond: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) stmts: array( ) ) ) else: null comments: array( 0: // yield in language constructs with their own parentheses ) ) 7: Stmt_If( cond: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) stmts: array( ) elseifs: array( 0: Stmt_ElseIf( cond: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) stmts: array( ) ) ) else: null ) 8: Stmt_While( cond: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) stmts: array( ) ) 9: Stmt_Do( stmts: array( ) cond: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) ) 10: Stmt_Switch( cond: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) cases: array( ) ) 11: Stmt_Expression( expr: Expr_Exit( expr: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) ) ) 12: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: func ) args: array( 0: Arg( name: null value: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) byRef: false unpack: false ) ) ) comments: array( 0: // yield in function calls ) ) 13: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: foo ) name: Identifier( name: func ) args: array( 0: Arg( name: null value: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) byRef: false unpack: false ) ) ) ) 14: Stmt_Expression( expr: Expr_New( class: Name( name: Foo ) args: array( 0: Arg( name: null value: Expr_Yield( key: null value: Expr_Variable( name: foo ) ) byRef: false unpack: false ) ) ) ) 15: Stmt_Expression( expr: Expr_YieldFrom( expr: Expr_Variable( name: foo ) ) ) 16: Stmt_Expression( expr: Expr_BinaryOp_LogicalAnd( left: Expr_YieldFrom( expr: Expr_Variable( name: foo ) ) right: Expr_YieldFrom( expr: Expr_Variable( name: bar ) ) ) ) 17: Stmt_Expression( expr: Expr_YieldFrom( expr: Expr_BinaryOp_Plus( left: Expr_Variable( name: foo ) right: Expr_Variable( name: bar ) ) ) ) ) ) ) ================================================ FILE: test/code/parser/stmt/generator/yieldPrecedence.test ================================================ Yield operator precedence ----- "a" . "b"; yield "k" => "a" or die; var_dump([yield "k" => "a" . "b"]); yield yield "k1" => yield "k2" => "a" . "b"; yield yield "k1" => (yield "k2") => "a" . "b"; var_dump([yield "k1" => yield "k2" => "a" . "b"]); var_dump([yield "k1" => (yield "k2") => "a" . "b"]); } ----- array( 0: Stmt_Function( attrGroups: array( ) byRef: false name: Identifier( name: gen ) params: array( ) returnType: null stmts: array( 0: Stmt_Expression( expr: Expr_Yield( key: null value: Expr_BinaryOp_Concat( left: Scalar_String( value: a ) right: Scalar_String( value: b ) ) ) ) 1: Stmt_Expression( expr: Expr_BinaryOp_LogicalOr( left: Expr_Yield( key: null value: Scalar_String( value: a ) ) right: Expr_Exit( expr: null ) ) ) 2: Stmt_Expression( expr: Expr_Yield( key: Scalar_String( value: k ) value: Expr_BinaryOp_Concat( left: Scalar_String( value: a ) right: Scalar_String( value: b ) ) ) ) 3: Stmt_Expression( expr: Expr_BinaryOp_LogicalOr( left: Expr_Yield( key: Scalar_String( value: k ) value: Scalar_String( value: a ) ) right: Expr_Exit( expr: null ) ) ) 4: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: var_dump ) args: array( 0: Arg( name: null value: Expr_Array( items: array( 0: ArrayItem( key: null value: Expr_Yield( key: Scalar_String( value: k ) value: Expr_BinaryOp_Concat( left: Scalar_String( value: a ) right: Scalar_String( value: b ) ) ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) ) ) ) 5: Stmt_Expression( expr: Expr_Yield( key: null value: Expr_Yield( key: Scalar_String( value: k1 ) value: Expr_Yield( key: Scalar_String( value: k2 ) value: Expr_BinaryOp_Concat( left: Scalar_String( value: a ) right: Scalar_String( value: b ) ) ) ) ) ) 6: Stmt_Expression( expr: Expr_Yield( key: Expr_Yield( key: Scalar_String( value: k1 ) value: Expr_Yield( key: null value: Scalar_String( value: k2 ) ) ) value: Expr_BinaryOp_Concat( left: Scalar_String( value: a ) right: Scalar_String( value: b ) ) ) ) 7: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: var_dump ) args: array( 0: Arg( name: null value: Expr_Array( items: array( 0: ArrayItem( key: null value: Expr_Yield( key: Scalar_String( value: k1 ) value: Expr_Yield( key: Scalar_String( value: k2 ) value: Expr_BinaryOp_Concat( left: Scalar_String( value: a ) right: Scalar_String( value: b ) ) ) ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) ) ) ) 8: Stmt_Expression( expr: Expr_FuncCall( name: Name( name: var_dump ) args: array( 0: Arg( name: null value: Expr_Array( items: array( 0: ArrayItem( key: Expr_Yield( key: Scalar_String( value: k1 ) value: Expr_Yield( key: null value: Scalar_String( value: k2 ) ) ) value: Expr_BinaryOp_Concat( left: Scalar_String( value: a ) right: Scalar_String( value: b ) ) byRef: false unpack: false ) ) ) byRef: false unpack: false ) ) ) ) ) ) ) ================================================ FILE: test/code/parser/stmt/generator/yieldUnaryPrecedence.test ================================================ Yield with unary operator argument ----- Hallo World! ----- array( 0: Stmt_Expression( expr: Expr_Variable( name: a ) ) 1: Stmt_HaltCompiler( remaining: Hallo World! ) ) ----- #!/usr/bin/env php ----- array( 0: Stmt_InlineHTML( value: #!/usr/bin/env php ) 1: Stmt_Echo( exprs: array( 0: Scalar_String( value: foobar ) ) ) 2: Stmt_InlineHTML( value: #!/usr/bin/env php ) ) ================================================ FILE: test/code/parser/stmt/if.test ================================================ If/Elseif/Else ----- B $c) {} foreach ($a as $b => &$c) {} foreach ($a as list($a, $b)) {} foreach ($a as $a => list($b, , $c)) {} // foreach on expression foreach (array() as $b) {} // alternative syntax foreach ($a as $b): endforeach; ----- array( 0: Stmt_Foreach( expr: Expr_Variable( name: a ) keyVar: null byRef: false valueVar: Expr_Variable( name: b ) stmts: array( ) comments: array( 0: // foreach on variable ) ) 1: Stmt_Foreach( expr: Expr_Variable( name: a ) keyVar: null byRef: true valueVar: Expr_Variable( name: b ) stmts: array( ) ) 2: Stmt_Foreach( expr: Expr_Variable( name: a ) keyVar: Expr_Variable( name: b ) byRef: false valueVar: Expr_Variable( name: c ) stmts: array( ) ) 3: Stmt_Foreach( expr: Expr_Variable( name: a ) keyVar: Expr_Variable( name: b ) byRef: true valueVar: Expr_Variable( name: c ) stmts: array( ) ) 4: Stmt_Foreach( expr: Expr_Variable( name: a ) keyVar: null byRef: false valueVar: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: a ) byRef: false unpack: false ) 1: ArrayItem( key: null value: Expr_Variable( name: b ) byRef: false unpack: false ) ) ) stmts: array( ) ) 5: Stmt_Foreach( expr: Expr_Variable( name: a ) keyVar: Expr_Variable( name: a ) byRef: false valueVar: Expr_List( items: array( 0: ArrayItem( key: null value: Expr_Variable( name: b ) byRef: false unpack: false ) 1: null 2: ArrayItem( key: null value: Expr_Variable( name: c ) byRef: false unpack: false ) ) ) stmts: array( ) ) 6: Stmt_Foreach( expr: Expr_Array( items: array( ) ) keyVar: null byRef: false valueVar: Expr_Variable( name: b ) stmts: array( ) comments: array( 0: // foreach on expression ) ) 7: Stmt_Foreach( expr: Expr_Variable( name: a ) keyVar: null byRef: false valueVar: Expr_Variable( name: b ) stmts: array( ) comments: array( 0: // alternative syntax ) ) ) ================================================ FILE: test/code/parser/stmt/loop/while.test ================================================ While loop ----- Hi! ----- array( 0: Stmt_Declare( declares: array( 0: DeclareItem( key: Identifier( name: A ) value: Scalar_String( value: B ) ) ) stmts: null ) 1: Stmt_Namespace( name: Name( name: B ) stmts: array( ) ) 2: Stmt_HaltCompiler( remaining: Hi! ) ) ----- a = $a; } }; new readonly class {}; ----- new class { }; new class extends A implements B, C { }; new class($a) extends A { private $a; public function __construct($a) { $this->a = $a; } }; new readonly class { }; ================================================ FILE: test/code/prettyPrinter/expr/arrayDestructuring.test ================================================ Array destructuring ----- $b, 'b' => $a] = $baz; ----- [$a, $b] = [$c, $d]; [, $a, , , $b, ] = $foo; [, [[$a]], $b] = $bar; ['a' => $b, 'b' => $a] = $baz; ================================================ FILE: test/code/prettyPrinter/expr/arraySpread.test ================================================ Array spread ----- $a; fn($x = 42) => $x; fn(&$x) => $x; fn&($x) => $x; static fn($x, ...$rest) => $rest; fn(): int => $x; fn($a, $b) => $a and $b; fn($a, $b) => $a && $b; ----- fn($a) => $a; fn($x = 42) => $x; fn(&$x) => $x; fn&($x) => $x; static fn($x, ...$rest) => $rest; fn(): int => $x; fn($a, $b) => $a and $b; fn($a, $b) => $a && $b; ================================================ FILE: test/code/prettyPrinter/expr/call.test ================================================ Calls ----- d} STR; call( <<d} STR; call(<<foo(...); A::foo(...); ----- foo(...); $this->foo(...); A::foo(...); ================================================ FILE: test/code/prettyPrinter/expr/include.test ================================================ Include ----- 'Foo', // Comment 2 => 'Bar', default => 'Foo', }; ----- echo match (1) { 0, 1 => 'Foo', // Comment 2 => 'Bar', default => 'Foo', }; ================================================ FILE: test/code/prettyPrinter/expr/namedArgs.test ================================================ Named arguments ----- property; new MyClass()->method(); new MyClass()(); new MyClass()[0]; new class {}::CONSTANT; new class {}::$staticProperty; new class {}::staticMethod(); new class {}->property; new class {}->method(); new class {}(); new class {}[0]; ----- !!version=8.4 new MyClass()::CONSTANT; new MyClass()::$staticProperty; new MyClass()::staticMethod(); new MyClass()->property; new MyClass()->method(); new MyClass()(); new MyClass()[0]; new class { }::CONSTANT; new class { }::$staticProperty; new class { }::staticMethod(); new class { }->property; new class { }->method(); new class { }(); new class { }[0]; ----- property; new MyClass()->method(); new MyClass()(); new MyClass()[0]; new class {}::CONSTANT; new class {}::$staticProperty; new class {}::staticMethod(); new class {}->property; new class {}->method(); new class {}(); new class {}[0]; ----- !!version=8.3 (new MyClass())::CONSTANT; (new MyClass())::$staticProperty; (new MyClass())::staticMethod(); (new MyClass())->property; (new MyClass())->method(); (new MyClass())(); (new MyClass())[0]; (new class { })::CONSTANT; (new class { })::$staticProperty; (new class { })::staticMethod(); (new class { })->property; (new class { })->method(); (new class { })(); (new class { })[0]; ================================================ FILE: test/code/prettyPrinter/expr/newVariable.test ================================================ Parentheses for complex new/instanceof expressions ----- y); new ((x)::$y); $x instanceof ('a' . 'b'); $x instanceof ($y++); ----- new ('a' . 'b')(); new (x)(); new (foo())(); new ('foo')(); new (x[0])(); new (x->y)(); new ((x)::$y)(); $x instanceof ('a' . 'b'); $x instanceof ($y++); ================================================ FILE: test/code/prettyPrinter/expr/nullsafe.test ================================================ Nullsafe operator ----- b; $a?->b($c); $a?->b?->c; $a?->b($c)?->d; $a?->b($c)(); new $a?->b; "{$a?->b}"; "$a?->b"; ----- $a?->b; $a?->b($c); $a?->b?->c; $a?->b($c)?->d; $a?->b($c)(); new $a?->b(); "{$a?->b}"; "{$a?->b}"; ================================================ FILE: test/code/prettyPrinter/expr/numbers.test ================================================ Number literals ----- > $b; $a < $b; $a <= $b; $a > $b; $a >= $b; $a == $b; $a != $b; $a <> $b; $a === $b; $a !== $b; $a <=> $b; $a & $b; $a ^ $b; $a | $b; $a && $b; $a || $b; $a ? $b : $c; $a ?: $c; $a ?? $c; $a = $b; $a **= $b; $a ??= $c; $a *= $b; $a /= $b; $a %= $b; $a += $b; $a -= $b; $a .= $b; $a <<= $b; $a >>= $b; $a &= $b; $a ^= $b; $a |= $b; $a =& $b; $a and $b; $a xor $b; $a or $b; $a instanceof Foo; $a instanceof $b; ----- $a ** $b; ++$a; --$a; $a++; $a--; @$a; ~$a; -$a; +$a; (int) $a; (int) $a; (float) $a; (double) $a; (real) $a; (float) $a; (double) $a; (real) $a; (string) $a; (string) $a; (array) $a; (object) $a; (bool) $a; (bool) $a; (unset) $a; $a * $b; $a / $b; $a % $b; $a + $b; $a - $b; $a . $b; $a << $b; $a >> $b; $a < $b; $a <= $b; $a > $b; $a >= $b; $a == $b; $a != $b; $a != $b; $a === $b; $a !== $b; $a <=> $b; $a & $b; $a ^ $b; $a | $b; $a && $b; $a || $b; $a ? $b : $c; $a ?: $c; $a ?? $c; $a = $b; $a **= $b; $a ??= $c; $a *= $b; $a /= $b; $a %= $b; $a += $b; $a -= $b; $a .= $b; $a <<= $b; $a >>= $b; $a &= $b; $a ^= $b; $a |= $b; $a =& $b; $a and $b; $a xor $b; $a or $b; $a instanceof Foo; $a instanceof $b; ================================================ FILE: test/code/prettyPrinter/expr/parentheses.test ================================================ Pretty printer generates least-parentheses output ----- 0) > (1 < 0); ++$a + $b; $a + $b++; $a ** $b ** $c; ($a ** $b) ** $c; -1 ** 2; yield from $a and yield from $b; yield from ($a and yield from $b); print ($a and print $b); clone ($a + $b); (throw $a) + $b; -(-$a); +(+$a); -(--$a); +(++$a); -(--$a)**$b; +(++$a)**$b; !$a = $b; ++$a ** $b; $a ** $b++; $a . ($b = $c) . $d; !($a = $b) || $c; (fn() => $a) || $b; ($a = $b and $c) + $d; $a ** ($b instanceof $c); ($a = $b) instanceof $c; [$a and $b => $c]; // TODO: This prints redundant parentheses [include $a => $c]; ----- echo 'abc' . 'cde' . 'fgh'; echo 'abc' . ('cde' . 'fgh'); echo 'abc' . 1 + 2 . 'fgh'; echo 'abc' . (1 + 2) . 'fgh'; echo 1 * 2 + 3 / 4 % 5 . 6; echo 1 * (2 + 3) / (4 % (5 . 6)); $a = $b = $c = $d = $f && true; ($a = $b = $c = $d = $f) && true; $a = $b = $c = $d = $f and true; $a = $b = $c = $d = ($f and true); (($a ? $b : $c) ? $d : $e) ? $f : $g; $a ? $b : ($c ? $d : ($e ? $f : $g)); $a ? $b ? $c : $d : $f; $a === $b ? $c : $d; $a ?? $b ?? $c; ($a ?? $b) ?? $c; $a ?? ($b ? $c : $d); $a || ($b ?? $c); (1 > 0) > (1 < 0); ++$a + $b; $a + $b++; $a ** $b ** $c; ($a ** $b) ** $c; -1 ** 2; yield from $a and yield from $b; yield from ($a and yield from $b); print ($a and print $b); clone ($a + $b); (throw $a) + $b; -(-$a); +(+$a); -(--$a); +(++$a); -(--$a ** $b); +(++$a ** $b); !$a = $b; ++$a ** $b; $a ** $b++; $a . ($b = $c) . $d; !($a = $b) || $c; (fn() => $a) || $b; ($a = $b and $c) + $d; $a ** ($b instanceof $c); ($a = $b) instanceof $c; [$a and $b => $c]; // TODO: This prints redundant parentheses [(include $a) => $c]; ================================================ FILE: test/code/prettyPrinter/expr/pipe.test ================================================ Pipe operator ----- $b |> $c; $a . $b |> $c . $d; $a |> $b == $c; $c == $a |> $b; ($a == $b) |> ($c == $d); $a . ($b |> $c) . $d; $a |> (fn($x) => $x) |> (fn($y) => $y) |> $b; (fn($x) => $x) |> $y; fn($x) => $x |> $y; ----- $a |> $b |> $c; $a . $b |> $c . $d; $a |> $b == $c; $c == $a |> $b; ($a == $b) |> ($c == $d); $a . ($b |> $c) . $d; $a |> (fn($x) => $x) |> (fn($y) => $y) |> $b; (fn($x) => $x) |> $y; fn($x) => $x |> $y; ================================================ FILE: test/code/prettyPrinter/expr/shortArraySyntax.test ================================================ Short array syntax ----- 'b', 'c' => 'd']; ----- []; array(1, 2, 3); ['a' => 'b', 'c' => 'd']; ================================================ FILE: test/code/prettyPrinter/expr/stringEscaping.test ================================================ Escape sequences in double-quoted strings ----- b)(); (A::$b)(); ('a' . 'b')::X; (A)::X; (A)::$x; (A)::x(); ----- (function () { })(); array('a', 'b')()(); A::$b::$c; $A::$b[$c](); $A::{$b[$c]}(); A::${$b}[$c](); ($a->b)(); (A::$b)(); ('a' . 'b')::X; (A)::X; (A)::$x; (A)::x(); ================================================ FILE: test/code/prettyPrinter/expr/variables.test ================================================ Variables ----- b; $a->b(); $a->b($c); $a->$b(); $a->{$b}(); $a->$b[$c](); $$a->b; $a[$b]; $a[$b](); $$a[$b]; $a::B; $a::$b; $a::b(); $a::b($c); $a::$b(); $a::$b[$c]; $a::$b[$c]($d); $a::{$b[$c]}($d); $a::{$b->c}(); A::$$b[$c](); a(); $a(); $a()[$b]; $a->b()[$c]; $a::$b()[$c]; (new A)->b; (new A())->b(); (new $$a)[$b]; (new $a->b)->c; global $a, $$a; ----- $a; ${$a}; ${$a}; $a->b; $a->b(); $a->b($c); $a->{$b}(); $a->{$b}(); $a->{$b}[$c](); ${$a}->b; $a[$b]; $a[$b](); ${$a}[$b]; $a::B; $a::$b; $a::b(); $a::b($c); $a::$b(); $a::$b[$c]; $a::$b[$c]($d); $a::{$b[$c]}($d); $a::{$b->c}(); A::${$b}[$c](); a(); $a(); $a()[$b]; $a->b()[$c]; $a::$b()[$c]; (new A())->b; (new A())->b(); (new ${$a}())[$b]; (new $a->b())->c; global $a, ${$a}; ================================================ FILE: test/code/prettyPrinter/expr/yield.test ================================================ Yield ----- $b; $a = yield; $a = yield $b; $a = yield $b => $c; yield from $a; $a = yield from $b; (yield $a) + $b; (yield from $a) + $b; [yield $a => $b]; [(yield $a) => $b]; [$a + (yield $b) => $c]; yield yield $a => $b; yield (yield $a) => $b; match ($x) { yield $a, (yield $b) => $c, }; yield -$a; (yield) - $a; yield * $a; } ----- function gen() { yield; yield $a; yield $a => $b; $a = yield; $a = yield $b; $a = yield $b => $c; yield from $a; $a = yield from $b; (yield $a) + $b; (yield from $a) + $b; [yield $a => $b]; [(yield $a) => $b]; [$a + (yield $b) => $c]; yield yield $a => $b; yield (yield $a) => $b; match ($x) { yield $a, (yield $b) => $c, }; yield -$a; (yield) - $a; (yield) * $a; } ----- $b; $a = yield; $a = yield $b; $a = yield $b => $c; yield from $a; $a = yield from $b; (yield $a) + $b; (yield from $a) + $b; [yield $a => $b]; [(yield $a) => $b]; [$a + (yield $b) => $c]; yield yield $a => $b; yield (yield $a) => $b; match ($x) { yield $a, (yield $b) => $c, }; yield -$a; (yield) - $a; yield * $a; } ----- !!version=5.6,parserVersion=8.0 function gen() { yield; (yield $a); (yield $a => $b); $a = yield; $a = (yield $b); $a = (yield $b => $c); yield from $a; $a = yield from $b; (yield $a) + $b; (yield from $a) + $b; [(yield $a => $b)]; [(yield $a) => $b]; [$a + (yield $b) => $c]; (yield (yield $a => $b)); (yield (yield $a) => $b); match ($x) { (yield $a), (yield $b) => $c, }; (yield -$a); (yield) - $a; (yield) * $a; } ================================================ FILE: test/code/prettyPrinter/indent.test ================================================ Indentation ----- HTML ----- HTML ----- HTML HTML ----- HTML HTML ----- HTML HTML HTML ----- HTML HTML HTML ----- HTMLHTML ----- HTMLHTML ----- @@{ "\r\r\n" }@@Test ----- @@{ "\n\n" }@@Test ================================================ FILE: test/code/prettyPrinter/nestedInlineHTML.test ================================================ InlineHTML node nested inside other code ----- Test Test 0; new #[A13] class {}; ----- #[A1, A2, A3(0), A4(x: 1)] function a() { } #[A5] class C { #[A6] public function m( #[A7] $param ) { } #[A12] public $prop; } #[A8] interface I { } #[A9] trait T { } $x = #[A10] function () { }; $y = #[A11] fn() => 0; new #[A13] class { }; ----- a = 'bar'; echo 'test'; } protected function baz() {} public function foo() {} abstract static function bar() {} } trait Bar { function test() { } } ----- class Foo extends Bar implements ABC, \DEF, namespace\GHI { var $a = 'foo'; private $b = 'bar'; static $c = 'baz'; function test() { $this->a = 'bar'; echo 'test'; } protected function baz() { } public function foo() { } abstract static function bar() { } } trait Bar { function test() { } } ================================================ FILE: test/code/prettyPrinter/stmt/class_const.test ================================================ Class constants ----- $val) { } foreach ($arr as $key => &$val) { } ----- foreach ($arr as $val) { } foreach ($arr as &$val) { } foreach ($arr as $key => $val) { } foreach ($arr as $key => &$val) { } ================================================ FILE: test/code/prettyPrinter/stmt/function_signatures.test ================================================ Function signatures ----- 42; ----- class Test { function test( // Comment $param ) { } } function test( // Comment $param ) { } function ( // Comment $param ) { }; fn( // Comment $param ) => 42; ----- 42; ----- !!version=8.0 class Test { function test( // Comment $param, ) { } } function test( // Comment $param, ) { } function ( // Comment $param, ) { }; fn( // Comment $param, ) => 42; ================================================ FILE: test/code/prettyPrinter/stmt/properties.test ================================================ Class properties ----- prop + 1; } set { $this->prop = $value - 1; } } public $prop = 1 { #[Attr] &get => $this->prop; final set($value) => $value - 1; } abstract public $prop { get; set; } // TODO: Force multiline for hooks? public function __construct( public $foo { get => 42; set => 123; }, public $bar ) {} } ----- class Test { public int $prop { get { return $this->prop + 1; } set { $this->prop = $value - 1; } } public $prop = 1 { #[Attr] &get => $this->prop; final set($value) => $value - 1; } abstract public $prop { get; set; } // TODO: Force multiline for hooks? public function __construct(public $foo { get => 42; set => 123; }, public $bar) { } } ================================================ FILE: test/code/prettyPrinter/stmt/property_promotion.test ================================================ Property promotion ----- $code) { if (false !== strpos($code, '@@{')) { // Skip tests with evaluate segments continue; } list($name, $tests) = $testParser->parseTest($code, 2); $newTests = []; foreach ($tests as list($modeLine, list($input, $expected))) { $modes = $codeParsingTest->parseModeLine($modeLine); $parser = $codeParsingTest->createParser($modes['version'] ?? null); list(, $output) = $codeParsingTest->getParseOutput($parser, $input, $modes); $newTests[] = [$modeLine, [$input, $output]]; } $newCode = $testParser->reconstructTest($name, $newTests); file_put_contents($fileName, $newCode); } ================================================ FILE: test_old/run-php-src.sh ================================================ VERSION=$1 if [[ ! -f php-$VERSION.tar.gz ]]; then wget -q https://github.com/php/php-src/archive/php-$VERSION.tar.gz fi rm -rf ./data/php-src mkdir -p ./data/php-src tar -xzf ./php-$VERSION.tar.gz -C ./data/php-src --strip-components=1 php test_old/run.php --verbose --no-progress --php-version=$VERSION PHP ./data/php-src ================================================ FILE: test_old/run.php ================================================ true, '--verbose' => true, '--php-version' => true, ]; $options = array(); $arguments = array(); // remove script name from argv array_shift($argv); foreach ($argv as $arg) { if ('-' === $arg[0]) { $parts = explode('=', $arg); $name = $parts[0]; if (!isset($allowedOptions[$name])) { showHelp("Unknown option \"$name\""); } $options[$name] = $parts[1] ?? true; } else { $arguments[] = $arg; } } if (count($arguments) !== 2) { showHelp('Too few arguments passed!'); } $showProgress = !isset($options['--no-progress']); $verbose = isset($options['--verbose']); $phpVersion = $options['--php-version'] ?? '8.0'; $testType = $arguments[0]; $dir = $arguments[1]; require_once __DIR__ . '/../vendor/autoload.php'; switch ($testType) { case 'Symfony': $fileFilter = function($path) { if (!preg_match('~\.php$~', $path)) { return false; } if (preg_match('~(?: # invalid php code dependency-injection.Tests.Fixtures.xml.xml_with_wrong_ext # difference in nop statement | framework-bundle.Resources.views.Form.choice_widget_options\.html # difference due to INF | yaml.Tests.InlineTest )\.php$~x', $path)) { return false; } return true; }; $codeExtractor = function($file, $code) { return $code; }; break; case 'PHP': $fileFilter = function($path) { return preg_match('~\.phpt$~', $path); }; $codeExtractor = function($file, $code) { if (preg_match('~(?: # skeleton files ext.gmp.tests.001 | ext.skeleton.tests.00\d # multibyte encoded files | ext.mbstring.tests.zend_multibyte-01 | Zend.tests.multibyte.multibyte_encoding_001 | Zend.tests.multibyte.multibyte_encoding_004 | Zend.tests.multibyte.multibyte_encoding_005 # invalid code due to missing WS after opening tag | tests.run-test.bug75042-3 # contains invalid chars, which we treat as parse error | Zend.tests.warning_during_heredoc_scan_ahead # pretty print differences due to negative LNumbers | Zend.tests.neg_num_string | Zend.tests.numeric_strings.neg_num_string | Zend.tests.bug72918 # pretty print difference due to nop statements | ext.mbstring.tests.htmlent | ext.standard.tests.file.fread_basic # its too hard to emulate these on old PHP versions | Zend.tests.flexible-heredoc-complex-test[1-4] # whitespace in namespaced name | Zend.tests.bug55086 | Zend.tests.grammar.regression_010 # not worth emulating on old PHP versions | Zend.tests.type_declarations.intersection_types.parsing_comment # comments in property fetch syntax, not emulated on old PHP versions | Zend.tests.gh14961 # harmless pretty print difference for clone($x, ) | Zend.tests.clone.ast )\.phpt$~x', $file)) { return null; } if (!preg_match('~--FILE--\s*(.*?)\n--[A-Z]+--~s', $code, $matches)) { return null; } if (preg_match('~--EXPECT(?:F|REGEX)?--\s*(?:Parse|Fatal) error~', $code)) { return null; } return $matches[1]; }; break; default: showHelp('Test type must be one of: PHP or Symfony'); } $parser = (new PhpParser\ParserFactory())->createForVersion(PhpParser\PhpVersion::fromString($phpVersion)); $prettyPrinter = new PhpParser\PrettyPrinter\Standard; $nodeDumper = new PhpParser\NodeDumper; $cloningTraverser = new PhpParser\NodeTraverser; $cloningTraverser->addVisitor(new PhpParser\NodeVisitor\CloningVisitor); $parseFail = $fpppFail = $ppFail = $compareFail = $count = 0; $readTime = $parseTime = $cloneTime = 0; $fpppTime = $ppTime = $reparseTime = $compareTime = 0; $totalStartTime = microtime(true); foreach (new RecursiveIteratorIterator( new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { if (!$fileFilter($file)) { continue; } $startTime = microtime(true); $origCode = file_get_contents($file); $readTime += microtime(true) - $startTime; if (null === $origCode = $codeExtractor($file, $origCode)) { continue; } set_time_limit(10); ++$count; if ($showProgress) { echo substr(str_pad('Testing file ' . $count . ': ' . substr($file, strlen($dir)), 79), 0, 79), "\r"; } try { $startTime = microtime(true); $origStmts = $parser->parse($origCode); $parseTime += microtime(true) - $startTime; $origTokens = $parser->getTokens(); $startTime = microtime(true); $stmts = $cloningTraverser->traverse($origStmts); $cloneTime += microtime(true) - $startTime; $startTime = microtime(true); $code = $prettyPrinter->printFormatPreserving($stmts, $origStmts, $origTokens); $fpppTime += microtime(true) - $startTime; if ($code !== $origCode) { echo $file, ":\n Result of format-preserving pretty-print differs\n"; if ($verbose) { echo "FPPP output:\n=====\n$code\n=====\n\n"; } ++$fpppFail; } $startTime = microtime(true); $code = "prettyPrint($stmts); $ppTime += microtime(true) - $startTime; try { $startTime = microtime(true); $ppStmts = $parser->parse($code); $reparseTime += microtime(true) - $startTime; $startTime = microtime(true); $same = $nodeDumper->dump($stmts) == $nodeDumper->dump($ppStmts); $compareTime += microtime(true) - $startTime; if (!$same) { echo $file, ":\n Result of initial parse and parse after pretty print differ\n"; if ($verbose) { echo "Pretty printer output:\n=====\n$code\n=====\n\n"; } ++$compareFail; } } catch (PhpParser\Error $e) { echo $file, ":\n Parse of pretty print failed with message: {$e->getMessage()}\n"; if ($verbose) { echo "Pretty printer output:\n=====\n$code\n=====\n\n"; } ++$ppFail; } } catch (PhpParser\Error $e) { echo $file, ":\n Parse failed with message: {$e->getMessage()}\n"; ++$parseFail; } catch (Throwable $e) { echo $file, ":\n Unknown error occurred: $e\n"; } } if (0 === $parseFail && 0 === $ppFail && 0 === $compareFail) { $exit = 0; echo "\n\n", 'All tests passed.', "\n"; } else { $exit = 1; echo "\n\n", '==========', "\n\n", 'There were: ', "\n"; if (0 !== $parseFail) { echo ' ', $parseFail, ' parse failures.', "\n"; } if (0 !== $ppFail) { echo ' ', $ppFail, ' pretty print failures.', "\n"; } if (0 !== $fpppFail) { echo ' ', $fpppFail, ' FPPP failures.', "\n"; } if (0 !== $compareFail) { echo ' ', $compareFail, ' compare failures.', "\n"; } } echo "\n", 'Tested files: ', $count, "\n", "\n", 'Reading files took: ', $readTime, "\n", 'Parsing took: ', $parseTime, "\n", 'Cloning took: ', $cloneTime, "\n", 'FPPP took: ', $fpppTime, "\n", 'Pretty printing took: ', $ppTime, "\n", 'Reparsing took: ', $reparseTime, "\n", 'Comparing took: ', $compareTime, "\n", "\n", 'Total time: ', microtime(true) - $totalStartTime, "\n", 'Maximum memory usage: ', memory_get_peak_usage(true), "\n"; exit($exit); ================================================ FILE: tools/composer.json ================================================ { "require": { "friendsofphp/php-cs-fixer": "^3.10", "phpstan/phpstan": "^2.0" } } ================================================ FILE: tools/fuzzing/generateCorpus.php ================================================ $code) { list($_name, $tests) = $testParser->parseTest($code, 2); foreach ($tests as list($_modeLine, list($input, $_expected))) { $path = $corpusDir . '/' . md5($input) . '.txt'; file_put_contents($path, $input); } } } ================================================ FILE: tools/fuzzing/php.dict ================================================ "" "__class__" "__dir__" "__file__" "__function__" "__halt_compiler" "__line__" "__method__" "__namespace__" "__trait__" "abstract" "array" "as" "binary" "bool" "boolean" "break" "callable" "case" "catch" "class" "clone" "const" "continue" "declare" "default" "die" "do" "double" "echo" "else" "elseif" "empty" "enddeclare" "endfor" "endforeach" "endif" "endswitch" "endwhile" "eval" "exit" "extends" "final" "finally" "float" "fn" "for" "foreach" "function" "global" "goto" "if" "implements" "include" "include_once" "instanceof" "insteadof" "int" "integer" "interface" "isset" "list" "namespace" "new" "object" "print" "private" "protected" "public" "readonly" "real" "require" "require_once" "return" "static" "string" "switch" "throw" "trait" "try" "unset" "unset" "use" "var" "while" "yield from" "yield" ================================================ FILE: tools/fuzzing/target.php ================================================ tokens = $tokens; } public function beforeTraverse(array $nodes): void { $this->hasProblematicConstruct = false; } public function leaveNode(PhpParser\Node $node) { // We don't precisely preserve nop statements. if ($node instanceof Stmt\Nop) { return NodeVisitor::REMOVE_NODE; } // We don't precisely preserve redundant trailing commas in array destructuring. if ($node instanceof Expr\List_) { while (!empty($node->items) && $node->items[count($node->items) - 1] === null) { array_pop($node->items); } } // For T_NUM_STRING the parser produced negative integer literals. Convert these into // a unary minus followed by a positive integer. if ($node instanceof Scalar\Int_ && $node->value < 0) { if ($node->value === \PHP_INT_MIN) { // PHP_INT_MIN == -PHP_INT_MAX - 1 return new Expr\BinaryOp\Minus( new Expr\UnaryMinus(new Scalar\Int_(\PHP_INT_MAX)), new Scalar\Int_(1)); } return new Expr\UnaryMinus(new Scalar\Int_(-$node->value)); } // If a constant with the same name as a cast operand occurs inside parentheses, it will // be parsed back as a cast. E.g. "foo(int)" will fail to parse, because the argument is // interpreted as a cast. We can run into this with inputs like "foo(int\n)", where the // newline is not preserved. if ($node instanceof Expr\ConstFetch && $node->name->isUnqualified() && in_array($node->name->toLowerString(), self::CAST_NAMES) ) { $this->hasProblematicConstruct = true; } // The parser does not distinguish between use X and use \X, as they are semantically // equivalent. However, use \keyword is legal PHP, while use keyword is not, so we inspect // tokens to detect this situation here. if ($node instanceof Stmt\Use_ && $node->uses[0]->name->isUnqualified() && $this->tokens[$node->uses[0]->name->getStartTokenPos()]->is(\T_NAME_FULLY_QUALIFIED) ) { $this->hasProblematicConstruct = true; } if ($node instanceof Stmt\GroupUse && $node->prefix->isUnqualified() && $this->tokens[$node->prefix->getStartTokenPos()]->is(\T_NAME_FULLY_QUALIFIED) ) { $this->hasProblematicConstruct = true; } // clone($x, ) is not preserved precisely. if ($node instanceof Expr\FuncCall && $node->name instanceof Node\Name && $node->name->toLowerString() == 'clone' && count($node->args) == 1 ) { $this->hasProblematicConstruct = true; } } }; $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor($visitor); $fuzzer->setTarget(function(string $input) use($lexer, $parser, $prettyPrinter, $nodeDumper, $visitor, $traverser) { $stmts = $parser->parse($input); $printed = $prettyPrinter->prettyPrintFile($stmts); $visitor->setTokens($parser->getTokens()); $stmts = $traverser->traverse($stmts); if ($visitor->hasProblematicConstruct) { return; } try { $printedStmts = $parser->parse($printed); } catch (PhpParser\Error $e) { throw new Error("Failed to parse pretty printer output"); } $visitor->setTokens($parser->getTokens()); $printedStmts = $traverser->traverse($printedStmts); $same = $nodeDumper->dump($stmts) == $nodeDumper->dump($printedStmts); if (!$same && !preg_match('/<\?php<\?php/i', $input)) { throw new Error("Result after pretty printing differs"); } }); $fuzzer->setMaxLen(1024); $fuzzer->addDictionary(__DIR__ . '/php.dict'); $fuzzer->setAllowedExceptions([PhpParser\Error::class]);