[BUGFIX] fluid: Harden CountViewHelper 27/54927/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 3 Dec 2017 20:30:35 +0000 (21:30 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 3 Dec 2017 20:53:46 +0000 (21:53 +0100)
The CountViewHelper calls count() on non-arrays or non-Countable
objects. This throws warnings on PHP 7.2 - sanitize this call.

Change-Id: Ie1932c31a099577cb0d344824a6441509aefbc03
Resolves: #83214
Releases: 7.6
Reviewed-on: https://review.typo3.org/54927
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/fluid/Classes/ViewHelpers/CountViewHelper.php

index fc5b117..99aa499 100644 (file)
@@ -78,6 +78,9 @@ class CountViewHelper extends AbstractViewHelper implements CompilableInterface
         if (is_object($subject) && !$subject instanceof \Countable) {
             throw new Exception('CountViewHelper only supports arrays and objects implementing \Countable interface. Given: "' . get_class($subject) . '"', 1279808078);
         }
-        return count($subject);
+        if (is_array($subject) || $subject instanceof \Countable) {
+            return count($subject);
+        }
+        return 0;
     }
 }