Hacker News new | ask | show | jobs
by krapp 4520 days ago
It would be nice if you had an option, like

   function foo(weak int $i)
for weak type hinting, and

   function foo(int $i)
for strict. The arguments for weak type hinting make sense but sometimes you don't want any ambiguity.
2 comments

Or something like "numeric" that allows both int and float, as well as any string that would pass the test of is_numeric(). It would be just like class inheritance: int and float would be treated as subtypes of "numeric".
Yeah, as long as there's a way to specify a strict type then I'd be happy. Libraries and other code that's intended to be used by 3rd parties could probably benefit from weak type hinting, but internally I'd really like the confidence that comes from strict hinting.