.. _parameter-must-be-an-array-or-an-object-that-implements-countable:
Parameter must be an array or an object that implements Countable
-----------------------------------------------------------------
.. meta::
:description:
Parameter must be an array or an object that implements Countable: The ``count()`` native function only count elements that are arrays, or objects that implements the ``Countable`` interface.
:og:image: https://php-errors.readthedocs.io/en/latest/_static/logo.png
:og:type: article
:og:title: Parameter must be an array or an object that implements Countable
:og:description: The ``count()`` native function only count elements that are arrays, or objects that implements the ``Countable`` interface
:og:url: https://php-errors.readthedocs.io/en/latest/messages/parameter-must-be-an-array-or-an-object-that-implements-countable.html
:og:locale: en
:twitter:card: summary_large_image
:twitter:site: @exakat
:twitter:title: Parameter must be an array or an object that implements Countable
:twitter:description: Parameter must be an array or an object that implements Countable: The ``count()`` native function only count elements that are arrays, or objects that implements the ``Countable`` interface
:twitter:creator: @exakat
:twitter:image:src: https://php-errors.readthedocs.io/en/latest/_static/logo.png
.. raw:: html
Description
___________
The ``count()`` native function only count elements that are arrays, or objects that implements the ``Countable`` interface. Anything else yields a fatal error.
Example
_______
.. code-block:: php
Solutions
_________
+ Check for type before using count: ``is_array`` or ``instanceof \Countable``.
In more recent PHP versions, this error message is now :ref:`must-be-of-type-countable|array,-%s-given`.
Static Analysis
_______________
This error may be tracked down with the following static analysis rules: `Structures/CanCountNonCountable `_.