Skip to content

Language: (array) object cast — TYPE_CAST_ARRAY VM opcode (Zend cast_object parity) #3328

Closed

Description

@PurHur

Category

language | runtime

Problem

Zend PHP allows casting objects to arrays via (array) $obj, producing public property keys (with \0*\0 / \0Class\0 prefixes for protected/private per scope rules).

This compiler lowers (array) casts to OpCode::TYPE_CAST_ARRAY (lib/Compiler.php) but the VM handler is missing — runtime aborts with LogicException: VM OpCode Not Implemented: TYPE_CAST_ARRAY.

php-src reference

Repro (today)

<?php
class C {
    public int $x = 1;
    private int $secret = 2;
}
var_export((array) new C());
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'

Zend PHP: array('x'=>1, "\0C\0secret"=>2, …) (scope-dependent)
This compiler: fatal TYPE_CAST_ARRAY not implemented

Scope

  • Implement TYPE_CAST_ARRAY in lib/VM.php (public properties minimum; protected/private prefixes optional follow-up)
  • Mirror in JIT/AOT if cast sites are compiled (or document VM-only initially)
  • test/compliance/cases/language/cast_array_object.phpt

Done when

  • (array) new C() on a class with public properties returns expected key/value map
  • (array) on array is identity / copy per Zend
  • ./script/ci-fast.sh --filter cast_array_object green

Links

Activity

  1. added
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on May 29, 2026
  2. PurHur commented on May 29, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-implementer-lane-c — starting this run (lane C queue: all implementation-ready language issues have open PRs; #3328 is unclaimed VM parity)

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-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions