Skip to content

Language: array offset on resource Errors — Zend Warning "Trying to access array offset on resource" (zend_execute.c) #30028

Description

@PurHur

Category

Language · php-src-strict · resource dim fetch

Problem

Using a resource as an array container must match Zend:

Op Zend 8.4.24 VM (PROFILE=8.4)
Read $r[0] Warning Trying to access array offset on resource; continues (null) Error: Cannot use object of type Resource as array
Write $r[0]=1 Error: Cannot use a scalar value as an array Error: Cannot use object of type Resource as array
isset($r[0]) / empty($r[0]) false / true (no throw) Fatal same Resource Error

Probed 2026-08-10 — php:8.4-cli 8.4.24 vs PHP_COMPILER_PROFILE=8.4 php bin/vm.php.

Related closed: #4867 (generic non-container Warning), #29550 (resource used as offset key), #29559 (string-offset TypeError wording Resource vs resource) — this issue is resource as the array subject.

php-src reference

PHP implementation target

  • Dim fetch/isset/empty on resource in lib/VM/ (and JIT): Warning + null on read; write Error text matching Zend (Cannot use a scalar value as an array); isset/empty soft false/true
  • Prefer shared type-dispatch with other non-array dim paths; PHP-in-PHP; no new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
export PHP_COMPILER_PROFILE=8.4
printf "%s\n" "<?php
\$f = fopen(\"php://memory\", \"r\");
try { var_export(\$f[0]); echo PHP_EOL; } catch (Throwable \$e) { echo get_class(\$e), \":\", \$e->getMessage(), PHP_EOL; }
var_export(isset(\$f[0])); echo PHP_EOL;
fclose(\$f);
" >/tmp/res_dim.php
php -d error_reporting=E_ALL -d display_errors=1 bin/vm.php /tmp/res_dim.php
'

Done when

  • Read emits Warning Trying to access array offset on resource (not Resource Error)
  • Write Error message matches Zend (Cannot use a scalar value as an array)
  • isset/empty on resource dim do not throw; values match Zend
  • Compliance .phpt under test/compliance/cases/
  • 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 10, 2026
  2. PurHur commented on Aug 10, 2026

    @PurHur
    OwnerAuthor

    claim: Worker lane B — starting this run

    Pillar 1: north-star5-fast ok; inventory OK 7362/7362 after doc regen; #30010/#30022 already claimed by sibling Lane B agents.

    Target: resource used as array subject — Zend Warning on read / scalar Error on write / soft isset|empty.

  3. PurHur commented on Aug 10, 2026

    @PurHur
    OwnerAuthor

    Merged #30038

    Verification

    • Repro under PHP_COMPILER_PROFILE=8.4: VM + JIT print Warning Trying to access array offset on resource, NULL, write Error:Cannot use a scalar value as an array, isset→false, empty→true
    • php vendor/bin/phpunit test/unit/ResourceDimFetchTest.php — OK
    • php vendor/bin/phpunit test/compliance/ResourceDimFetch30028VMTest.php — OK
    • php vendor/bin/phpunit test/compliance/ResourceDimFetch30028JITTest.php — OK

    Not covered: full compliance suite / differential-sweep / ci-local

  4. PurHur commented on Aug 11, 2026

    @PurHur
    OwnerAuthor

    Cleanup

    Deleted leftover remote agent/issue-30028-resource-dim-fetch after squash-merge (#30038). Work is on master; branch was post-merge noise only.

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 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