On Thu, Nov 2, 2017 at 3:21 PM, Larry Garfield <la...@garfieldtech.com> wrote:
> > While I normally strongly agree with supporting all traversables, not > just arrays, in this case I don't think it works. Hmm.. You're right. Traversables would be best served by having another method to indicate their return type as part of the interface. Adding this to the existing traversable interface would be BC breaking. A new interface would be best and having another interface isn't without precedent - countable already exists. This new interface would the PHP engine on what to do. So, what about this syntax $a instanceof string[] If the engine sees this and it's an array, all the values are checked to see if it's a string. Else if $a references a generator, the return type definition of the generator will be checked, and a failure will occur if the generator doesn't declare its return type. Else if $a references an object and that object implements the SingleReturnType* interface then the method of that interface, getReturnType() is queried and it's return is checked to see if it matches. In the above case 'string' would need to be returned. I leave it to people smarter than me to find the holes in the above, but this moron thinks it might work. * Someone smarter than me can come up with a better name too :P