Am 26.12.2017 um 20:15 schrieb Sara Golemon:
On Tue, Dec 26, 2017 at 10:56 AM, Sebastian Bergmann <sebast...@php.net> wrote:
Am 26.12.2017 um 16:46 schrieb li...@rhsoft.net:
would you mind to explain this?

"Foo|Bar", "array|string", etc. (still) make no sense to me.

"scalar" makes sense to me although it is but an alias for
"bool|float|int|string".

Would you feel differently if we combined union types with type aliasing?

use Numeric = int | float;

function foo(Numeric $bar) { ... }

looks also good for me (while directed to someone else) but i would still prefer function foo(int|float $bar) because it's more native and hence works finally the same way for every code which targets the minimum PHP version where it's available

at the first look "use Numeric = int | float" looks gut, but you need namespaces to avoid collisions and the same thing could have a different meaning in different namespaces while "int|float" is very clear and could also be "myClassA|myClassB" without explicit declaration

what could also be a problem with "use Numeric = int | float" is what happens with existing code if someone changes that line by add another type while functions don#t expect that one as input at the time they where written - that can't happen with "int|float" in the function declaration because it's a case-by-case decision

anyways, it would be a good progress if PHP programmers would be able to declare type-hints for everything in hwatever way it is implemented

phpdoc even warns when documentation block and type hints differ and it's something to enhance code quality compared to "i can't declare a typehint at all or need 3 different functions"

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

Reply via email to