On 15.06.2016 at 00:51, Levi Morrison wrote:

> On Tue, Jun 14, 2016 at 2:43 PM, Zeev Suraski <z...@zend.com> wrote:
>>
>> On 14 ביוני 2016, at 22:53, Levi Morrison <le...@php.net> wrote:
>>
>> I'm personally against Union types because it makes no sense for classes
>>
>> I've been over this before but I'll repeat it here for completeness:
>> this is not true.
>>
>> There are more than enough constructs in PHP to handle all these use cases,
>> and handle them nicely.  We don't need specialized constructs for every use
>> case.
> 
> To clarify here, you are saying we don't need unions because they are
> a special case, yes? But you previously stated you are in favor of
> special casing the language types such as numeric?
> 
> These are at odds.

In my opinion, there have to be always compromises when designing a
language for practical purposes.  Theoretically, it would not even be
necessary for PHP to have scalar types; everything could be done with
(immutable) objects as well.  However, we do have scalar types, and
these are likely to stay, so it seems reasonable to me to add a few
special cases to our type system covering this issue (say, Stringable,
Iterable, numeric, Invokable).

Adding union types as a general mechanism, on the other hand, adds a new
level of complexity for the user which is orthogonal to the classical OO
type system, at least when type definitions will be added, what I
estimate will not take long, due to the verbose inline union typing.
And that is easily going to get out of hand, because independent
libraries might introduce their own LIB\numeric, for instance,
potentially with slightly different definitions (e.g. with or without GMP).

Finally, I don't consider |false a very reasonable thing, because the
respective functions could return a nullable type as well, what would in
my opinion be better anyway for the famous strpos(), which requests the
position of $needle in $haystack, what should be either a numeric index
or NULL (== not present).  And at least built-in functions may also
return NULL for wrong argument types, which would require to type their
return values as X|false|null to be exact.

-- 
Christoph M. Becker

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to