php - call to a member function on null
I'd suspect that this getTemplate( 'dml' )
is not returning a value. If you do a var_dump(getTemplate( 'dml' ))
, does it show anything?
You might check for "null" before doing that line of code, and in your "else" statement, output an error message, or some other action suitable for that error.
Your problem is solved long time ago, but I suppose a lot of people looking for solution struggle with this error. PHP 8.0 introduces new operator nullsafe operator (?->)
. It's not for suppressing the error(!), but for cases when variable is allowed to be null
and then we don't need to double check its value.
So in OP's question last row would look like:
return $this->registry->output->getTemplate( 'dml' )?->duplicatesLoadMovie( $host, $path, $id, $md5 );
It should be used very carefully, because it's not solution for every occurence of this kind of error!