PHP 8.2 RFC: Unwrap reference after foreach

Unwrap reference after foreach
PHP 8.2
Under Discussion

Unwrap reference after foreach

TypeImprovement
Version PHP 8.2

After a foreach by reference loop, the value variable currently remains a reference to the last array element, which may result in unexpected behavior if the variable is later reused. This RFC proposes to unwrap the reference after the foreach loop.

Subscribe to PHP.Watch newsletter for monthly updates

You will receive an email on last Wednesday of every month and on major PHP releases with new articles related to PHP, upcoming changes, new features and what's changing in the language. No marketing emails, no selling of your contacts, no click-tracking, and one-click instant unsubscribe from any email you receive.