MatrixBlockModel error - "Call to a member function on a non-object"
Matrix initializes its blocks’ field types multiple times – once for each existing block in the field, and one last time to get the initial input HTML that should be used when new blocks are added.

For existing blocks, $this-&gt;element will be set on the field types, referring back to the existing MatrixBlockModel objects representing each of those blocks.

That won’t be the case the time that your field type is just telling Matrix what the initial input HTML should be, however, since no corresponding Matrix block exists yet.

When you call this:



var_dump($this-&gt;element);


it’s not giving you any errors because $this-&gt;element will just be null when there is no element set, and there’s nothing wrong with dumping a null variable.

But when you call this;

var_dump($this-&gt;element-&gt;getOwner())


now you’re trying to access a method on $this-&gt;element, which won’t necessarily be set, and that’s when you’re getting that exception.

So what you need to do is ensure that $this-&gt;element is actually set before trying to access getOwner():

if (isset($this-&gt;element))
{
    $owner = $this-&gt;element-&gt;getOwner();

    if ($owner)
    {
        // ...
    }
}


Note that I’m also not assuming that getOwner() will actually return anything, because that’s not a certainty either. For example if you create/save a new entry but there are validation errors, when the Edit Entry page reloads, you will have MatrixBlockModel objects for each of the blocks you had created, which $this-&gt;element will point to, but they won’t actually have IDs nor an owner yet.