Re: Countable Type Hint

From: Date: Thu, 17 Nov 2016 14:59:10 +0000
Subject: Re: Countable Type Hint
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-96955@lists.php.net to get a copy of this message
On 17/11/2016 14:06, Josh Di Fabio wrote:
Apologies, I thought you were simply proposing the following: interface Countable {
    function count(): int;
}
No, what Craig is proposing is a type hint that covers both the existing Countable interface and primitives which are naturally countable. If the union types RFC had passed, you'd be able to say "array|Traversable $foo"; a recent RFC lets you instead say "iterable $foo". The suggestion is to add a keyword which similarly acts as "array|Countable $foo". Unfortunately, as others have pointed out, it can't be called just "countable", because that's the name of the existing interface. The principle seems sound though, assuming we don't want to go down the route of treating arrays as implementing interfaces. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#96955) next »