Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:104080
Return-Path: <rowan.collins@gmail.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 97017 invoked from network); 3 Feb 2019 22:38:54 -0000
Received: from unknown (HELO mail-wm1-f44.google.com) (209.85.128.44)
  by pb1.pair.com with SMTP; 3 Feb 2019 22:38:54 -0000
Received: by mail-wm1-f44.google.com with SMTP id t200so11253073wmt.0
        for <internals@lists.php.net>; Sun, 03 Feb 2019 11:19:36 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=subject:to:references:from:message-id:date:user-agent:mime-version
         :in-reply-to:content-transfer-encoding:content-language;
        bh=3i2SoJYe8T/bat4iYAFtaIPx5B3Eh9qYKXbRyI1V+N0=;
        b=ZOKElKRRQY4g9Fl2QsU2UyvOHXy7K480I/412pgX7KpwN59VG59a0AGYut8xCHQ3TL
         AL6em60vm83iEnFvt/psXD4/Coq3RdI1mOufSCWbgxQvaiOKppFFS6dlkIds882wLZR8
         Cv9L6cZ3uuKRIVedPnhjC7yfygL5VTb6XOuk8Wx5LqnngBKi4O26aWCT7Q7PH+xsXbvx
         zSBFyEW20RQIIrXS92jDV495+FUA9+VrvUJpYJvTpWJnA337CyzaQjjRymtlg2hltyjD
         IcGhlTcrrl3TuJa7SKKyFCBJYQS4GniLnDyHPkVQ1PotPljTemAiZawpwMUyOVe38hfk
         B6nw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-transfer-encoding
         :content-language;
        bh=3i2SoJYe8T/bat4iYAFtaIPx5B3Eh9qYKXbRyI1V+N0=;
        b=Rr9mLtKH4b0YoSZkQREWR6dJ52Z1xZKG5hhIhQnJloCMgbI4w73Zf6nnXxmc0uMqjb
         gJgAf4ATDB8AGDbyh1h2dZd4JFWvg1iZTLlChVBZ2gRbnNgMMW8ybHC+MPJIVnKkDMoh
         g4IqdPInAMapY3lH84sanS+ruRBq9sMrXnRewsaoDCqZzqMVzALiJtXpSF42O74a94mS
         DVQz8jJl1M02InBcJ5ZmXJ1do8GX0LhT5BeTtTLu+ENMPWvlBc8vLoJ4or2dCOTwhvDT
         1eMxZCSRVGSenBDMlRyAl9pcIB2APkJvD4U0euh6Htjk4UmaOU70ind2GgvWdFKvyeMQ
         qUsA==
X-Gm-Message-State: AHQUAuYgSF78qFnOt3AIK6smUwc4AZne7khzeq5BvzdsYXFp5oYPBdRr
	DXLIhj24tq6MmMavsYIqwUzhOfBn
X-Google-Smtp-Source: AHgI3IZiRkl+ufDlx4u3K/tT03TBocsjGNEyctZ+BOTiRnZv+k/kBekIN3BwoniW9wlOvyV/TsxZQg==
X-Received: by 2002:a1c:2804:: with SMTP id o4mr10990097wmo.150.1549221575071;
        Sun, 03 Feb 2019 11:19:35 -0800 (PST)
Received: from [192.168.0.16] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115])
        by smtp.googlemail.com with ESMTPSA id w16sm20361407wrp.1.2019.02.03.11.19.34
        for <internals@lists.php.net>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 03 Feb 2019 11:19:34 -0800 (PST)
To: internals@lists.php.net
References: <CAEsg9X1EU5hjiXZQHr5XTitsL1hdiFUAWVB-kOXwSGQ4FdLs2g@mail.gmail.com>
 <b6455813-07fe-8d47-0f34-61d4113eed56@gmx.de>
Message-ID: <11367213-db84-bbdf-c125-4b105e08b8b6@gmail.com>
Date: Sun, 3 Feb 2019 19:19:33 +0000
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101
 Thunderbird/60.5.0
MIME-Version: 1.0
In-Reply-To: <b6455813-07fe-8d47-0f34-61d4113eed56@gmx.de>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Language: en-GB
Subject: Re: [PHP-DEV] Re: PHP 8: Method Overloading, The Ressurection
From: rowan.collins@gmail.com (Rowan Collins)

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);

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.

Regards,

-- 
Rowan Collins
[IMSoP]