Skip to content

feat: support static interface methods (PHP 8.3+)#458

Open
chadmandoo wants to merge 2 commits into
illegalstudio:mainfrom
chadmandoo:upstream-pr/static-interface-methods
Open

feat: support static interface methods (PHP 8.3+)#458
chadmandoo wants to merge 2 commits into
illegalstudio:mainfrom
chadmandoo:upstream-pr/static-interface-methods

Conversation

@chadmandoo

Copy link
Copy Markdown
Contributor

What

Adds support for PHP 8.3+ static interface methods — interfaces may now declare public static function members, and implementing classes satisfy them with a static method.

interface Previewable { public static function previews(): array; }
final class C implements Previewable {
    public static function previews(): array { return ['a', 'b', 'c']; }
}
echo implode(',', C::previews()); // a,b,c

Previously this errored at the schema stage: "Static interface methods are not supported yet".

How

  • InterfaceInfo gains static_methods (+ static_method_order), recorded apart from instance methods — static dispatch is by class, so they take no vtable slot.
  • The interface schema builder routes a static interface method into static_methods (and inherits parent-interface static methods) instead of rejecting it.
  • A new validate_interface_static_method enforces conformance: a concrete class must declare a compatible static method (an abstract class may defer); a missing implementation errors with "Class X must implement static interface method I::m".

Verification

  • Byte-parity vs PHP 8.5 for a static-interface-method call (C::previews() → identical output).
  • Negative case (class omits the static method) correctly errors.
  • Instance interfaces unaffected; no regressions in the interface/instanceof suites.

Interfaces may now declare `public static function` members. Adds
InterfaceInfo.static_methods (+ static_method_order), recorded apart from
instance methods (no vtable slot — static dispatch is by class, not vtable).
Implementing classes satisfy them with a static method, validated by a new
validate_interface_static_method (a concrete class omitting one errors; an
abstract class may defer). Parent interfaces inherit static methods.

Byte-parity regression test (static interface method + impl + call). Missing
impl correctly errors; instance interfaces unregressed (the 2 pre-existing
instanceof "linker failed" env failures are unchanged on clean integration).
AIC epic illegalstudio#483 / EC-4 (illegalstudio#487).

(cherry picked from commit 8db0923)
(cherry picked from commit 7e1943f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant