Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82528 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69884 invoked from network); 12 Feb 2015 12:39:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2015 12:39:38 -0000 Authentication-Results: pb1.pair.com header.from=pajousek@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pajousek@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.171 as permitted sender) X-PHP-List-Original-Sender: pajousek@gmail.com X-Host-Fingerprint: 209.85.216.171 mail-qc0-f171.google.com Received: from [209.85.216.171] ([209.85.216.171:48597] helo=mail-qc0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/A3-50473-90F9CD45 for ; Thu, 12 Feb 2015 07:39:37 -0500 Received: by mail-qc0-f171.google.com with SMTP id l6so8165152qcy.2 for ; Thu, 12 Feb 2015 04:39:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=/VmDEmm2Xtwd2fw9fN9eD+0YTkuaqIT7Mrb/0Ekavig=; b=DEaddKWyhN4eyCjdXNNqx2NIo89FrJZNC+wCSRLcLo0Zef8ZZNPE1yZ1fql7PHMmJJ IKCfwpQ9VCItWrwEYNp+Fx+yJtq+Zob3yH+Qn+Qzyb2DElGR6nPhLqO79VaF4ow0e+8Q txraHzp2RRBEei0xRkNxJMFdn/RoqNRUuI4BEr2DODOmcprrxuTAhXclL+rZK7nyupQt WhYPXdN+hOYDhmb/0sqUnh39grOu8+uhz6Xs95xznZbGFWJ254ycLzBegGaYrgL4Dpw2 oQRVE3AJ2f5tnoc88xsUtb85zExmUQWHCoKsPyLhTn5ThR91V7srml2q6rbMIpegv5/H 4PAg== MIME-Version: 1.0 X-Received: by 10.140.23.199 with SMTP id 65mr9684593qgp.84.1423744774818; Thu, 12 Feb 2015 04:39:34 -0800 (PST) Received: by 10.96.66.201 with HTTP; Thu, 12 Feb 2015 04:39:34 -0800 (PST) In-Reply-To: References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> <54DAF884.7000508@lerdorf.com> <203e611c8e0b03568a868b8d931aec37@mail.gmail.com> <61E01A7C-C5C8-447F-A8FA-E12A18E847CA@ajf.me> Date: Thu, 12 Feb 2015 13:39:34 +0100 Message-ID: To: Andrea Faulds Cc: "guilhermeblanco@gmail.com" , Zeev Suraski , Rasmus Lerdorf , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints From: pajousek@gmail.com (=?UTF-8?Q?Pavel_Kou=C5=99il?=) On Thu, Feb 12, 2015 at 12:44 PM, Andrea Faulds wrote: > > 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 mig= ht cause unpredictable behaviour (with strict types you=E2=80=99d get an er= ror 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 p= arameters and dynamic typing. Finally, overloading can lead to really poor = API design: it=E2=80=99s not that uncommon in some languages to see 20 diff= erent function definitions with overlapping and non-comprehensive subsets o= f a method=E2=80=99s behaviour, that are distinguished only by parameter ty= pes. It=E2=80=99s one of my least favourite Java/C#/C++ features for that r= eason. > > In response to saying numbers are not a type: well, they are more of an a= bstract type which integer and float subclass. We already have internal fac= ilities for converting to and from =E2=80=9Cnumbers=E2=80=9D alongside inte= gers and floats, I don=E2=80=99t see why we can=E2=80=99t expose this to us= ers. > Hello, 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. Overloading on scalar types - unpredictable how? Even with weak calls, the best candidate could be chosen? 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? 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. 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. Well, about "number" type hint. How this would work, in combination with strict types? function bar(float $f) { return $f * 1.23; } function foo(number $x) { return bar($x); } foo(1); From my understanding, it wouldn't? Regards Pavel Kouril