Skip to content

Language: Magic methods __get/__set/__call/__toString — JIT lowering (phase 2 of #146) #4066

Description

@PurHur

Category

language

Problem (phase 2 of #146)

VM and AOT already dispatch __get, __set, __call, __callStatic, and __toString on user classes (see docs/capabilities-syntax.md — VM yes, AOT yes). JIT still deopts or aborts on undeclared property access / missing methods instead of lowering magic dispatch in LLVM IR.

Framework-style code ($obj->$name, (string) $plugin, lazy config objects) compiles under VM but bin/jit.php / MCJIT paths fail or fall back to VM for whole functions.

php-src reference

  • Zend/zend_object_handlers.c — zend_std_read_property, zend_std_write_property, zend_std_get_static_method, zend_std_get_method, zend_std_cast_object_tostring
  • Zend/zend_execute.c — ZEND_FETCH_OBJ_*, ZEND_INIT_METHOD_CALL slow paths

Repro (JIT failure today)

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

Zend / VM: 1box
JIT (today): compile-time or runtime abort on unknown property x / missing __toString lowering (see JITTest magic-method skips).

Scope

  • lib/JIT/ — property fetch/store slow paths when declared property lookup misses (PropertyFetchHelper, RuntimeIndirectInstanceMethodCall)
  • lib/Compiler.php — avoid treating all dynamic $obj->prop as hard errors when class defines __get/__set
  • test/compliance/cases/language/magic_methods_jit.phpt
  • test/compliance/JITTest.php — remove or narrow VM-only skips for magic cases

Done when

  • Repro prints 1box under bin/jit.php without VM fallback
  • __call / __callStatic JIT smoke passes for at least one arity
  • docs/capabilities-syntax.md magic-methods row shows JIT: yes (regenerate matrix)
  • ./script/ci-fast.sh --filter 'magic_methods_jit|MagicMethod' green

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