diff --git a/src/parser/variable.js b/src/parser/variable.js index 3036c7b33..531afddc0 100644 --- a/src/parser/variable.js +++ b/src/parser/variable.js @@ -137,6 +137,15 @@ module.exports = { this.next(); what = what(name, false); break; + case this.tok.T_CLASS: + if (!is_static_lookup) { + this.error(); + } + what = this.node("identifier"); + name = this.text(); + this.next(); + what = what(name, false); + break; case "$": what = this.node(); this.next().expect(["$", "{", this.tok.T_VARIABLE]); diff --git a/test/snapshot/__snapshots__/variable.test.js.snap b/test/snapshot/__snapshots__/variable.test.js.snap index 309f8dd3b..27de19cfb 100644 --- a/test/snapshot/__snapshots__/variable.test.js.snap +++ b/test/snapshot/__snapshots__/variable.test.js.snap @@ -781,6 +781,59 @@ Program { } `; +exports[`Test variables class keyword on variables 1`] = ` +Program { + "children": [ + ExpressionStatement { + "expression": StaticLookup { + "kind": "staticlookup", + "offset": Identifier { + "kind": "identifier", + "name": "class", + }, + "what": PropertyLookup { + "kind": "propertylookup", + "offset": Identifier { + "kind": "identifier", + "name": "classProp", + }, + "what": Variable { + "curly": false, + "kind": "variable", + "name": "classVariable", + }, + }, + }, + "kind": "expressionstatement", + }, + ExpressionStatement { + "expression": StaticLookup { + "kind": "staticlookup", + "offset": Identifier { + "kind": "identifier", + "name": "class", + }, + "what": OffsetLookup { + "kind": "offsetlookup", + "offset": Number { + "kind": "number", + "value": "0", + }, + "what": Variable { + "curly": false, + "kind": "variable", + "name": "arrayVariable", + }, + }, + }, + "kind": "expressionstatement", + }, + ], + "errors": [], + "kind": "program", +} +`; + exports[`Test variables default variables 1`] = ` Program { "children": [ diff --git a/test/snapshot/variable.test.js b/test/snapshot/variable.test.js index dff819c9b..ae401cebc 100644 --- a/test/snapshot/variable.test.js +++ b/test/snapshot/variable.test.js @@ -179,4 +179,12 @@ describe("Test variables", function () { it("simple variable #4", function () { expect(parser.parseEval("$var = $$$var;")).toMatchSnapshot(); }); + it("class keyword on variables", function () { + expect( + parser.parseEval( + `$classVariable->classProp::class; + $arrayVariable[0]::class;`, + ), + ).toMatchSnapshot(); + }); });