2) { throw new Exception("Invalid number of arguments for count. count expects 1 or 2 parameters."); } $value = $params[0]; if ($value instanceof \Countable) { return $value->count(); } $mode = count($params) == 2 ? (int) $params[1] : COUNT_NORMAL; return count((array) $value, $mode); } }