HomeDevCentral

Allow to count "null" and "false" values

Description

Allow to count "null" and "false" values

Summary:
Legacy codebases can have methods with dual return value:

  • an array when data is found
  • null when no data is found

Then count is called, to ensure there are data.

In modern PHP, this triggers a warning;
count(): Parameter must be an array or an object that implements Countable

This change provides a method to accept also null and false values.
In such case, the 0 value is returned.

This method isn't intended to be totally permissive: if something
else than an array, a Countable, null or false is passed
as parameter, a TypeError error is thrown, even with falsy values.

Test Plan: Tests provided with countable and not countable variables.

Reviewers: dereckson

Reviewed By: dereckson

Differential Revision: https://devcentral.nasqueron.org/D1632

Details

Provenance
derecksonAuthored on Apr 29 2018, 22:36
derecksonPushed on Apr 29 2018, 22:44
Reviewer
dereckson
Differential Revision
D1632: Allow to count "null" and "false" values
Parents
rKOT159b9c0da150: Allow to determine if a string is an UUID
Branches
Unknown
Tags
Unknown