Hang in Windows after upgrade 8.4.6 to 8.4.7, unpacking IteratorAggregate with custom Traversable when unpacking
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code hangs in after testing out 8.5. Narrowed it down to an earlier version 8.4.7 in which this behavior first occurs. In 8.4.6 is works with no issues. Seems only to apply in Windows. In non-windows it seems to run fine: https://3v4l.org/eRYIJ#v8.4.7
<?php
class ArrayMap implements \Iterator
{
public function __construct(private array $array)
{
}
public function current(): mixed
{
return current($this->array);
}
public function next(): void
{
next($this->array);
}
public function key(): int|string|null
{
return key($this->array);
}
public function valid(): bool
{
return key($this->array) !== null;
}
public function rewind(): void
{
reset($this->array);
}
}
class Aggregate implements \IteratorAggregate
{
public function __construct(private array $array)
{
}
public function getIterator(): Traversable
{
return new ArrayMap($this->array);
}
}
class Y
{
}
class Z
{
}
$_1 = new Aggregate([Z::class => Z::class,]);
var_dump(1);
$_2 = [...iterator_to_array($_1, true)];
var_dump(2);
$_3 = [...$_2, Y::class => Z::class];
var_dump(3);
$_4 = new Aggregate($_3);
var_dump(4);
[...$_4];
var_dump(5);
Resulted in this output:
int(1)
int(2)
int(3)
int(4)
it hangs here with max cpu
But I expected this output instead:
int(1)
int(2)
int(3)
int(4)
int(5)
PHP Version
PHP 8.4.7 (cli) (built: May 6 2025 14:14:22) (NTS Visual C++ 2022 x64)
Copyright (c) The PHP Group
Zend Engine v4.4.7, Copyright (c) Zend Technologies
Operating System
Windows
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied reproducer on Windows with PHP 8.4.7 and compare it with 8.4.6, focusing on iterator_to_array() and array unpacking of the custom IteratorAggregate. Done means the final unpack completes without hanging and prints int(5), while preserving the reported behavior on non-Windows systems.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100