豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit b3bdbd6

Browse files
authored
fix: raise SyntaxError for final class constants before PHP 8.1 (#1234)
1 parent 9f448b7 commit b3bdbd6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/parser/class.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ module.exports = {
344344
if (flags[1] === 1 || flags[2] === 1 || flags[3] === 1) {
345345
this.error();
346346
}
347+
// final class constants require PHP 8.1+
348+
if (flags[2] === 2 && this.version < 801) {
349+
this.raiseError("Final class constants are not allowed before PHP 8.1");
350+
}
347351

348352
const [nullable, type] =
349353
this.version >= 803 ? this.read_optional_type() : [false, null];

test/snapshot/classconstant.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ describe("classconstant", () => {
5959
),
6060
).toMatchSnapshot();
6161
});
62+
it("final should throw before PHP 8.1", () => {
63+
expect(() =>
64+
parser.parseEval("class Foo { final const CONSTANT = 1; }", {
65+
parser: { version: 800 },
66+
}),
67+
).toThrow(SyntaxError);
68+
});
6269
it("type hinted (supported)", () => {
6370
expect(
6471
parser.parseEval(

0 commit comments

Comments
 (0)