Re: Inline typecasting / typehinting for classes and interfaces
| From: | Stas Malyshev | Date: | Wed, 15 Aug 2012 08:02:54 +0000 |
| Subject: | Re: Inline typecasting / typehinting for classes and interfaces | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62165@lists.php.net to get a copy of this message | ||
Hi!
> My proposal is simple: behave as an inline type hint. The same type hints
> you have in arguments lists, but inline. The use case is "I want to make
> sure this value is of this type" and a side benefit is the IDE can know the
> variable is of this type too (for autocompletion purposes).
What's wrong with instanceof? You can then throw fatal error if you
want, it's just two lines:
if(!($foo instanceof Bar)) {
trigger_error(E_USER_ERROR, "Wrong foo!");
}
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227