Skip to content

Property initialization (default value) with property hooks inside readonly classes #15419

Description

@SerafimArts

Description

Referenced RFC #13455

The following code:

<?phpfinalreadonlyclass ReadonlyClassWithProperty
{
publicconstintDEFAULT_VALUE = 640;
publicfunction__construct(
publicint$value = self::DEFAULT_VALUE {
set(int$value) => $value;
},
) {}
}
// Need to create new object multiple times$ctx = newReadonlyClassWithProperty();
$ctx = newReadonlyClassWithProperty();

Resulted in this output:

*nothing*

But I expected this output instead:

PHP Fatal error: Uncaught Error: Cannot modify readonly property ReadonlyClassWithProperty::$value in ...
Stack trace:
#0 ...: ReadonlyClassWithProperty->$value::set(640)
#1 ...: ReadonlyClassWithProperty->__construct()
#2 {main}
thrown in ...

@iluuu1994 I mention you again, this time it's a not known issue, right?)

PHP Version

PHP 8.4-beta1

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