Commit 2e0b61e
committed
bug symfony#20859 Avoid warning in PHP 7.2 because of non-countable data (wouterj)
This PR was merged into the 2.7 branch.
Discussion
----------
Avoid warning in PHP 7.2 because of non-countable data
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Recently, the "[Counting of non-countable objects][1]" RFC was merged in PHP 7.2-dev. This means `count()` now causes a warning when passing anything that's not countable (e.g. `null` or `''`).
As PHP does not lazily execute conditions, `FormUtil::isEmtpy($data) || 0 === count($data)` will cause *both* conditions to be executed. This means `count($data)` errors when `$data` is empty.
Splitting it up in 2 statements avoids the warning being triggered in PHP 7.2.
See https://travis-ci.org/symfony-cmf/content-bundle/jobs/181815895 for a failing test caused by this bug.
[1]: https://wiki.php.net/rfc/counting_non_countables
Commits
-------
94253e8 Only count on arrays or countables to avoid warnings in PHP 7.21 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
748 | 748 | | |
749 | 749 | | |
750 | 750 | | |
751 | | - | |
| 751 | + | |
752 | 752 | | |
753 | 753 | | |
754 | 754 | | |
| |||
0 commit comments