> -----Original Message----- > From: Fleshgrinder [mailto:p...@fleshgrinder.com] > Sent: Tuesday, April 19, 2016 11:03 PM > To: Zeev Suraski <z...@zend.com> > Cc: internals@lists.php.net > Subject: Re: [PHP-DEV] Re: Improving PHP's type system > > On 4/19/2016 8:48 PM, Zeev Suraski wrote: > >> but it does not help with primitive types. :( > > > > Which is fine. Primitive types can and should get dedicated solutions. > There's really no need for allowing over creativity with userland-customized > scalar types. > > > > Hmmm... nope. I already brought various examples where I personally see the > strength of union types and that is exactly with the primitives.[1] > *int|string* is so powerful if you deal with MySQLi and its BIGINT stuff > because I can fully type hint it now (like the /mysqli/ extension does in C) > and > check very fast if I need to use GMP or not.
I can only repeat - primitive types can and should get dedicated solutions. There's really no need for allowing over creativity with userland-customized scalar types. If we think that a certain scalar definition makes a lot of sense, we can add it at the language level. There's no need to complicate the language, add syntax which makes no sense for objects and isn't really needed for scalars either. > interface HouseCat { > function drink(); > } > > interface Dog { > function eat(); > } > >-interface Lion { >+interface Lion extends HouseCat, Dog{ > function drink(); > function eat(); > } Pardon me saying this but it doesn't appear as if you've read what I wrote. Please take a look at the 'diff' I made in the definition of your Lion class, because without it, your sample and mine have little to do with each other. With that change in place, please reevaluate whether what you said is relevant: > A lion drinks and eats but is neither a HouseCat nor a Dog. This is dangerous > and introduces many potential hard to find bugs. Better don't touch it and go > for duck typing or the introduction of a dedicated > interface: *always* Nothing further. Zeev