On Mon, Mar 10, 2025, at 20:05, Daniel Scherzer wrote:
> Hi internals,
> 
> I'd like to start discussion on a new RFC about allowing `never` for 
> parameter types when declaring a method.
> 
> * RFC: https://wiki.php.net/rfc/never-parameters-v2
> * Implementation: https://github.com/php/php-src/pull/18016
> 
> -Daniel

Hey Daniel,

This looks interesting. I'm not sure that I like "never" as a parameter type 
and while it "technically" doesn't violate LSP, it seems like a backdoor to 
doing just that:

abstract class Point {
  function add(never $other);
  function subtract(never $other);
}

class Vector2 extends Point {
  public function add(Banana $other) {}
  public function subtract(Football $other) {}
}

There's basically only a gentleman's agreement that a subclass will implement 
things in a way that makes sense. I would also personally prefer associated 
types:

abstract class Point {
  public type OtherPoint;
  public function add(OtherPoint $other);
  pubic function subtract(OtherPoint $other);
}

This at least lets you ensure the "other point" is the same type in both 
functions, though personally, I'd rather just have generics.

— Rob

Reply via email to