Skip to content

Language: ArrayAccess $obj[$k] += n TypeError mixed + int — Zend writes through by-ref offsetGet (zend_vm_def.h) #31947

Description

@PurHur

Category

Language · php-src-strict / ArrayAccess assign-op

Problem

$obj[$k] += n (and -=, *=) on a user ArrayAccess object whose offsetGet returns by reference must read the stored int and write the result back (Zend ZEND_ASSIGN_DIM_OP). The VM instead TypeErrors Unsupported operand types: mixed + int — the dim-fetch used for the assign-op is typed as the declared mixed return rather than the live integer. Postfix ++ on the same object already matches Zend.

Probed 2026-08-17 @ c202af3d73 — Zend 8.2.32 vs php bin/vm.php.

Repro Zend 8.2.32 VM
$a[0]++ with &offsetGet backing [0=>1] inc=2 inc=2 (parity OK)
$a[0] += 2 plus=3 TypeError: Unsupported operand types: mixed + int
$a[0] *= 3 mul=3 TypeError: Unsupported operand types: mixed * int

Distinct from closed #3446 / #5460 (non-ref offsetGet nested write → notice / Error). This is the by-ref assign-op path that must succeed.

php-src reference

PHP implementation target

  • lib/VM/ArrayAccessDimension.php — read() for assign-op must yield the live value type, not the declared mixed
  • lib/VM.php — dim assign-op on ArrayAccess objects; reuse by-ref offsetGet then offsetSet
  • JIT/AOT: lib/VM/VmArrayAccess.php after VM green
  • No new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_arrayaccess_assign_op.php'
./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_arrayaccess_assign_op.php'

Done when

  • VM prints inc=2 / plus=3 / mul=3 (matches Zend); no mixed + int TypeError
  • JIT/AOT same on the repro (or documented skip with reason)
  • Compliance .phpt under test/compliance/cases/language/
  • php-src-strict; no php-compiler-strict shortcut

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