Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82524 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61681 invoked from network); 12 Feb 2015 11:44:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2015 11:44:39 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.208 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.208 imap2-3.ox.privateemail.com Received: from [192.64.116.208] ([192.64.116.208:55366] helo=imap2-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/22-50473-5229CD45 for ; Thu, 12 Feb 2015 06:44:38 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id AD7F68C0075; Thu, 12 Feb 2015 06:44:34 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap2.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap2.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id sZIeLtaeP5QO; Thu, 12 Feb 2015 06:44:34 -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 24F6E8C0069; Thu, 12 Feb 2015 06:44:33 -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 11:44:30 +0000 Cc: "guilhermeblanco@gmail.com" , Zeev Suraski , Rasmus Lerdorf , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: 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, > On 12 Feb 2015, at 07:05, Pavel Kou=C5=99il = wrote: >=20 > On Thu, Feb 12, 2015 at 1:13 AM, Andrea Faulds wrote: >>=20 >> A number (or numeric, or num, or some other name) type hint is = something I plan to propose in a future, follow-up RFC. >>=20 >=20 > wouldn't polymorphism (via method overloading) solve the use cases and > be much more useful in the long run than introducing a something > that's not a type into type hints? PHP already has polymorphism through its dynamic typing. I don=E2=80=99t = see method overloading happening any time soon. We have optional = parameters and dynamic typing, which all but eliminate the main needs = for overloading. We=E2=80=99re a weakly-typed language, so overloading = on scalar types might cause unpredictable behaviour (with strict types = you=E2=80=99d get an error sometimes, and that=E2=80=99s fine - but = calling an entirely different function? Now that=E2=80=99s different.) = There=E2=80=99s also the question of how, or if at all, method = overloading could interact with our optional parameters and dynamic = typing. Finally, overloading can lead to really poor API design: it=E2=80=99= s not that uncommon in some languages to see 20 different function = definitions with overlapping and non-comprehensive subsets of a = method=E2=80=99s behaviour, that are distinguished only by parameter = types. It=E2=80=99s one of my least favourite Java/C#/C++ features for = that reason. In response to saying numbers are not a type: well, they are more of an = abstract type which integer and float subclass. We already have internal = facilities for converting to and from =E2=80=9Cnumbers=E2=80=9D = alongside integers and floats, I don=E2=80=99t see why we can=E2=80=99t = expose this to users. Thanks. -- Andrea Faulds http://ajf.me/