Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93841 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84378 invoked from network); 6 Jun 2016 12:22:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jun 2016 12:22:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=codekestrel@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=codekestrel@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 74.125.82.46 as permitted sender) X-PHP-List-Original-Sender: codekestrel@googlemail.com X-Host-Fingerprint: 74.125.82.46 mail-wm0-f46.google.com Received: from [74.125.82.46] ([74.125.82.46:36392] helo=mail-wm0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/61-10476-B1B65575 for ; Mon, 06 Jun 2016 08:22:52 -0400 Received: by mail-wm0-f46.google.com with SMTP id n184so89665334wmn.1 for ; Mon, 06 Jun 2016 05:22:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=qDl6SwXkAk0cTnBeoB85nRwZuplbGhbeLqG7O2po5OA=; b=xcSXOP55tYoFZYinlPf/issuiePh3Y2yox+10OMXMqFeFsavuJdulrTIVgayAsLyna FE9ycmC72GAdWF2Mpdqz8Fg2JiWq3dPVv5/psqhSAN5y57O/j4KFKqJhcKySKyxtqACR 7fmM7ernaImxM12nWOvZcRXXwCdu22TCE+t51ZrCZkv2hymHtHmH0QS6eGCbsdADt3w7 u535+vx5LYpFP6P2puq4kPh01opxW1zzilw4nxSP6jxfxPVf/Y8LaEQbV+/+igxxvDiK TyJJQ+BfOfRFj31FBzhpFZjsrrdd71fkkeUTVpLw6yXefOth+Hv4uIV/xrIn/wyNP+v8 x6eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=qDl6SwXkAk0cTnBeoB85nRwZuplbGhbeLqG7O2po5OA=; b=bd/qYTX5AqOgtyiUVyWJKEpgR/2kVd+6GcogRGnyr7LQj/Tjyu6eEI3SoGmTWeBEDb 2N0PQZ/HZA1f0CX22moyzrf3y54IP0XgwMTK7AsEXvcKbbMEctlzsbq+X+yF2K3eVOhR 41hOwaRr0QrwA50jIDielxU3W0z6U5Vn5tX5vK+HtJvJhHSbX3bQzLXz+h28ncceAG3N Dymi4KS2kgN019JeFUrf/eHx/DnVBIr0Udidh25Hr45qKnLwTPzdVKWhCMFEavozt4Zc 20BfiDxLoSDv3AB9SiY/c2GKP1XQC4U2XeR+iHHhNY+ddgtEtlhsTBbMH0CWK9YlSNcB Yi6A== X-Gm-Message-State: ALyK8tI5KvF7tiERh2CLAV5G69a+MiMwYWlsMctLD3ZcZbgat9Rl7s8RSUC+jUmUjN+SKBz8ceeKjU2HvLTPLA== MIME-Version: 1.0 X-Received: by 10.194.116.69 with SMTP id ju5mr15313967wjb.101.1465215768961; Mon, 06 Jun 2016 05:22:48 -0700 (PDT) Received: by 10.28.130.2 with HTTP; Mon, 6 Jun 2016 05:22:48 -0700 (PDT) Received: by 10.28.130.2 with HTTP; Mon, 6 Jun 2016 05:22:48 -0700 (PDT) In-Reply-To: <37e3870e-9fe4-af80-3e75-2751e33b1a36@gmail.com> References: <8b3055e5-706d-ae5e-bbe6-de6ba292ca5b@gmx.de> <9b9b33c0-03ff-c147-5105-e4f02901ce6e@gmail.com> <37e3870e-9fe4-af80-3e75-2751e33b1a36@gmail.com> Date: Mon, 6 Jun 2016 13:22:48 +0100 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=001a1130ccf06dac4405349b21a6 Subject: Re: [PHP-DEV] Opinion on function/method name overloading From: codekestrel@googlemail.com (Dominic Grostate) --001a1130ccf06dac4405349b21a6 Content-Type: text/plain; charset=UTF-8 Yes, I can see what you mean. Should a float prefer a string or an int? I don't know. That would be a issue unless an additional method of prioritising were involved. Perhaps if attributes get in there will be a solution: <> function foo(int $a) {} <> function foo(string $a) {} Yet as complicated as overloading would be to begin with, this I feel would make it even worse lol. Just for clarifies sake I'll explain briefly what I feel the benefits are, and perhaps we can see if it's worth discussing further: - No need to conjure new names. A biggy IMO. - A new way of overriding. If you want to override a base class method by capturing an argument of lower bounds, you won't need to do an instance check and decide on super or alternative code. - Performance enhancement over emulated overloads such as __call, variadic and anonymous arguments. Regarding the last point, I've mocked up a basic benchmark to illustrate the difference in performance when comparing emulated overloading with alternative functions. I expect native support for overloading to be somewhere in between the results of the two tests. https://gist.github.com/orolyn/ff70f512efee36d402d1fc4fbc8f0521 On 6 Jun 2016 12:19 p.m., "Rowan Collins" wrote: > On 06/06/2016 12:06, Dominic Grostate wrote: > >> float, int and string all share the same row on an upside down pyramid, >> with $bar, being dynamic, at the bottom. >> > > OK, so take away the dynamic case, and assume the caller is in weak mode. > Now you have a second case where you need priorities between the types. > > Or consider this code, which is already valid: > > class A { function foo($bar) { echo "A: $bar"; } } > class B { function foo(int $bar) { echo "B: $bar"; } } > (new B)->foo(1.5); // B: 1 > > Or we could construct similar examples with parent and sub-classes as the > type constraint of $bar. And so on. > > I tried to stress that this is an example of one detail among many that > would need to be worked out; I wasn't looking for a single answer. > > Perhaps we would need to add a new keyword (or a native annotation?) to > mark that a function was overloaded, so that existing inheritance didn't > accidentally become overloading. > > To my mind, this would add a lot of complexity to the language, and I'm > not convinced of the gain. If you want to avoid dynamically checking > variable types, you can always just provide separately named methods for > separate cases. > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a1130ccf06dac4405349b21a6--