Browse Source

Stop warnings when using count in QueryCompiler in PHP 7.2

- PHP 7.2 has changed the count function to emit warnings when the object
  being "counted" is not an array or does not implement the Countable
  interface.  The QueryCompiler was using count for objects that did not
  fall into those two categories.  This fixes that problem while
  maintaining the same logic (returning early when $parts is not set, is
  null, or has a count of 0).
Mike Fellows 8 years ago
parent
commit
2c958f6243
1 changed files with 3 additions and 1 deletions
  1. 3 1
      src/Database/QueryCompiler.php

+ 3 - 1
src/Database/QueryCompiler.php

@@ -125,7 +125,9 @@ class QueryCompiler
     protected function _sqlCompiler(&$sql, $query, $generator)
     {
         return function ($parts, $name) use (&$sql, $query, $generator) {
-            if (!count($parts)) {
+            if (!isset($parts) ||
+                ((is_array($parts) || $parts instanceof \Countable) && !count($parts))
+            ) {
                 return;
             }
             if ($parts instanceof ExpressionInterface) {