Skip to content

Language: resource used as array offset TypeError — Zend Warning + int cast (zend_hash.c / zend_execute.c) #29550

Closed

Description

@PurHur

Category

language · php-src-strict · array offset / resource · pillar 4

Problem

On Zend 8.2, using a resource as an array offset emits E_WARNING (Resource ID#N used as offset, casting to integer (N)) and stores under the cast integer key. VM/JIT throw TypeError: Illegal offset type and refuse the write — observable control-flow and data divergence (not just message text).

Probed 2026-08-09 @ 092e9d1ee8 vs Zend 8.2.32. JIT matches VM.

Repro Zend 8.2.32 VM / JIT
$a[$r]=1 ($r = fopen('php://memory','r')) Warning + $a[N]=1 TypeError: Illegal offset type
isset($a[$r]) after Zend write Warning + true TypeError on isset path

php-src reference

PHP implementation target

  • Match php-src-strict for PHP 8.2 resource offsets: warn + cast to int for write/isset/unset (same resource id), do not TypeError
  • PHP-in-PHP in VM/JIT hash/dim helpers; no new C runtime logic

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/resource_key.php <<'"'"'PHP'"'"'
<?php
error_reporting(E_ALL);
$a = [];
$r = fopen("php://memory", "r");
try {
  $a[$r] = 1;
  echo "set:"; var_export($a); echo "\n";
} catch (Throwable $e) {
  echo "set:", get_class($e), ":", $e->getMessage(), "\n";
}
fclose($r);
PHP
php -d zend.exception_ignore_args=0 /tmp/resource_key.php
php -d zend.exception_ignore_args=0 bin/vm.php /tmp/resource_key.php
php -d zend.exception_ignore_args=0 bin/jit.php /tmp/resource_key.php'

Done when

  • VM + JIT: resource array offset write matches Zend (Warning + integer key), not TypeError
  • isset/unset on resource offset match Zend warn+cast behavior
  • Compliance/.phpt or test/repro/ guard
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Aug 9, 2026
  2. PurHur commented on Aug 9, 2026

    @PurHur
    OwnerAuthor

    claim: Lane A implementer — starting this run (resource array offset warn+cast vs TypeError)

  3. PurHur commented on Aug 9, 2026

    @PurHur
    OwnerAuthor

    Merged via #29572

    Verification: VM + JIT match Zend warn+cast for $a[$resource] set/isset/unset (resource id may differ by process). PHPUnit ResourceArrayOffsetWarnCastTest|IllegalOffsetObjectKeyNewInTryTest OK. Inventory 7292/7292 + spine sync OK.

    php-src-strict; PHP-in-PHP in ResourceArrayOffsetSupport / HashTableResourceKeyLlvm — no new C runtime.

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:compilerCompiler / CFG / JITarea:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions