Em dom, 3 de fev de 2019 às 17:19, Rowan Collins <rowan.coll...@gmail.com> escreveu:
> On 03/02/2019 19:00, Christoph M. Becker wrote: > > On 03.02.2019 at 19:39, David Rodrigues wrote: > > > >> overload function sum(int $a, int $b): int; > >> overload function sum(float $b, float $b): float; > > Which function would sum(17.4, 42) call? Also consider: > > > > sum(PHP_INT_MAX, PHP_INT_MAX) > > > > vs. > > > > sum(PHP_INT_MAX+1, PHP_INT_MAX+1) > > > Yes, marking overloaded functions explicitly definitely helps, but I > think the dispatch part is more complex than it first seems. Classes and > interfaces require a bit of subtlety too: > > class Foo {} > class Bar extends Foo {} > > overload function foo(Foo $a, Foo $b); > overload function foo(Foo $a, Bar $b); > overload function foo(Bar $a, Foo $b); > > foo(new Bar, new Bar); > This example could be complex. So, what other languages does in cases like that? Java, for instance. > > There are plenty of cases more complex than this, e.g. when a class > implements multiple interfaces, and you need to find a matching signature. > > That's not to say it's impossible, just don't underestimate the edge > cases you'll need to legislate for. > > Oh, and note that return types can't participate in overloading, because > there's no concept of "desired type" to choose between them. > You are right, in general. But still is possible identify the desired type if return is used as argument to a typed parameter, but I still thinks that it could not be done in general terms, so maybe we should not includes return type to overloading. > > Regards, > > -- > Rowan Collins > [IMSoP] > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- David Rodrigues