Skip to content

Language: static methods on user-defined classes (Expr_StaticCall) #2209

Description

@PurHur

Problem

#58 tracks instance methods ($obj->method()). #2185 ✅ closed ::class and minimal static factory patterns for MiniWebApp bootstrap PHPTs.

Many compiler and app trees still need user-defined static methods:

class Router {
    public static function fromConfig(array $config): self {
        return new self($config);
    }
}
Router::fromConfig($config)->dispatch($method, $route);

Today Expr_StaticCall on user classes is unsupported or JIT-throws while instance calls are in flight.

Goal

VM + AOT (+ JIT follow-up) for public static methods on user classes:

Implementation hints

Layer Files Notes
Compiler lib/Compiler.php Expr_StaticCall → internal func id + class context
VM lib/VM.php Dispatch without instance receiver
JIT lib/JIT.php Monomorphic static call for v1
AOT lib/AOT/ Same metadata as instance methods
Lint lib/Lint/UnsupportedRegistry.php Split from #58 instance methods
Tests test/compliance/cases/class_static_method.phpt VM baseline

Acceptance criteria

./phpc run -r 'class C{public static function id():string{return "ok";}} echo C::id();'
# → ok

./phpc lint examples/003-MiniWebApp   # no unsupported Expr_StaticCall on Router (if refactored to use static factory)

Harness:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter class_static_method'

Dependencies

Links

Activity

  1. added a commit that references this issue on May 26, 2026
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