Skip to content

Language: late static binding (static::method()) #1231

Description

@PurHur

Summary

Resolve static:: to the called class (late static binding) in inheritance hierarchies — including return-value chains where static::foo() propagates through nested calls.

Context

Problem

class Base { public static function id(): string { return 'base'; } }
class Child extends Base {
    public static function chain(): string {
        return static::id();  // must be 'child' when called as Child::chain()
    }
}

Today: VM may resolve static:: at compile time to the declaring class, or JIT skips with stub policy.

Implementation hints

Layer Files Notes
Compiler lib/Compiler.php Class_::SCOPE_STATIC on StaticCall — bind called class from runtime receiver
VM lib/VM.php resolveStaticCall($calledClass, $method) using get_called_class() semantics
CFG php-cfg Ensure static:: in return position does not constant-fold to declaring class
JIT lib/JIT.php, lib/JIT/Builtin/ SelfHostBuiltinPolicy — stub or deopt until VM green
Tests test/compliance/cases/language/late_static_binding*.phpt chain + static::class (#740 ✅ closed)
Self-host test/selfhost/ Add fixture if spine hits LSB in lib/

Search before coding

rg 'SCOPE_STATIC|LateStatic|static::' lib/Compiler.php lib/VM.php test/
rg 'late_static_binding' test/compliance/

Unblock order

VM called-class resolution (#1231) → JIT lowering → #1858 parent:: parity → self-host spine units

Acceptance criteria

  • Child::chain() returns 'child' in VM (./script/ci-fast.sh --filter LateStatic)
  • Nested return static::…() in web-safe fixtures passes compliance PHPT
  • JIT: explicit stub policy documented OR green on @group llvm subset
  • php script/capability-syntax.php row updated
  • Language features wave 2: JIT/syntax gaps tracker (#1222–#1235) #1238 table row marked ✅ when done

Verification (local / Docker only)

./script/ci-fast.sh --filter LateStatic
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  ./script/ci-fast.sh --filter LateStatic

No GitHub Actions.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions