If we are do not define variable, we get notice, for example
$a = null;
$str = DB::find()->select('name')->where(['id' => 1])->one(); //returns null or string name
echo $a ?: '';
PHP has a feature known as "type juggling", where when a function is called on some data that is unsupported, PHP will try to convert the data to a usable format. For example,
echo 1234; will output
1234, rather than throwing an error (as
1234 is not a string).
null is type juggled to the empty string, as it's probably the most logical thing for it to convert to (
null representing the concept of nothing). This behaviour is defined here, under the converting to string section.