Re: Inline typecasting / typehinting for classes and interfaces
| From: | Stas Malyshev | Date: | Wed, 15 Aug 2012 09:06:38 +0000 |
| Subject: | Re: Inline typecasting / typehinting for classes and interfaces | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62174@lists.php.net to get a copy of this message | ||
Hi!
> All right, your method accepts an array of objects, instances of Foo. How do
> you enforce this contract?
You are trying to re-invent generics/parametrized types and bolt it onto
PHP. I still don't think it is a good idea - PHP is not a statically
typed language. Just check you array elements if you need.
> What's your proposal? From the discussion so far, I'd guess it's peppering
> out code with if-s with the same error written everywhere everytime we check
> the item in an array.
By "peppering" here you mean one if. Yes, this is my proposal - if you
need to do a check - do a check.
> The same applies to typehints, so make up your mind.
No it does not. But this is exactly why I think one of the problems with
strict typing in arguments is - because people take it and starting to
use it as a legitimation of turning PHP into weird hybrid of dynamically
typed language with random islands of static typing popping in random
places. I still do not think it is a good idea.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227