Answer the question
In order to leave comments, you need to log in
Schrödinger Object: Where does Trying to get property 'type' of non-object come from?
The error pops up here, on the 125th line:
125: if ($work->category->type == Category::TYPE_URGENT_WORK) {
126: $this->doSomething();
127: }
$t = $work->category->type;
if ($t == 2) {
}
Answer the question
In order to leave comments, you need to log in
Are you running this code in a loop? what is the list of models? With your validation, you are only validating the first object and the others below are not. To catch a cat:
if (!$work->category) {
print_r($work);
}
if ($work->category && $work->category->type == Category::TYPE_URGENT_WORK) {
// ...
}
In a particular case, there may not be a connection, so in any case, an "extra check" will not hurt:
125: if ($work->category && $work->category->type == Category::TYPE_URGENT_WORK) {
126: $this->doSomething();
127: }
125: if ($work->category instanceof Category && $work->category->type == Category::TYPE_URGENT_WORK) {
126: $this->doSomething();
127: }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question