Skip to content

Language: parent:: and static:: resolution in extends chain (#101 phase 1b) #1858

Description

@PurHur

Category

language

Problem

#101 tracks single-parent extends and empty implements v1. Real PHP controllers and future self-host code also use:

class Child extends Parent_ {
    public function run(): void {
        parent::greet();
        static::factory();
    }
}

Without parent:: / static:: lowering, even a minimal extends landing forces duplicated method bodies.

php-src reference

  • Zend/zend_compile.czend_compile_static_call, parent / static class name resolution
  • Zend/zend_inheritance.c — parent method lookup, zend_get_parent_ce
  • Zend/zend_class.c — late static binding (Z_CE_SCOPE, called scope)
  • Zend/zend_vm_execute.hZEND_INIT_FCALL / static call opcodes with LSB

Repro (today)

<?php
class Parent_ {
    public static function tag(): string { return 'P'; }
    public function greet(): string { return 'hi'; }
}
class Child extends Parent_ {
    public function run(): string {
        return parent::greet() . static::tag();
    }
}
echo (new Child())->run();
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
/usr/bin/php repro.php   # Zend: hip

This compiler: compile error or wrong dispatch on parent:: / static:: until #101 + this issue land.

Goal

After #101 phase 1a (extends + method lookup chain on VM):

  1. Compile parent::method() to parent vtable dispatch
  2. Compile static::method() to late-static binding (class of call site, not instance)
  3. Reject parent:: on non-methods with clear compile error

Defer: parent::class, parent::$prop, traits (#144).

Scope (this repo)

Layer Files Notes
Compiler lib/Compiler.php Expr_StaticCall with parent / static class
VM lib/VM.php Parent chain walk; LSB uses declaring class
JIT lib/JIT.php Defer — VM PHPT first
Tests test/compliance/cases/classes/ parent_method_call.phpt, static_late_binding.phpt

Done when

Dependencies

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