Skip to content

Runtime: $GLOBALS must preserve enum case objects — not backing scalars (Zend/zend_hash.c) #9436

Description

@PurHur

Category

runtime — php-src-strict enum zval preservation in superglobals

Problem

Storing a backed enum case in $GLOBALS[...] (or assigning into the $GLOBALS array) materializes the backing scalar (int(1)) instead of keeping the enum case object. Zend preserves the enum zval.

Part of the enum-preservation cluster (#8746, #9342); distinct from compact() (#8686) and array helpers.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r '"'"'enum E:int{case A=1;} $GLOBALS["e"]=E::A; var_dump($GLOBALS["e"]);'"'"''

Zend:

enum(E::A)

This compiler (bin/vm.php):

int(1)

Scope (PHP-in-PHP)

  • lib/VM.php — $GLOBALS write path / superglobal table insert
  • lib/VM/Context.php — globals hashtable helpers
  • lib/VM/EnumCaseSupport.php — ensure enum zvals are not scalarized on hash insert
  • JIT/AOT globals refresh if separate LLVM path exists

Done when (php-src-strict)

  • Repro prints enum(E::A) on VM (and JIT/AOT when globals touched in compiled code).
  • Compliance guard test/compliance/cases/runtime/globals_enum_case.phpt (add) matches Zend.
  • $_SERVER / other superglobals that accept enum values follow same preservation rule when in scope.

Related

#8746, #9342, #8686, closed #5547 enum preservation umbrella.

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 machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions