<?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.
You have javascript disabled. You will not be able to edit any code.