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
Related
Category
stdlib·language· php-src-strictProblem
Zend treats backed enum case objects as valid
WeakMapkeys (weak-referenced like any object). This compiler rejects the assignment:VM throws
TypeError: WeakMap key must be an objectbecause enum cases are represented as backing scalars (int) andWeakMaponly acceptsTYPE_OBJECT.php-src reference
Zend/zend_weakrefs.c—zend_weakmap_offset_set, object-key guardZend/zend_enum.c— enum case isIS_OBJECTRepro
$m[E::A] = 1offsetGetreturns stored valueTypeError: WeakMap key must be an objectScope
lib/VM/WeakMapSupport.php(or equivalent) — acceptTYPE_ENUM_CASEkeyslib/VM/EnumSupport.php— enum cases must be objects at runtime (pairs #8941)lib/JIT/Builtin/WeakRefRegistryRuntime.php/ WeakMap loweringtest/compliance/cases/stdlib/weakmap_enum_case_key.phptPHP-in-PHP: registry + offset handlers in PHP VM/JIT; shrink any C weakref tables when PHP path lands (#9191).
Done when
TypeError./script/ci-fast.sh --filter weakmap_enum_case_keygreenRelated
spl_object_id()/ enum case object acceptance