?? vs isset() with __isset() and __get()
<?php
class A
{
public function __get($id)
{
return 'a value';
}
}
class B
{
public function __isset($id)
{
return false;
}
public function __get($id)
{
return 'a value';
}
}
class c
{
protected $test = "a value";
public function __isset($id)
{
return true;
}
}
$a = new A();
$b = new B();
$c = new C();
echo isset($a->test) ? $a->test : 'nothing'; echo $a->test ?? 'nothing'; echo isset($b->test) ? $b->test : 'nothing'; echo $b->test ?? 'nothing'; echo isset($c->test) ? $c->test : 'nothing'; echo $c->test ?? 'nothing'; ?>