Skip to content

Unable to have an anonymous readonly class #10377

Closed
@claudepache

Description

@claudepache

Description

The following code:

<?php

$a = new readonly class {
    public int $x;
    function __construct() {
        $this->x = 2;
     }
};
var_dump($a->x);

Resulted in this output:

Parse error: syntax error, unexpected token "readonly" in /in/3uciU on line 3

But I expected this output instead:

int(2)

PHP Version

PHP 8.2.1

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions