3v4l.org

run code in 500+ PHP versions simultaneously
<?php final class DemoFile { private readonly string $method; public static function create(int $a): static { $self = new static(); $self->method = 'hi'; if ($a > 0) { $self->method = 'hello'; } return $self; } } $demo = DemoFile::create(2); var_dump($demo);
Output for 8.1.32 - 8.1.34, 8.2.7 - 8.2.30, 8.3.5 - 8.3.30, 8.4.2 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught Error: Cannot modify readonly property DemoFile::$method in /in/hv7TE:12 Stack trace: #0 /in/hv7TE(18): DemoFile::create(2) #1 {main} thrown in /in/hv7TE on line 12
Process exited with code 255.

preferences:
55.18 ms | 689 KiB | 4 Q