Check is smarty variable exist before using it in code
{if (isset($variable)}
{/if}
In PHP you have to check is it object https://www.php.net/manual/en/function.is-object.php
is($_smarty_tpl->tpl_vars) && count($_smarty_tpl->tpl_vars['subcategories'])