3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public $define; // null public $redefine; // null public function define(?bool $something = null): ?bool { return $this->define = $this->define ?? $something; } public function redefine(?bool $something = null): ?bool { return $this->redefine = $something ?? $this->redefine; } } $test = function(?bool $value) { var_export($value ?? 'Not set!' ?: 'False!'); echo PHP_EOL; }; $foo = new Test(); $test($foo->define()); $test($foo->define(true)); $test($foo->define()); $test($foo->define(false)); $test($foo->define()); $test($foo->redefine()); $test($foo->redefine(true)); $test($foo->redefine()); $test($foo->redefine(false)); $test($foo->redefine());

preferences:
173.83 ms | 404 KiB | 5 Q