You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
array_unshift() skips unvisited values in foreach by reference when the array has holes #25107
AI-assisted report. The explanation was prepared with AI assistance. The reproduction and outputs below were verified by local execution.
Calling array_unshift() during a foreach by reference can skip an unvisited element when deleted entries leave holes before the iterator position. This can silently omit work items.
The PHP 7 foreach RFC and Zend/tests/foreach/foreach_016.phpt specify that array_unshift() preserves reference-iterator positions. This case also reproduces with string-keyed arrays. The rebuild compacts deleted slots, but the iterator adjustment only adds the number of prepended values to the old position.
Related PR #24475 optimizes the path without holes or active iterators; its current fallback retains the affected iterator adjustment.
PHP Version
Also reproduced on the lowest actively supported branch, PHP-8.4, at commit dfcc0433fcda7fb732cba8d7ee8c857d23f9a9e7, with debug and ZTS enabled.
PHP 8.4.28-dev (cli) (built: Oct 31 2026 18:38:26) (ZTS DEBUG)
Copyright (c) The PHP Group
Zend Engine v4.4.28-dev, Copyright (c) Zend Technologies
PHP 8.5.12 (cli) (built: Oct 28 2026 01:23:38) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.5.12, Copyright (c) Zend Technologies
with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies
Also reproduced on PHP 8.7.0-dev at commit 248c5c45409667b5e69bba38a92c5cc9edd7582a.
Activity