Re: [RFC] Return Type Declarations
| From: | Larry Garfield | Date: | Tue, 29 Apr 2014 14:52:16 +0000 |
| Subject: | Re: [RFC] Return Type Declarations | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-73845@lists.php.net to get a copy of this message | ||
On 4/28/14, 8:19 PM, Levi Morrison wrote:
In other words, "let's punt on that until we figure out generics". With the new error message in the RFC I can work with that. Thanks. --Larry GarfieldAgreed; however I would rather have all kinds of Iterators and collection like object be able to type their values too. This would obviously fall outside of this RFC so I have specifically left this possibility open without directing its future too much.Special casing a generator's return type would be an inconsistency in the design. If you var_dump() something that returns generator it tells you it is a generator; this should match the type of the return value and anything else is unexpected. As an example, using a generator to fulfill an Iterator return type should succeed; special casing the Generator would complicate the code to achieve this. Special casing the generator would also infringe on other future ideas, such as adding generics to the language. All in all, special casing generators doesn't make sense.That makes sense from an engine point of view, certainly. From a user POV, I can still see it being the source of much confusion. I confess I've barely used generators so far (PHP 5.5 still having very small market penetration), but it feels natural to mentally align return type / return keyword and return type / yield keyword. It also means I have no way of declaring that a generator will always return items of type X, which seems like a valid thing to do.