Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected invalid classnames in Runtime code for foreach #1001

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1000.md
@@ -0,0 +1 @@
- Fix invalid classnames in Runtime code for foreach [#1000](https://github.com/smarty-php/smarty/issues/1000)
18 changes: 8 additions & 10 deletions src/Runtime/ForeachRuntime.php
Expand Up @@ -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);
}

/**
Expand Down