[GIT-PULLS] [php-src] PR #22635: feat: Implement extension methods (RFC prototype, phase 1)

[email protected] (hollyschilling)
Newsgroups php.git-pulls
Message-ID <[email protected]>
Pull Request: https://github.com/php/php-src/pull/22635
Author: hollyschilling

Adds Swift-style extension blocks that declare additional methods for an existing class or interface, resolved at call time only when the receiver does not define the method itself:

    extension Target {
        public function helper(): string { /* $this is the receiver */ }
    }

- `extension` is a contextual keyword (T_EXTENSION), lexed only when followed by another identifier, mirroring the enum technique; a `extension extends/implements` carve-out preserves classes named "extension", and T_EXTENSION is semi-reserved.
- Extension blocks compile to a synthetic final anonymous class; a new ZEND_BIND_EXTENSION opcode (212) registers its methods, keyed by the lowercased resolved target name, when the declaration executes (load-gated, like function declarations).
- zend_std_get_method gains one fallback on its miss path: real method, then __call trampoline, then extension registry lookup (most-derived target first: inheritance chain, then interfaces). Registered methods are flagged ZEND_ACC_NEVER_CACHE so the polymorphic inline cache and JIT are bypassed in this prototype.
- Methods only: properties, constants, and cases are compile errors.
- Indirect invocation (callables, reflection, method_exists) deliberately does not see extensions.

PROTOTYPE LIMITATIONS: the registry is a process global, so user-class method pointers dangle after request 1 in multi-request SAPIs (CLI only until it moves into zend_executor_globals); duplicate registrations are silently ignored (first wins).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.