Re: [PHP-DEV] Countable Type Hint

2016-11-23 Thread Daniel Morris
If somehow the Countable type-hint can absorb primitives, another example I would like to see with similar behaviour is Serializable, the type-hint currently allows classes implementing the Serializable interface to be serialized, but primitives (which are serializeable) can not be serialized when

Re: [PHP-DEV] Countable Type Hint

2016-11-21 Thread Stanislav Malyshev
Hi! > Nothing prevents it? As far as I'm aware there's no current way to type > hint Countable or array. No, there's not - as there's no way to make other complex type conditions as type. You still can check for it, or just use count(). > How would one add an interface that includes Countable

Re: [PHP-DEV] Countable Type Hint

2016-11-20 Thread Niklas Keller
2016-11-19 19:18 GMT+01:00 Larry Garfield : > On 11/17/2016 10:12 AM, Niklas Keller wrote: > >> 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

Re: [PHP-DEV] Countable Type Hint

2016-11-19 Thread Craig Duncan
On 19 November 2016 at 18:36, Stanislav Malyshev wrote: > > > Should I bring *countable* to RFC? > > Nothing prevents one from having such interfaces or classes or traits if > they need it. I don't see any need of adding more special cases into the > language. Special cases

Re: [PHP-DEV] Countable Type Hint

2016-11-19 Thread Stanislav Malyshev
Hi! > Does anybody have any thoughts on this? > Should I bring *countable* to RFC? > Should I bring *arraylike* to RFC? Nothing prevents one from having such interfaces or classes or traits if they need it. I don't see any need of adding more special cases into the language. Special cases are

Re: [PHP-DEV] Countable Type Hint

2016-11-19 Thread Larry Garfield
On 11/17/2016 10:12 AM, Niklas Keller wrote: 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

Re: [PHP-DEV] Countable Type Hint

2016-11-17 Thread Niklas Keller
> > 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

Re: [PHP-DEV] Countable Type Hint

2016-11-17 Thread Rowan Collins
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

Re: [PHP-DEV] Countable Type Hint

2016-11-17 Thread Christoph M. Becker
On 17.11.2016 at 15:06, Josh Di Fabio wrote: > Apologies, I thought you were simply proposing the following: > > interface Countable > { > function count(): int; > } We already have this as of PHP 5.1.0, see . :-) -- Christoph M. Becker --

Re: [PHP-DEV] Countable Type Hint

2016-11-17 Thread Jordi Boggiano
On 17/11/2016 13:52, Craig Duncan wrote: Hi everybody Following on from the recent rfc for *count()* ( https://wiki.php.net/rfc/counting_non_countables) and the one for *iterable* (https://wiki.php.net/rfc/iterable) it would be useful if there was a `countable` type hint: function

Re: [PHP-DEV] Countable Type Hint

2016-11-17 Thread Josh Di Fabio
On Thu, Nov 17, 2016 at 2:01 PM Craig Duncan wrote: > On 17 November 2016 at 13:50, Josh Di Fabio wrote: > > What's the benefit of such an interface? Why not simply ask for `int > $count` in your param list instead? > > > Using the example from my

Re: [PHP-DEV] Countable Type Hint

2016-11-17 Thread Craig Duncan
On 17 November 2016 at 13:50, Josh Di Fabio wrote: > What's the benefit of such an interface? Why not simply ask for `int > $count` in your param list instead? > Using the example from my original email, it's a bit awkward to always have to pass the count of a countable:

Re: [PHP-DEV] Countable Type Hint

2016-11-17 Thread Josh Di Fabio
On Thu, Nov 17, 2016 at 1:00 PM Levi Morrison wrote: > On Thu, Nov 17, 2016 at 5:52 AM, Craig Duncan wrote: > > Hi everybody > > > > Following on from the recent rfc for *count()* ( > > https://wiki.php.net/rfc/counting_non_countables) and the one for >

Re: [PHP-DEV] Countable Type Hint

2016-11-17 Thread Levi Morrison
On Thu, Nov 17, 2016 at 5:52 AM, Craig Duncan wrote: > Hi everybody > > Following on from the recent rfc for *count()* ( > https://wiki.php.net/rfc/counting_non_countables) and the one for *iterable* > (https://wiki.php.net/rfc/iterable) it would be useful if there was a >

[PHP-DEV] Countable Type Hint

2016-11-17 Thread Craig Duncan
Hi everybody Following on from the recent rfc for *count()* ( https://wiki.php.net/rfc/counting_non_countables) and the one for *iterable* (https://wiki.php.net/rfc/iterable) it would be useful if there was a `countable` type hint: function foo(countable $thing) { if (count($thing) > 0) {