Skip to content

Stdlib: WeakMap::offsetSet() must accept backed enum case keys (Zend/zend_weakrefs.c) #9194

Description

@PurHur

Category

stdlib · language · php-src-strict

Problem

Zend treats backed enum case objects as valid WeakMap keys (weak-referenced like any object). This compiler rejects the assignment:

enum E: int { case A = 1; }
$m = new WeakMap();
$m[E::A] = 42;   // Zend: ok
echo $m[E::A];   // 42

VM throws TypeError: WeakMap key must be an object because enum cases are represented as backing scalars (int) and WeakMap only accepts TYPE_OBJECT.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_weakmap_enum_case_key.php
php bin/vm.php test/repro-maintainer/parity_weakmap_enum_case_key.php 2>&1 | head -5
'
Runtime $m[E::A] = 1
Zend succeeds; offsetGet returns stored value
VM TypeError: WeakMap key must be an object

Scope

Layer Files
VM lib/VM/WeakMapSupport.php (or equivalent) — accept TYPE_ENUM_CASE keys
Enum lib/VM/EnumSupport.php — enum cases must be objects at runtime (pairs #8941)
JIT lib/JIT/Builtin/WeakRefRegistryRuntime.php / WeakMap lowering
Tests test/compliance/cases/stdlib/weakmap_enum_case_key.phpt

PHP-in-PHP: registry + offset handlers in PHP VM/JIT; shrink any C weakref tables when PHP path lands (#9191).

Done when

  • Repro stores and retrieves value on VM like Zend
  • Non-object scalars still TypeError
  • ./script/ci-fast.sh --filter weakmap_enum_case_key green

Related

Activity

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 machineimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions