== Why is this an issue?

The `empty()` function in PHP is specifically designed to check if a variable is empty, and it returns true if the variable is empty or evaluates to false. It handles various types of values, such as empty strings, zero, null, and arrays with no elements. This makes the code more readable because it clearly expresses the intention of checking for emptiness.

On the other hand, the `count()` function in PHP is primarily used to count the number of elements in an array or the properties of an object. It’s less explicit and may be less intuitive for someone reading the code.

=== What is the potential impact?

In terms of performance, `empty()` is generally faster than `count()` because it doesn’t need to iterate over all the elements in an array to count them. Instead, it directly checks if the variable is empty or evaluates to false. This can be advantageous when dealing with large arrays or performance-sensitive code.

== How to fix it

=== Code examples

==== Noncompliant code example

[source,php,diff-id=1,diff-type=noncompliant]
----
if (count($a) === 0) { // Noncompliant
 echo $a[0];
}
----

==== Compliant solution

[source,php,diff-id=1,diff-type=compliant]
----
if (empty($a)) {
  echo $a[0];
}
----

== Resources

=== Documentation

* https://www.php.net/manual/en/function.empty[PHP Manual - empty]
* https://www.php.net/manual/en/function.count.php[PHP Manual - count]


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::../message.adoc[]

'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
