[PR #891] [MERGED] Do not iterate non-array Traversables #1401

Closed
opened 2026-03-04 03:12:07 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Seldaek/monolog/pull/891
Author: @naderman
Created: 11/24/2016
Status: Merged
Merged: 11/26/2016
Merged by: @Seldaek

Base: 1.xHead: t/do-not-iterate-non-arrays


📝 Commits (1)

  • 45de570 Don't even try to attempt normalizing iterators or generators in context

📊 Changes

1 file changed (+2 additions, -6 deletions)

View changed files

📝 src/Monolog/Formatter/NormalizerFormatter.php (+2 -6)

📄 Description

Iterators and Generators may not be rewindable, so foreach is not safe to use on them.

Iterators and especially Generators may trigger irreversible actions on calling next(), so iterating over all values can potentially cause harm, e.g. imagine an iterator over a set of HTTP POST requests that are sent when the next value is requested . The only sufficiently safe thing to iterate and include here are primitive arrays.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Seldaek/monolog/pull/891 **Author:** [@naderman](https://github.com/naderman) **Created:** 11/24/2016 **Status:** ✅ Merged **Merged:** 11/26/2016 **Merged by:** [@Seldaek](https://github.com/Seldaek) **Base:** `1.x` ← **Head:** `t/do-not-iterate-non-arrays` --- ### 📝 Commits (1) - [`45de570`](https://github.com/Seldaek/monolog/commit/45de570954c570deb66686f06da9854ea361779f) Don't even try to attempt normalizing iterators or generators in context ### 📊 Changes **1 file changed** (+2 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `src/Monolog/Formatter/NormalizerFormatter.php` (+2 -6) </details> ### 📄 Description Iterators and Generators may not be rewindable, so foreach is not safe to use on them. Iterators and especially Generators may trigger irreversible actions on calling next(), so iterating over all values can potentially cause harm, e.g. imagine an iterator over a set of HTTP POST requests that are sent when the next value is requested . The only sufficiently safe thing to iterate and include here are primitive arrays. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-04 03:12:07 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#1401
No description provided.