Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82537 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88914 invoked from network); 12 Feb 2015 14:31:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2015 14:31:17 -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.199 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.199 imap11-2.ox.privateemail.com Received: from [192.64.116.199] ([192.64.116.199:46581] helo=imap11-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/17-50473-439BCD45 for ; Thu, 12 Feb 2015 09:31:17 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 191D78800D5; Thu, 12 Feb 2015 09:31:14 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 7qMTN845U-0H; Thu, 12 Feb 2015 09:31:13 -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 B4EFD8800E6; Thu, 12 Feb 2015 09:31:12 -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 14:31:10 +0000 Cc: "guilhermeblanco@gmail.com" , Zeev Suraski , Rasmus Lerdorf , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <342635C4-F0EA-4557-A37F-753E51100402@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> <85D76C91-9A9E-459B-847A-619AA21B9262@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 13:48, Pavel Kou=C5=99il = wrote: >=20 > C# does have dynamic typing. No it doesn=E2=80=99t, it=E2=80=99s a statically-typed language. I = don=E2=80=99t understand why you say it has dynamic typing - there is = some limited dynamism in parts, but I don=E2=80=99t think it affects = what we=E2=80=99re talking about. Dynamic typing and polymorphism = aren=E2=80=99t the same. > I just don't believe that method overloading would suddenly make > everyone write poor programs. Maybe not, but all the facilities needed to make good programs are = already there. Overloading would only really be useful for writing bad = programs, because all the good things it enables are already supported = by PHP. > It brings cleaner declarations of methods and functions. Only slightly. A switch() (or better, a pattern match, were we to add = that) can do the same job and it=E2=80=99s not that much less clean. > Also, it > brings the possibility of having operator overloading in user classes > someday in the future (yes, this can be abused as well, but it also > has legitimate use cases - like class for representing Money and being > able to do +, - , / or * operations on them). Overloading isn=E2=80=99t necessary for operator overloading. > Is the option of omiting > type hints and having optional parameters really a good enough > replacement for method overloading polymorphism for you? Because for > me, it unfortunately is not. :( Could you give an example use-case? > Read the example once more, please - the issue I see with it is that > bar() requires float, but foo() just number and doesn't convert it to > the required type. The most unpredictable thing is that it will work > half of the time and half of the time it will just throw errors. Well, yes. PHP is dynamically-typed, this can happen, whether you=E2=80=99= re using strict or weak typing. Your only way to guard against it here = is to do proper testing. Well, if we added a numeric type hint, your IDE = could catch this error for you, actually. Anyway, the same thing can happen for float->int conversions *with* weak = typing, as we disallow certain conversions (PHP_INT_MIN > $x, = PHP_INT_MAX < $x, !isfinite($x), isnan($x)). Also, even though PHP does allow most float->int conversions with weak = typing, it doesn=E2=80=99t mean they=E2=80=99re a good idea. Silently = losing the fractional part is probably not what you want. Thanks. -- Andrea Faulds http://ajf.me/