Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81830 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57973 invoked from network); 4 Feb 2015 18:12:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2015 18:12:21 -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.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:51501] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B4/43-40930-50162D45 for ; Wed, 04 Feb 2015 13:12:21 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 92FB82400A9; Wed, 4 Feb 2015 13:12:18 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id wY5Lu0pNs2hR; Wed, 4 Feb 2015 13:12:18 -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 698112400D3; Wed, 4 Feb 2015 13:12:16 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: <003f01d0405e$5d1bf080$1753d180$@tutteli.ch> Date: Wed, 4 Feb 2015 18:12:14 +0000 Cc: Dmitry Stogov , Sebastian Bergmann , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <8D7126B3-C559-4FBA-94C9-28390F18377D@ajf.me> References: <00c101d04049$ca411ec0$5ec35c40$@tekwire.net> <54D1CA7C.8060204@php.net> <003f01d0405e$5d1bf080$1753d180$@tutteli.ch> To: Robert Stoll X-Mailer: Apple Mail (2.2070.6) Subject: Re: [PHP-DEV] What do we need strict scalar type hints for? From: ajf@ajf.me (Andrea Faulds) Hi Robert, > On 4 Feb 2015, at 09:38, Robert Stoll wrote: >=20 > Personally I am not in favour of the declare approach because the user = will need to switch between strict context and non-strict context which = will be quite challenging, anti-efficient (in terms of productivity) and = most probably another source for bugs. I=E2=80=99ve found this not to be quite true in practice. When I ported = my app to use strict scalar hints, very little broke - and this is an = app that took advantage of weak typing everywhere. I realise switching = contexts might be a little painful, but it doesn=E2=80=99t seem to be as = bad as I expected. It looks to me like much PHP code is already fairly = strict and consistent with its types. I think it=E2=80=99s mostly just edge cases where things break with = strict types on. Any strict code will work fine as =E2=80=9Cweak=E2=80=9D = code, and most weak code will work fine as strict code, I think. > Yet, I have to defend Andrea's RFC here since the claims made that it = will break all kind of existing code is just not true (or I got the RFC = completely wrong). >=20 > sin(1) would only be broken if and only if the user has decided to use = it in a strict mode. Consider the following: >=20 > User A writes the file index.php >=20 > $a =3D sin(1); //perfectly fine > include 'test_strict.php' > ?> >=20 > and user B writes test_strict.php >=20 > declare(strict=3D1); > $b =3D sin(1); //will fail and that's ok [*] since the user decided to = be in strict mode > ?> >=20 > As far as I can tell user A which want to code in non-strict mode = could do so also in the future - no error is reported, no problem at = all. Only user B would get the error and only because he/she wanted to = be informed when his/her code is not strict. >=20 > [*] we could actually distinguish between int literals/constants and = int variables. The above case would be fine as well since 1 can be int = or float (pretty much as Haskell is handling it) Yeah, I only had int/float issues when I turned on strict mode in my = app. And that caught a bug, actually, so I was quite thankful for it. -- Andrea Faulds http://ajf.me/