Skip to content

By-ref foreach over a static array property leaks three blocks #653

Description

@mirchaemanuel

Summary

A by-reference foreach over a static array property leaks three heap blocks. Output is correct.

Repro

<?php
class C { public static array $x = [1, 2]; }
foreach (C::$x as &$v) { $v = $v * 2; }
unset($v);
echo implode(",", C::$x);

main 2829ce0ab, macOS ARM64, --heap-debug:

2,4
HEAP DEBUG: allocs=7 frees=4 live_blocks=3

PHP 8.4.23 prints the same 2,4. The static property is mutated correctly — this is purely a lifetime issue.

Notes

Found while fixing #642 (by-ref foreach over an instance property, which corrupted the property outright). The static path behaves correctly by comparison — the writes land and nothing is freed early — but it does not balance its allocations.

Measured identically before and after that fix, so it is pre-existing and independent: the static path is untouched by #651.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions