Skip to content

Ensures count is applied on array or countables

Compare
Choose a tag to compare
@ffflabs ffflabs released this 13 Jun 14:03
· 110 commits to master since this release

As described in #62, the library uses count without checking if the parameter is an array or a countable object.
In versions of PHP prior to v7.1, this would return 0 for null and 1 for non-arrays/non-countables. From 7.2 onwards, this practice will emit an E_WARNING.

On this release, we've implemented a global safe_count function, which in turn will call is_countable (if available, as of PHP 7.3) or a polyfill of it declared if the native function does not exist, then return 0 if the parameter is not countable, or the proper item count otherwise.