3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Thing { private string $state; public function __construct() { $this->state = 'foo'; } public function __set(string $property, $value) : void { if ((\debug_backtrace()[1]['object'] ?? null) !== $this) { throw new \Exception('nope'); } $this->$property = $value; } } $thing = new Thing(); var_dump($thing); $thing->state = 'this should never be allowed';

preferences:
28.87 ms | 405 KiB | 5 Q