Skip to content

Regression: WeakMap/WeakReference inside closure — offsetGet/get() NULL again (re-#13923, Zend/zend_weakrefs.c) #14132

Description

@PurHur

Category

stdlib · php-src-strict · regression (re-#13923)

Problem

#13923 was closed 2026-06-30 but closure-scoped weak refs are still broken on VM: WeakMap offset read and WeakReference::get() return NULL inside a user closure while top-level access works.

php-src reference

Repro (verified 2026-06-30)

test/repro/maintainer_gap_weakmap_closure_offsetget.php
test/repro/maintainer_gap_weakreference_closure_get.php

./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_weakmap_closure_offsetget.php   # TypeError: int return, null given
./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_weakreference_closure_get.php   # exit 1
Check Zend VM
(fn(): int => { $wm=new WeakMap(); $o=new stdClass(); $wm[$o]=9; return $wm[$o]; })() 9 NULL
(fn(): bool => { $o=new stdClass(); return WeakReference::create($o)->get()===$o; })() true false

Done when

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 30, 2026
  2. PurHur commented on Jun 30, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — batch (issues #14132)

  3. PurHur commented on Jun 30, 2026

    @PurHur
    OwnerAuthor

    Merged via #14137.

    Fix: `hasStrongScopeBinding()` now scans the active `executingFrame` (closure / parent-linked) in addition to `runStack` suspended callers — closure locals were invisible to weak-ref alive checks.

    Verification:
    ```bash
    ./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_weakmap_closure_offsetget.php # ok
    ./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_weakreference_closure_get.php # ok
    ./script/docker-exec.sh -- ./vendor/bin/phpunit test/unit/WeakReferenceWeakMapTest.php # OK (21 tests)
    ```

  4. PurHur commented on Jun 30, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — batch (issues #14132)

  5. PurHur commented on Jun 30, 2026

    @PurHur
    OwnerAuthor

    Merged via #14138 — VM repros green; WeakReferenceWeakMapTest 19/19; AOT lint on weakmap closure repro exit 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions