Re: Consolidation of Traversable and array operations
| From: | Levi Morrison | Date: | Thu, 16 Jul 2015 15:23:17 +0000 |
| Subject: | Re: Consolidation of Traversable and array operations | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-87200@lists.php.net to get a copy of this message | ||
On Thu, Jul 16, 2015 at 4:38 AM, Michael Wallner <mike@php.net> wrote:
> On 16/07/15 11:26, Rowan Collins wrote:
>> Benjamin Eberlei wrote on 15/07/2015 21:19:
>>>
>>> But instanceof and anything related to Reflection or get_class or
>>> relevant code will fail on array.
>>
>>
>> Ah, yes, I hadn't thought of reflection type things. I don't think
>> instanceof would be a problem, because checking for any class or
>> interface other than Traversable would correctly return false; not sure
>> if it would make sense for "array() instanceof Traversable" to return
>> true or not...
>>
>
> Maybe some pseudotype like callable (e.g. iteratable) makes more sense then?
People have talked about creating types like so:
type Iterable = array | Traversable;
which could then be used as normal:
function foo(Iterable $f);
I understand that this is the second feature I have mentioned in this
train of thought that has not yet be officially proposed, but I think
it's relevant. Why special case a pseudo-type if we can have a generic
way of making them in user-land?