is_countable before you call count

Since 7.2 count() warns on anything that is not an array or Countable, and the guard everybody wrote by hand is now in the standard library.

if (is_countable($result) && count($result) > 0) {
    $this->render($result);
}

// and the case worth internalising
$gen = (function () { yield 1; })();
var_dump(is_countable($gen));    // false

A generator being uncountable is the detail that matters, because switching a method from returning an array to yielding is exactly the kind of change that makes this guard start failing quietly. A generator has no length until it is consumed, so any code that wants a count wants the array. Where the guard appears more than twice in one file the real fix is a return type on whatever produced the value, not another check.