- var_dump: documentation ( source)
- trigger_error: documentation ( source)
<?php
class Coalescing
{
protected $attributes = [
'attribute1' => 'value1',
];
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;
}
public function __isset($name)
{
print "ISSET\n";
return array_key_exists($name, $this->attributes);
}
}
$coal = new Coalescing();
var_dump($coal->attribute1 ?? 'default');
var_dump($coal->attribute2 ?? 'default');