3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Coalescing { protected $attributes = [ 'attribute1' => 'value1', ]; public function __isset($name) { 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
based on IUtdA
Output for 7.0.6 - 7.3.0beta1
GET string(6) "value1" string(7) "default"
Output for hhvm-3.18.5 - 3.21.3, 7.0.0 - 7.0.5
GET string(6) "value1" GET Notice: Property attribute2 does not exist in /in/hg4Wf on line 20 string(7) "default"
Output for hhvm-3.22.0
GET string(6) "value1" GET Notice: Property attribute2 does not exist in /in/hg4Wf on line -1 string(7) "default"
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected '?' in /in/hg4Wf on line 28
Process exited with code 255.