Answer the question
In order to leave comments, you need to log in
Yii2: Why are the received values of var_dump($ar['test'] ?? 0) and var_dump($ar['test']) different for ActiveRecord?
Model:
class ArModel extends yii\db\ActiveRecord
{
public $test;
}
$ar = new ArModel();
$ar->test = 5;
var_dump($ar['test'] ?? 0);
var_dump($ar['test']);
int(0)
int(5)
Answer the question
In order to leave comments, you need to log in
Because the database table for this model is not specified.$ar['test'] ?? 0
is equivalent to
Invoke , which catches the Exception "The table does not exist" and returns false.isset($ar['test']) ? $ar['test']: 0
There is a call \yii\db\BaseActiveRecord::__get()
that returns a value.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question