Re: Iterable Type Hint
| From: | Matthew Weier O'Phinney | Date: | Fri, 13 Jul 2012 13:41:43 +0000 |
| Subject: | Re: Iterable Type Hint | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61196@lists.php.net to get a copy of this message | ||
On 2012-07-12, Stas Malyshev <smalyshev@sugarcrm.com> wrote:
> > For non-interchangeable types it is already strict by definition. I
> > don't see a problem with type hints that make life easier on both the
> > caller (by generating better error messages) and the callee (by having
> > to write less boilerplate type verification code).
>
> It doesn't make the life of the caller easier. On the contrary, it makes
> each call into a minefield - will it blow up with a system-level error
> when you call it?
I think you're reading way more into this, or didn't read the same
sample I did from Anthony.
foreach() allows an array or a Traversable object. The proposal is to
create a typehint that spans the set of (array + Traversable) so that
folks don't have to do a check in each and every method where they want
to accept both so they can iterate. I've written the same or similar
checks to what Anthony posted hundreds of times, and seen it many, many
more than that.
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc