Skip to content

Stdlib: extract() with enum case array keys must TypeError (ext/standard/basic_functions.c) #5756

Closed

Description

@PurHur

Category

stdlib

Problem

extract() must reject arrays whose keys are enum case objects.

Zend throws TypeError: Illegal offset type. Today, the VM appears to accept enum case keys and proceeds, which is incorrect and can import variables under unpredictable names.

This is a php-src-strict parity requirement.

php-src reference

  • ext/standard/basic_functions.c — PHP_FUNCTION(extract) key validation (zend_hash_* + offset type rules)

Repro

Save as test/repro-maintainer/parity_extract_enum_keys.php:

<?php
enum E { case A; }

try {
    extract([E::A => 1]);
    echo "ok\n";
} catch (Throwable $e) {
    echo $e::class, ': ', $e->getMessage(), "\n";
}

Run:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_extract_enum_keys.php
php bin/vm.php test/repro-maintainer/parity_extract_enum_keys.php
'

Expected (Zend):

  • TypeError: Illegal offset type

Observed (this compiler today):

  • Prints ok.

Scope (this repo)

  • ext/standard/extract.php (or builtin lowering) — validate key types before symbol table writes
  • lib/VM/ — ensure hash iteration surfaces enum case keys as illegal offsets consistently (do not coerce to backing scalar)
  • Add compliance test: test/compliance/cases/stdlib/extract_enum_keys.phpt

Done when

  • VM throws TypeError: Illegal offset type for enum case keys
  • Other illegal offset key types behave like Zend (objects/resources) (may be follow-up)
  • ./script/ci-fast.sh --filter extract_enum_keys is green

Links

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 4, 2026
  2. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: extract([E::A => 1]) already throws TypeError on master before extract() runs (enum array literal guard from #5753). VM/JIT repro on test/repro-maintainer/parity_extract_enum_keys.php matches Zend. Recommend closing as duplicate unless repro differs (e.g. array reaching extract via non-literal path).

  4. PurHur commented on Jun 16, 2026

    @PurHur
    OwnerAuthor

    unclaim: stale — claim from 2026-06-09, no open PR, no activity >7d (maintainer triage 2026-06-16).

  5. PurHur commented on Jul 7, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-c — starting this run

  6. PurHur commented on Jul 7, 2026

    @PurHur
    OwnerAuthor

    claim released: repro throws at array literal construction (Illegal offset type), not extract() — behavior matches Zend; issue stale.

  7. PurHur commented on Jul 16, 2026

    @PurHur
    OwnerAuthor

    unclaim: stale claim (>7 days, no open PR). Returning to implementation-ready pool for the next worker.

  8. PurHur commented on Jul 18, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

    Trust (this workspace):

    • php script/bootstrap-inventory.php --check → OK 5596/5596
    • ./script/release-readiness.sh --json → user_release_ready: yes (inventory, spine, north-star5-fast, vm-driver-probe ok)

    Pre-claim repro: both Zend and VM throw TypeError: Illegal offset type for extract([E::A => 1]) and for $a[E::A]=1 (non-literal). Will add the missing extract_enum_keys compliance guard and close.

  9. PurHur commented on Jul 18, 2026

    @PurHur
    OwnerAuthor

    Merged via #20454

    Verification

    • Zend + VM: TypeError: Illegal offset type for extract([E::A => 1]) and $a[E::A]=1
    • phpunit --filter extract_enum_keys → OK (2 tests)

    Parity already held on master (array-key illegal offset); compliance + maintainer repro now guard #5756.

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 apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions