Skip to content

Add support for anonymous readonly classes#1168

Merged
czosel merged 2 commits intoglayzzle:mainfrom
olivereisenhut:main
Feb 13, 2026
Merged

Add support for anonymous readonly classes#1168
czosel merged 2 commits intoglayzzle:mainfrom
olivereisenhut:main

Conversation

@olivereisenhut
Copy link
Contributor

This adds support for anonymous classes that are readonly.
e.g new readonly {}.

Copy link
Collaborator

@czosel czosel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing @olivereisenhut! This looks great, just a tiny tweak and we can get this merged.

Comment on lines 766 to 770
const isReadonly = this.token === this.tok.T_READ_ONLY;
if (
this.token === this.tok.T_CLASS ||
(isReadonly && this.next().token === this.tok.T_CLASS)
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a version check, and a slight refactor of the control flow along the lines of this:

Suggested change
const isReadonly = this.token === this.tok.T_READ_ONLY;
if (
this.token === this.tok.T_CLASS ||
(isReadonly && this.next().token === this.tok.T_CLASS)
) {
const isReadonly = this.token === this.tok.T_READ_ONLY;
if (isReadonly) {
if (this.version < 830) {
// throw exception
}
this.next();
}
if (this.token === this.tok.T_CLASS) {

@olivereisenhut
Copy link
Contributor Author

Thanks for reviewing the PR, @czosel. I have added the version check and a test for it.

Copy link
Collaborator

@czosel czosel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks again for contributing.

@czosel czosel merged commit 6c5cbf6 into glayzzle:main Feb 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants