Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82875 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7494 invoked from network); 16 Feb 2015 18:56:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Feb 2015 18:56:23 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.171 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.171 mail-vc0-f171.google.com Received: from [209.85.220.171] ([209.85.220.171:54849] helo=mail-vc0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F4/FA-36518-55D32E45 for ; Mon, 16 Feb 2015 13:56:22 -0500 Received: by mail-vc0-f171.google.com with SMTP id kv19so11164457vcb.2 for ; Mon, 16 Feb 2015 10:56:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=ElO6GXKqwYpWERTX5Gx+xhoFj7+L4Wnt2JyS3GJXOcc=; b=mDZF/pS4pqGr13RAnxhG/4R0/IT5y5GJfZ8yWubb0wWIn0s9/bwe0ff5pn/R53IsgG QwAwB0GZvMcEYbK9b9BNq4WzjiGqrDUCZiO5ZZ6r+piN9mKWyLXJQtEfcK9wpfuc0yle d8UbCh2wQItPCjEn9iPlYaHeYT13WSs9W4DNQzMm4sAN6+jXGY+Ad08b5l3DX/SahBU6 JjJYMonRXn+Rq7D28A3kCwi4AH89Lv8KCvgx/y3W9YapYl6hun+IUS9v45nUA9xnqBmi VveP8p8AY2C9oDdfOxXbmAVr1S5oWR1U5hMPgQRwTgiTVIZIYkKGlvLzS7XSerBAhwZE 8gRA== X-Gm-Message-State: ALoCoQm74ETfPHjV7hXgu9HIHHeeLyTkNT57AsCF7LWkDMFOb+XeywGRaIiZWZiMXJ4G25v06YAlL5FqOmYfU6RgvxDs/1JBqEbX/uDp2uPM6Wh2oMK8PQykLrAb4N17q5/GBCiy3AaMI8L6pHCng8sQDYJ8nqUiYg== MIME-Version: 1.0 X-Received: by 10.52.52.136 with SMTP id t8mr14041443vdo.49.1424112975844; Mon, 16 Feb 2015 10:56:15 -0800 (PST) Received: by 10.52.74.73 with HTTP; Mon, 16 Feb 2015 10:56:15 -0800 (PST) In-Reply-To: <011801d04a07$83ab1c00$8b015400$@php.net> References: <011801d04a07$83ab1c00$8b015400$@php.net> Date: Mon, 16 Feb 2015 22:56:15 +0400 Message-ID: To: francois@php.net Cc: Arvids Godjuks , Jefferson Gonzalez , Rowan Collins , PHP internals Content-Type: multipart/alternative; boundary=089e0115f0480baef6050f392448 Subject: Re: [PHP-DEV] Reviving scalar type hints From: dmitry@zend.com (Dmitry Stogov) --089e0115f0480baef6050f392448 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Feb 16, 2015 at 7:42 PM, Fran=C3=A7ois Laupretre wrote: > Hi, > > > > De : Arvids Godjuks [mailto:arvids.godjuks@gmail.com] > > > > The 0.1 RFC version was mentioned a lot as a good compromise by many > > people > > and had major support. > > Maybe someone competent could pick it up, make necessary adjustments > > that > > where required and let people vote on it? Start with small steps - get > the > > weak type hints into the language first, see how it gets used and then = we > > can always add strict type hints if there is a need/desire to do that. > > > > That way we finally get type hints into the language, and those wanting > the > > strict variety have all the opportunities in the world to add them at a > > later release with proper discussion and development time. > > That's what I am planning. If I write an RFC, it will be based on Andrea'= s > 0.1/0.2 version, and won't propose different modes. > I would propose exactly Andrea's 0.1. Most people were agree to support weak type hints by default. This proposal won't prevent feature addition of optional strict type hints. All are tired from endless arguing. > The problem is that the previous controversial RFC focused people on weak > vs strict typing, while we should have explored other technical concerns. > Here are the main ones I see : > > - the fact that the RFC supports single types only, like the previous > 'return type' RFC. While it is easier to implement, it opens several issu= es > as multiply-typed arguments are an integral part of the PHP language > (mostly completeness and compatibility with internal function hinting). I= f > we want to support multiple types the same way for internal and userspace > functions, we must extend the ZPP layer to support it. > this is not a big technical problem. - the mechanism to check for type hints on internal functions, while easy > to implement, is not sufficient, as a lot of internal functions get a bar= e > zval from the parsing system and then convert it by themselves. With the > proposed mechanism, there's no possible hinting on such argument, which > will make the implementation different from the documentation. Even if th= e > check is done by the function body, it won't be done in a consistent way > with type hinting checks and won't raise a similar error. As most cases a= re > related to multiply-typed args, the solution is in adding multiply-typed > support to ZPP. Multiply-typed support needs to redefine scalar conversio= n > rules, to take care of the target type being a combination of single type= s. > I wouldn't rise this question. Lets it work as is for now. > - We need to define the appropriate extension to Reflection > parameters/return type. That's not complex, but it takes time. > It's a subject for separate more or less obvious RFC. > - Other changes I'd like to propose are exposed in Bob Weinand's article, > at https://gist.github.com/bwoebi/b4c5564388ecd004ba96. The article > explains how restricting weak conversion possibilities would make strict > typing almost useless. Changes include forbidding bool to int/float or > '7years' to int. This cannot be left for future additions as BC breaks wi= ll > make it impossible. To remain consistent between userspace/internal > functions, this must also be done at the ZPP level. > Lets go forward by small steps. If we would do it before we would already got all the features. We may restrict ZPP rules by next RFC. I'll most probably support it. The same for the rest. Thanks. Dmitry. > - Using bare class names as type hints is a potential issue too, as it > makes reserved keywords and class names share the same naming space. I > think we should deprecate the use of class names as type hints in favor o= f > 'object(class-name)'. If we don't do that, every future addition of a typ= e > hint keyword will cause a BC break (and will be practically impossible). > > - Additional 'hybrid' types like 'numeric' and 'mixed' should be also > provided. > > So, most features I have in mind are really 'now or never'. > > My main concern, anyway, is with March 15 announced feature freeze. If we > need a vote by this date, it's impossible. And planning such BC for 7.1 i= s > probably unrealistic because of the huge syntax additions and BC breaks i= t > brings. So, if it's too late for an inclusion in 7.0, I think I'll give u= p. > > So, could someone confirm what 'feature freeze' exactly means ? > > Regards > > Fran=C3=A7ois > > > > > > > > > The main issues are completeness (we can give hints for some cases, but > not for others) and, more important, the compatibility with internal > functions. As Andrea herself agreed, her mechanism for type hinting on > internal functions is not sufficient. Just using the ZPP macros, as they > exist today, won't work as a lot of internal functions get a bare zval an= d > then convert it by themselves. So, in this case, we would check nothing. > So, an argument described as 'string|array' in the documentation, wouldn'= t > produce the same sort of error when sent an object, than its friend, > described as 'string'. This is not consistent and will open a lot of side > effects if it is left out of the type hint layer. > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --089e0115f0480baef6050f392448--