3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Coalescing { protected $attributes = [ 'attribute1' => 'value1', ]; public function __isset() { return array_key_exists($name, $this->attributes); } public function __get($name) { print "GET\n"; if (array_key_exists($name, $this->attributes)) { return $this->attributes[$name]; } trigger_error("Property $name does not exist"); return null; } } $coal = new Coalescing(); var_dump($coal->attribute1 ?? 'default'); //GET //string(6) "value1" var_dump($coal->attribute2 ?? 'default'); //GET // It should dump 'default' here. Instead, the error of __get() is triggered
Output for 7.1.0 - 7.1.12, 7.2.0
Fatal error: Method Coalescing::__isset() must take exactly 1 argument in /in/IUtdA on line 10
Process exited with code 255.

preferences:
158.76 ms | 1395 KiB | 21 Q