Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82530 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73291 invoked from network); 12 Feb 2015 12:45:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2015 12:45:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:33292] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/64-50473-A50ACD45 for ; Thu, 12 Feb 2015 07:45:14 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 355712400C2; Thu, 12 Feb 2015 07:45:11 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ei1h5eFmo8iw; Thu, 12 Feb 2015 07:45:10 -0500 (EST) Received: from oa-res-26-240.wireless.abdn.ac.uk (oa-res-26-240.wireless.abdn.ac.uk [137.50.26.240]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 3C99B2400D4; Thu, 12 Feb 2015 07:45:09 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: Date: Thu, 12 Feb 2015 12:45:07 +0000 Cc: "guilhermeblanco@gmail.com" , Zeev Suraski , Rasmus Lerdorf , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <85D76C91-9A9E-459B-847A-619AA21B9262@ajf.me> References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> <54DAF884.7000508@lerdorf.com> <203e611c8e0b03568a868b8d931aec37@mail.gmail.com> <61E01A7C-C5C8-447F-A8FA-E12A18E847CA@ajf.me> To: =?utf-8?Q?Pavel_Kou=C5=99il?= X-Mailer: Apple Mail (2.2070.6) Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints From: ajf@ajf.me (Andrea Faulds) Hi Pavel, > On 12 Feb 2015, at 12:39, Pavel Kou=C5=99il = wrote: >=20 > I don't see any problem with combination of optional parameters with > method overloading. C# has it and it is pretty useful and works there > without any bigger issues. Sure, the dynamic typing may be a (small) > issue, but again, C# does it in an IMHO meaningful way as well and it > can be used as an inspiration, should this way be chosen. C# also doesn=E2=80=99t have dynamic typing. Plus, adding overloading to = an existing language is more difficult. > Overloading on scalar types - unpredictable how? Even with weak calls, > the best candidate could be chosen? Still likely to cause chaos. If you can overload based on scalar types, = then foobar($a / 2) could call any of *three* different functions. > Of course, sometimes there will be > an abmbiguous call, but as long as there would be a way to define > which call you want, it shouldn't be a problem as well? =E2=80=9CA way to define which call you want=E2=80=9D? Sounds like a = hacky workaround to me. > Poor API - for useland code or in PHP's functions itself? But I don't > think this should be considered as a real problem, because in userland > code, developers are able to create a poor API even with the current > versions of PHP. That doesn=E2=80=99t mean we should make it any easier. > If someone wants to shoot himself in the foot, he > will do it in one way or another. And at the same time, polymorphism > via method overloading can lead to a cleaner APIs, if it's used well. I don=E2=80=99t see how. The main things it enables are optional = parameters (which we already support) and polymorphism (which we already = support). So you=E2=80=99d have to explain what overloading brings to = the table beyond those two things. > Well, about "number" type hint. How this would work, in combination > with strict types? >=20 > function bar(float $f) { > return $f * 1.23; > } >=20 > function foo(number $x) { > return bar($x); > } >=20 > foo(1); >=20 > =46rom my understanding, it wouldn=E2=80=99t? It would accept an integer or a float, because both subclass number: function foobar(): number { return 1.0; // okay return 1; // okay } function foo(number $x) {} foo(1.0); // okay foo(1); // okay I don=E2=80=99t see why it =E2=80=9Cwouldn=E2=80=99t work=E2=80=9D. -- Andrea Faulds http://ajf.me/