Hi

Am 2025-03-20 21:27, schrieb Matt Fonda:
If an interface adds a method but makes no promises about what parameters it accepts, then why is it part of the interface in the first place--why
add a method that can't be used?

It would more cleanly allow for userland / PHPDoc-based generics, while still providing some engine-enforced type safety. Consider this example (not sure if I got the syntax completely right):

    /** @template T */
    interface Comparable {
        /** @param T $other */
        public function compareTo(never $other): int;
    }

    /** @implements Comparable<Number> */
    final class Number implements Comparable {
public function compareTo(Number $other): int { return $this <=> $other; }
    }

Without `never`, the `$other` parameter in the interface would need to be `mixed` or untyped, preventing the method in the `Number` class from adding the type to the engine-enforced signature, requiring it to check manually inside the method body.

To me this is another good example of how a small engine change can improve the safety of the language for all users, even when third party static analysis tools are required to make full use of it.

Best regards
Tim Düsterhus

Reply via email to