Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80045 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23534 invoked from network); 1 Jan 2015 14:05:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jan 2015 14:05:17 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:65486] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F4/39-60454-C1455A45 for ; Thu, 01 Jan 2015 09:05:17 -0500 Received: by mail-wi0-f180.google.com with SMTP id n3so26654959wiv.13 for ; Thu, 01 Jan 2015 06:05:13 -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; bh=ICnP4w5v0zXwVBQGXt5tJ8qLnkhQVE7XZgeMmKV/DU0=; b=hLPEZ5tJye/GSQz5PEwMZp+vl05Rp1qknEALUEPFAwtDr+lp8QZlfe/zh+SFxCPiaD yaEw7tWtxWPaWC5R0ULp8XF3qNpF/mN+S6rMxbi/XcApBq0yLkzsoUpAumYGbmHmX3wt R5EbrlizsfDkhXvJrq85jcTadms+vMWc5S8IJOYrmSviTJPE6fOIdHOVE3Obf/hKCDmd rMa0Uv+2ne4/8FMh0tbNXEy6SBDH7EchYc/sflgc7WwuwBgpD+T1GgKiJNtQCiz8LQsC pOVVVBLPAd13r+/bGtsDnozS27ItvEacQAMITGoY5RUv4qxZhEeD3WH8RgPZVJ55cW9G lz7g== MIME-Version: 1.0 X-Received: by 10.194.95.10 with SMTP id dg10mr141228848wjb.82.1420121113583; Thu, 01 Jan 2015 06:05:13 -0800 (PST) Received: by 10.27.10.196 with HTTP; Thu, 1 Jan 2015 06:05:13 -0800 (PST) In-Reply-To: <41D5BB0B-73AF-488E-968D-90B2878E3178@ajf.me> References: <41D5BB0B-73AF-488E-968D-90B2878E3178@ajf.me> Date: Thu, 1 Jan 2015 15:05:13 +0100 Message-ID: To: Andrea Faulds Cc: PHP Internals Content-Type: multipart/alternative; boundary=047d7bdc807883656c050b97b661 Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints From: nikita.ppv@gmail.com (Nikita Popov) --047d7bdc807883656c050b97b661 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Dec 31, 2014 at 9:27 PM, Andrea Faulds wrote: > Good evening, > > Parameter type hints for PHP=E2=80=99s scalar types are a long-requested = feature > for PHP. Today I am proposing an RFC which is a new attempt to add them t= o > the language. It is my hope that we can finally get this done for PHP 7. > > I=E2=80=99d like to thank Dmitry, who emailed me and gave me some feedbac= k on the > draft RFC and some improvements to the patch. He encouraged me to put thi= s > to internals sooner rather than later, as it=E2=80=99s a feature many peo= ple are > hoping will be in PHP 7. > > The new RFC can be found here: https://wiki.php.net/rfc/scalar_type_hints > > As well as the RFC, there is a working Zend Engine III patch with tests, > and an incomplete specification patch. > > Please read the RFC (and specification patch, if you wish) and tell me > your thoughts. > > Thanks! > While in favor of introducing scalar type annotations, I'm against this proposal in particular. I've held a different position in the past, but by now I'm thoroughly convinced that if we introduce scalar type declarations, they should be strict. No wiggling, no casting. Apart from being consistent with the existing behavior of type declarations and being what the majority of the vocal community wants, it is also possible to reason about strict type declarations statically. This means that an IDE or other tool will be able to perform meaningful analysis based on typehinted functions. E.g. if you pass the result of a string function to an int parameter, your code is definitely wrong and you can be told so. Loose typehints as proposed here do not offer this possibility, because a string can be or can not be a valid input to an int parameter depending on the exact value. For the same reason loose typehints are also more fragile. Code that worked in casual testing during development will fail in production when unexpected, improperly validated user input is encountered. With strict types on the other hand it is very likely that code working with one input will also work with all other possible inputs, because the type check is not value-dependent. (Types are typically much less volatile than values.) The ability to statically check type annotations is rather important to me. I think much of the usefulness of this feature would be lost without the ability to check correct usage with tooling. I'd also like to point out that Hack uses a strict type scheme and it seems to work well there (though I do acknowledge that the situation is not the same, as Hack has a generally more powerful and fully statically checked type system). Apart from these general thoughts, I also think that this proposal is a regression from the previous one. In the name of "consistency" it uses the rather weak zpp validation rules, which allow a lot of questionable input. Just look at the conversion table in the RFC, practically all of it is "Yes". I understand the motivation to reduce the number of different conversion semantics, but I just can't get behind it if it means reusing existing, bad conversion rules. Nikita --047d7bdc807883656c050b97b661--