Corrected invalid classnames in Runtime code for foreach (#1001)

Fixes #1000
This commit is contained in:
Simon Wisselink
2024-04-19 10:42:54 +02:00
committed by GitHub
parent 5ee4363000
commit 9a8702d937
2 changed files with 9 additions and 10 deletions

1
changelog/1000.md Normal file
View File

@@ -0,0 +1 @@
- Fix invalid classnames in Runtime code for foreach [#1000](https://github.com/smarty-php/smarty/issues/1000)

View File

@@ -116,22 +116,20 @@ class ForeachRuntime {
* *
* @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0 * @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0
* for empty elements * for empty elements
* @throws \Exception
*/ */
public function count($value) { public function count($value): int
if ($value instanceof IteratorAggregate) { {
if ($value instanceof \IteratorAggregate) {
// Note: getIterator() returns a Traversable, not an Iterator // Note: getIterator() returns a Traversable, not an Iterator
// thus rewind() and valid() methods may not be present // thus rewind() and valid() methods may not be present
return iterator_count($value->getIterator()); return iterator_count($value->getIterator());
} elseif ($value instanceof Iterator) { } elseif ($value instanceof \Iterator) {
return $value instanceof Generator ? 1 : iterator_count($value); return $value instanceof \Generator ? 1 : iterator_count($value);
} elseif ($value instanceof Countable) { } elseif ($value instanceof \Countable) {
return count($value); 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);
} }
/** /**