CommentParser: Avoid unnecessary reference in foreach()

This is not necessary, and never has been. This variable contains an
object and it's never assigned to.

Instead, the reference creates hard-to-debug bugs (I've just spent
an hour debugging one). When the variable name is reused later in
the same function as the loop variable of another foreach() loop
(such as in If918bfd5e0), the result is overwriting of the last entry
in $this->threadItems with the last entry from the other array.
I was questioning everything I know about variables until I noticed.

Change-Id: Ibb57f915b39dd4d6d2e744903f9ecadd67b1f52d
This commit is contained in:
Bartosz Dziewoński 2020-10-14 03:08:39 +02:00
parent a2cf9cc978
commit 88b5be11fd

View file

@ -968,7 +968,7 @@ class CommentParser {
$replies = [];
$this->commentsById = [];
foreach ( $this->threadItems as &$threadItem ) {
foreach ( $this->threadItems as $threadItem ) {
if ( $threadItem instanceof HeadingItem ) {
// We don't need ids for section headings right now, but we might in the future
// e.g. if we allow replying directly to sections (adding top-level comments)