From 9a8702d9372b7e68b41303cd2182b7c30a688ec7 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 19 Apr 2024 10:42:54 +0200 Subject: [PATCH] Corrected invalid classnames in Runtime code for foreach (#1001) Fixes #1000 --- changelog/1000.md | 1 + src/Runtime/ForeachRuntime.php | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 changelog/1000.md diff --git a/changelog/1000.md b/changelog/1000.md new file mode 100644 index 000000000..5aa31f8cc --- /dev/null +++ b/changelog/1000.md @@ -0,0 +1 @@ +- Fix invalid classnames in Runtime code for foreach [#1000](https://github.com/smarty-php/smarty/issues/1000) \ No newline at end of file diff --git a/src/Runtime/ForeachRuntime.php b/src/Runtime/ForeachRuntime.php index fc311df0f..06da7d546 100644 --- a/src/Runtime/ForeachRuntime.php +++ b/src/Runtime/ForeachRuntime.php @@ -116,22 +116,20 @@ public function init( * * @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0 * for empty elements + * @throws \Exception */ - public function count($value) { - if ($value instanceof IteratorAggregate) { + public function count($value): int + { + if ($value instanceof \IteratorAggregate) { // Note: getIterator() returns a Traversable, not an Iterator // thus rewind() and valid() methods may not be present return iterator_count($value->getIterator()); - } elseif ($value instanceof Iterator) { - return $value instanceof Generator ? 1 : iterator_count($value); - } elseif ($value instanceof Countable) { + } elseif ($value instanceof \Iterator) { + return $value instanceof \Generator ? 1 : iterator_count($value); + } elseif ($value instanceof \Countable) { return count($value); - } elseif ($value instanceof PDOStatement) { - return $value->rowCount(); - } elseif ($value instanceof Traversable) { - return iterator_count($value); } - return count((array)$value); + return count((array) $value); } /**