Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82548 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12521 invoked from network); 12 Feb 2015 17:22:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2015 17:22:40 -0000 Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:42457] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 46/B0-08423-D51ECD45 for ; Thu, 12 Feb 2015 12:22:39 -0500 Received: (qmail 13150 invoked from network); 12 Feb 2015 18:22:34 +0100 Received: from cm135-167.liwest.at (HELO RoLaptop) (81.10.135.167) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 12 Feb 2015 18:22:34 +0100 To: , "'Nikita Nefedov'" , "'Andrea Faulds'" Cc: =?utf-8?Q?'Pavel_Kou=C5=99il'?= , "'PHP Internals'" 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> <342635C4-F0EA-4557-A37F-753E51100402@ajf.me> <007b01d046df$1bde01d0$539a0570$@tutteli.ch> <008801d046e5$89edc2e0$9dc948a0$@tekwire.net> In-Reply-To: <008801d046e5$89edc2e0$9dc948a0$@tekwire.net> Date: Thu, 12 Feb 2015 18:22:33 +0100 Message-ID: <007d01d046e8$7d414190$77c3c4b0$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQJMIZG9mXkdirFXmuP9r5ZK3xIuzQJbJJA/AzCIQggCYWllLQKBurkXAYsw6s4B6qYCMgHjX/2GAb5UKOABwylnMQKF/fUwArGIQ84B1RtadQMO5Q+CAqJubzkBDVl/xQJTeJzMAX5nsziazlPJEA== Content-Language: de-ch Subject: AW: [PHP-DEV] [VOTE] Scalar Type Hints From: php@tutteli.ch ("Robert Stoll") Hi Fran=C3=A7ois, > -----Urspr=C3=BCngliche Nachricht----- > Von: Fran=C3=A7ois Laupretre [mailto:francois@tekwire.net] > Gesendet: Donnerstag, 12. Februar 2015 18:01 > An: 'Robert Stoll'; 'Nikita Nefedov'; 'Andrea Faulds' > Cc: 'Pavel Kou=C5=99il'; 'PHP Internals' > Betreff: RE: [PHP-DEV] [VOTE] Scalar Type Hints >=20 > Hi Robert, >=20 > > De : Robert Stoll [mailto:php@tutteli.ch] > > > > There are several programming languages which do support dynamic > > typing and method overloading somehow (Clojure, Erlang, Prolog, = Cecil > > and certainly more). Most of them use a multi-method approach and I > > think if PHP would introduce function/method overloading, then such = an > > approach would be appropriate. Right now, I need to implement the > > dynamic dispatching quasi myself which might be more verbose but is > > also more cumbersome (and uglier IMO). Consider the following = (fictional example): >=20 > We all agree on the interest of polymorphism on object classes, even = if your example could be solved with specialized > logger classes, but the question was about polymorphism on different = scalar types, which is much more problematic in PHP, > even using strict scalar typing. >=20 > Cheers >=20 > Fran=C3=A7ois OK, maybe I went a little bit off topic due to the booted discussion = about method overloading which did not cover all aspects IMO. So back = to scalar type hints: I do not really see how num would be a problem or polymorphism in = general. I am not really aware of memory management of PHP but I guess = it is not optimised for fixed-sized integers or is it? If not, then it does not really matter whether a parameter holds an int, = a float or a BigInt, allocation is dynamic anyway I suppose. Or what = problems do you see here? Maybe you are referring to Pavel's example: > 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 The same applies for the following code class Foo{} class Bar{} function foo(Foo foo){ bar($foo); } function bar(Bar bar){ //.. } and we still agree upon that polymorphism is the right way to go since = it allows more expressive code with a certain "safety". If you want full = flexibility, then rely on dynamic typing only and if you want some = safety then use type hints. I do not see a special case here - = polymorphism for scalar types is nothing new