Re: Iterable Type Hint
| From: | Gustavo Lopes | Date: | Thu, 12 Jul 2012 17:40:31 +0000 |
| Subject: | Re: Iterable Type Hint | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61182@lists.php.net to get a copy of this message | ||
Em Thu, 12 Jul 2012 18:30:43 +0200, Stas Malyshev <smalyshev@sugarcrm.com> escreveu:
I agree with everything Stas said. Additionally, while "callable" has a problem that "iterable" wouldn't have -- namely, whether something is callable is context sensitive* -- its implementation was accompanied by a homogenization of callable types (e.g., you can now do $a = $func = ['A', 'foo']; $a()). Traversable types are by no means interchangeable. In fact the only thing they have in common is that can be passed to foreach. On everything else, they're different. It makes to sense to a pseudo-type for two entities that all they have in common is that one property. * Example: class A { public static function foo(callable $r) { B::foo($r); } private static function test() {} } class B { public static function foo(callable $r) {} } A::foo(['A', 'test']); -- Gustavo LopesWould it be worth while adding a new type hint that checks for this condition? I'd propose Iterable:I see more and more multiplication of weird ad-hoc type checks. First we had "callable", now "traversable", then we invent more and more weird functional types with complex logic. I don't like this development at all. It's ad-hoc introducing of half-baked, unstandartized, undesigned strict typing. Strict typing is not a good idea for PHP, and weird strict typing based on complex conditions hidden from the user is even worse IMO.