Skip to content

MIR0016

InvalidDynamicProperty

Enums and readonly classes cannot hold dynamic properties: writing a property they do not declare throws Error: Cannot create dynamic property E::$x. On other classes the same write is DynamicPropertyCreation.

<?php
readonly class Point {
public function __construct(public int $x) {}
}
$p = new Point(1);
$p->y = 2;

Declare the property, or keep the extra data elsewhere.