Hi!

> It's about the perception of consistency. "Oh, I can do this! Neat:"
> 
> function neat(Foo | Bar $a) { ... }

You shouldn't be able to do this, because it makes no sense - why would
a function accept two random types and only them? That's probably a bad
design - it should be one type or two functions.

> "But I can't do this? WTF?"
> 
> catch (FooException | BarException $ex) { ... }

But this makes total sense - you routinely catch more than one type of
exceptions, just not you write it catch(Foo) ... catch(Bar...). You very
rarely have functions that do exactly the same with two types, and only
those. The usage is different.

I do not think approach "it should look the same, no matter what the
usage is" is right.

> And vice-versa. The perception revolves around the fact that both appear
> to be signatured, regardless of how they're implemented in the engine.

But that's not what they do. Function says "I accept only parameter of
this type, and it's an error if it's not". Catch says "I will process
exception of this type, but if it's not, other catch clause may process
it". You don't chain functions like that, but you do chain catch
clauses. Again, different usage.
-- 
Stas Malyshev
smalys...@gmail.com

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

Reply via email to