Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82497 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82614 invoked from network); 11 Feb 2015 21:46:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Feb 2015 21:46:39 -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.200 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.200 imap1-2.ox.privateemail.com Received: from [192.64.116.200] ([192.64.116.200:33373] helo=imap1-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/A2-02515-CBDCBD45 for ; Wed, 11 Feb 2015 16:46:38 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 84195B00085; Wed, 11 Feb 2015 16:46:33 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap1.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap1.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id SsXPKvc4j0cP; Wed, 11 Feb 2015 16:46:33 -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 3EAC8B00068; Wed, 11 Feb 2015 16:46:32 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: <203e611c8e0b03568a868b8d931aec37@mail.gmail.com> Date: Wed, 11 Feb 2015 21:46:30 +0000 Cc: 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> To: Zeev Suraski X-Mailer: Apple Mail (2.2070.6) Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints From: ajf@ajf.me (Andrea Faulds) > On 11 Feb 2015, at 21:30, Zeev Suraski wrote: >=20 >> -----Original Message----- >> From: Rasmus Lerdorf [mailto:rasmus@lerdorf.com] >> Sent: Wednesday, February 11, 2015 8:37 AM >> To: Xinchen Hui; Andrea Faulds >> Cc: PHP Internals >> Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints >>=20 >> On 02/10/2015 07:57 PM, Xinchen Hui wrote: >>>> am I wrong?! >>> seems I am wrong with this, it's a false alarm... it can restore >> automatically. >>=20 >> Yeah, declare() doesn't span files so that isn't a problem. >>=20 >> My worry is still the lack of type coercion for internal calls. >=20 > There's also some pretty interesting analysis on this proposal - based = on > some real world experimentation - from Benjamin Eberlei - = bit.ly/1vl0UED I disagree with some aspects of the blogpost: > enabling strict mode completly defeats the purpose, because now we are = forced to convert manually, reimplementing weak type hinting in our own = code This isn=E2=80=99t true at all. The key difference between explicit = conversions and implicit conversions is that they=E2=80=99re, well, = *explicit*. You can see them, they are blatantly obvious, if you use = grep you can find them. Implicit conversions, while they can sometimes = be great, happen silently and automatically - if they screw up, it can = be hard to track down where the conversion is taking place. With = explicit conversions, you=E2=80=99re converting once and you know = you=E2=80=99ve converted. With implicit conversions, you have no idea = where and how often values are being converted. > We write code with casts already, the scalar type hints patch is not = necessary for that! Only a superficial level of additional safety is = gained, one additional check of something we already know is true! Yet in the previous part he was explaining how existing code doesn=E2=80=99= t use casts and would need them added=E2=80=A6 so therefore, this thing = *isn=E2=80=99t* already known to be true, and the blogpost is = self-contradictory. > strict mode is useless for library developers, because I always have = to assume weak mode anyways. I don=E2=80=99t really understand at all=E2=80=A6 either he doesn=E2=80=99= t understand the proposal (which guarantees you get the types you ask = for), or it=E2=80=99s a reference to the claim from the previous = paragraph, which I=E2=80=99ve already responded to. > In a well designed application or library, the developer can already = trust the types of his variables today, 95% of the time, without even = having type hints, using carefully designed abstractions (example = Symfony Forms and Doctrine ORM): No substantial win for her from having = strict type hints. Yet he was previously explaining how, actually, data coming in from web = requests isn=E2=80=99t the correct types. > In a badly designed application, the developer is uncertain about the = types of variables. Using strict mode in this scenario she needs to = start casting everywhere just to be sure. In an application using strict mode everywhere with scalar type hints = everywhere, you can=E2=80=99t possibly be uncertain about the types of = variables. =E2=80=A6 there=E2=80=99s a lot more in that blog post I could disagree = with, but I won=E2=80=99t bother. Benjamin has his reasons for not = liking strict mode. That=E2=80=99s fine. But if PHP adds strict mode, it = has zero effect on him. > If you've voted on this RFC or intend to vote - please spend the few = minutes > to read through his blog post. It does a good job at actually = illustrating > what life would look like if this rubber ends up meeting the road. Anthony Ferrara also had his own analysis which showed some of the = problems with weak type hinting, and where strict types can be = beneficial: http://blog.ircmaxell.com/2015/02/scalar-types-and-php.html I would suggest people read that blog post before voting, as well. It = points out some real-world examples of where weak typing in PHP can be = insufficient (div), or even downright dangerous (curlopt). -- Andrea Faulds http://ajf.me/