3v4l.org

run code in 500+ PHP versions simultaneously
<?php new class { private array $data = ['foo' => true, 'bar' => false,]; function __construct() { // $this->foo ||= true; $this->foo || ($this->foo = true); assert($this->data['foo'] === true); // $this->bar ||= false; $this->bar || ($this->bar = false); assert($this->data['bar'] === false); } function __get(string $name): bool { echo "Getter called for {$name}\n"; return $this->data[$name]; } function __set(string $name, bool $value): void { echo "Setter called for {$name}\n"; $this->data[$name] = $value; } };
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
Getter called for foo Getter called for bar Setter called for bar

preferences:
29.09 ms | 1137 KiB | 7 Q