Skip to content

Language: Implement foreach (CFG → VM → JIT) #53

@PurHur

Description

@PurHur

Problem

No Foreach handling in lib/Compiler.php (grep shows no TYPE_FOREACH). Web apps iterate query params, DB rows, and template data constantly.

Goal

foreach ($arr as $k => $v) on packed and string-key hashtables.

Tasks

  • Lower PHPCfg\Op\Stmt\Foreach_ to opcodes (iterator state or indexed loop for packed arrays)
  • VM implementation in lib/VM.php
  • JIT lowering in lib/JIT.php (may reuse HashTable iterate helpers)
  • PHPT compliance cases: list arrays, $_GET key iteration (after dynamic superglobals)
  • Reference in macro tests if applicable

Acceptance criteria

foreach (['a' => 1, 'b' => 2] as $k => $v) { echo $k, $v; }

runs in VM and JIT.

Note

Associative arrays with string keys may depend on hashtable string-key maturity (separate issue).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions