Follow

Much ado about null (and a more -friendly alternative to monads you can use today!)

peakd.com/hive-168588/@crell/m

@Crell A possible correction to your article: we have a bottom type as of PHP 8.1. It's not void; it's "never". (See the discussion under the heading "Variance" on wiki.php.net/rfc/noreturn_type)

@mwop Hrm, possibly. I... don't quite grok how they're not both bottom types, though. Other than "never" being "more bottom"? Would void have qualified as a bottom type before never snuck in below it?

@Crell If a parent interface/class defines a non-void, non-null type as the return type, you cannot redefine it as void in the child (PHP considers it an incompatible signature). You CAN redefine it as never, however.

Essentially, we never had a bottom type before.

@mwop That strikes me as weird, but I will take your word for it and update. :-) Thanks.

@Crell Create an interface that defines a method that returns a type (e.g. int, object, etc. — anything but void, null, or mixed), and then create an implementation that uses void. This results in a fatal. Switch it to never (PHP 8.1 only), and it's valid.

It was one of the reasons for adding the type, and part of why it was also proposed later for arguments. The problem is that the name ("never") as a type for an argument is hard to grok, so that proposal failed.

Sign in to participate in the conversation
PHP Community on Mastodon

Open source. Open community. We are dedicated to building and enriching the PHP community.