To me type declarations help to make my code easier and more consistent.
Having multiple scalar types for a single function parameter is against this
goal since I need extra logic to handle this.
e.g. function foo(string | int | bool $bar) {} makes no sense in weak mode
since string can already handle int, bool, float, etc.
having different behavior between
foo("42"); function foo(string $b) {echo gettype($b);} // string
and
foo("42"); function foo(string | int $b) {echo gettype($b);} // integer
also makes no sense to me.
Things like string|array are useful (e.g. str_replace) since we can cast the
string easily to array and calling a string parameter with an array would give
a fatal error.
Regards
Thomas
Rowan Collins wrote on 03.06.2016 16:32:
> On 03/06/2016 15:24, Thomas Bley wrote:
>> maybe easier to get a majority from voters if defining union types only in
>> strict mode for 7.1?
>
> No go, I'm afraid.
>
> Strict types are opt-in at the point of calling the function, but union
> types are a feature of the declaration. If I write "function foo(int |
> string $a) {}", it is not up to me whether it's executed in strict mode
> or not.
>
> We'd have to throw an error of "function %s cannot be called without
> strict types enabled", and that goes against the entire premise of
> strict types as implemented.
>
> Regards,
> --
> Rowan Collins
> [IMSoP]
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php