Skip to content

Language: Magic methods (__get, __set, __call, __toString) #146

Description

@PurHur

Category

language

Status (refreshed 2026-06-01)

VM + AOT magic dispatch is implemented for __get, __set, __call, __callStatic, and __toString (see docs/capabilities-syntax.md — VM yes, AOT yes). Compliance: test/compliance/cases/language/ magic-method PHPTs.

Remaining gap: JIT still deopts or errors on undeclared property access instead of lowering magic handlers — tracked in #4066 (filed this run).

This issue remains the umbrella tracker for magic-method parity; close when VM + JIT + AOT matrix row is all yes.

Problem (original)

Property fetch on objects without declared properties fails in VM today. Frameworks, ORMs, and debug helpers rely on __get, __set, __call, and __toString magic dispatch when a member is missing.

003-MiniWebApp uses explicit properties on Router only — not blocking the north-star app — but plugin-style routing, lazy config objects, and (string) $obj casts need magic methods.

php-src reference

Repro (JIT — still failing)

<?php
class Box {
    private array $data = ['x' => 1];
    public function __get(string $name) {
        return $this->data[$name] ?? null;
    }
}
$o = new Box();
echo $o->x, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'    # expect: 1
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php repro.php'   # JIT gap

Scope

Done when

Links

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