3v4l.org

run code in 500+ PHP versions simultaneously
<?php final class DemoFile { private bool $isConstructed = false; // This is changed to true public mixed $value = null { get { return $this->value; } set { if (!$this->isConstructed) { $this->value = $value; return; } if (!is_string($value)) { throw TypeError('$value must be a string when it is already constructed!'); } $this->value = $value; } } public function __construct( mixed $value = null, ) { $this->value = $value; $this->isConstructed = true; // This is removed } } $testVar = new DemoFile(1); // This is fine if $isConstructed default is false // $testVar->value = 1; // This should always throw.
Output for 8.4.18
Output for 8.3.5
Parse error: syntax error, unexpected token "return" in /in/ZrofM on line 9
Process exited with code 255.

preferences:
13.99 ms | 1166 KiB | 5 Q