8000 bug #20859 Avoid warning in PHP 7.2 because of non-countable data (wo… · symfony/symfony@2e0b61e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e0b61e

Browse files
committed
bug #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.2
2 parents 0c1260c + 94253e8 commit 2e0b61e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Symfony/Component/Form/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ public function isEmpty()
748748

749749
return FormUtil::isEmpty($this->modelData) ||
750750
// arrays, countables
751-
0 === count($this->modelData) ||
751+
((is_array($this->modelData) || $this->modelData instanceof \Countable) && 0 === count($this->modelData)) ||
752752
// traversables that are not countable
753753
($this->modelData instanceof \Traversable && 0 === iterator_count($this->modelData));
754754
}

0 commit comments

Comments
 (0)
0