Re: [RFC] Union Types
| From: | Derick Rethans | Date: | Thu, 14 Apr 2016 09:25:07 +0000 |
| Subject: | Re: [RFC] Union Types | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92286@lists.php.net to get a copy of this message | ||
On Thu, 14 Apr 2016, Lin Yo-An wrote:
> On Thu, Apr 14, 2016 at 5:12 PM, Derick Rethans <derick@php.net> wrote:
>
> > I think what I am missing in the RFC is behaviour with scalar (weak)
> > typehints, and which type the variable in a class would be converted to.
> > Take for example:
> >
> > function foo(int|bool $var) { echo get_type( $var ), "\n"; }
> >
> > foo(5); I guess int(5)
> > foo(false); I guess bool(false)
> > foo(0.5); It could be either int(1) or bool(true)
> >
> > And what if the hint would be "bool|int" ?
>
> I think type conversion shouldn't be done internally, implicitly.
>
> Implicit conversion leads more confusion in the language. when you
> pass variables, you have to remember these conversion rules.
Sorry, we already have this with our weak scalar types. You can't make
union types not work with that.
cheers,
Derick