Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82992 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10468 invoked from network); 17 Feb 2015 17:46:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 17:46:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=francois@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=francois@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 212.27.42.2 as permitted sender) X-PHP-List-Original-Sender: francois@php.net X-Host-Fingerprint: 212.27.42.2 smtp2-g21.free.fr Received: from [212.27.42.2] ([212.27.42.2:1431] helo=smtp2-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7D/28-19463-87E73E45 for ; Tue, 17 Feb 2015 12:46:33 -0500 Received: from moorea (unknown [82.240.16.115]) by smtp2-g21.free.fr (Postfix) with ESMTP id 029AE4B02AE; Tue, 17 Feb 2015 18:46:11 +0100 (CET) Reply-To: To: "'Anthony Ferrara'" , "'Zeev Suraski'" Cc: "'Sara Golemon'" , "'PHP internals'" References: <011801d04a07$83ab1c00$8b015400$@php.net> <016f01d04a3a$e9183220$bb489660$@php.net> <022801d04ab1$4a0c47d0$de24d770$@php.net> <1913e09d7f52541901d8574d2080a63f@mail.gmail.com> In-Reply-To: Date: Tue, 17 Feb 2015 18:46:26 +0100 Message-ID: <025f01d04ad9$a77a8e90$f66fabb0$@php.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQGD0sLDaA+/0NIeBlQhQC5OtPA/xwHih9+6AanvcsEBj7eMCwEU0CpMAs0H7+gBDwGZjwJNu28fAX8sxVSdHyZlkA== Content-Language: fr X-Antivirus: avast! (VPS 150217-1, 17/02/2015), Outbound message X-Antivirus-Status: Clean Subject: RE: [PHP-DEV] Reviving scalar type hints From: francois@php.net (=?utf-8?Q?Fran=C3=A7ois_Laupretre?=) Hi Anthony, I understand your concerns and think the work we are doing should be = suitable to compilers and static analyzers, but that's hard to make = everyone happy. One thing I thought we should reserve for a future release is the = addition of a set of strict type hints : something like (just example = syntax) 'int!', 'float!', 'string!', 'bool!' (other types are strict = already). These types would have their counterpart at the ZPP level and = their parsing rule would be to reject everything except the = corresponding zval type. This way, the user can write : function convertToInt(string $number): int! { <- int! instead of int if (!preg_match("(^[0-9]{1,17}$)", $number)) { throw new InvalidArgumentException("Supplied argument is not a = valid number"); } return $number; } Which makes it usable for static analysis, I guess. These would be = primarily used for return types. Another valuable type would be something like 'numeric!', which could = accept IS_LONG and IS_FLOAT only. This would be interesting for static = analysis, to know that it cannot be a string, while accepting any zval = numeric value. This is a little harder because it should be implemented = as an alias of 'int!|float!', and we wanted to reserve union types for a = future release. About using zval type *and* value, I don't like it too, and I would = prefer using types only, but I see no way of keeping accepting "31" as = int without depending of the runtime value. Additional strict types, as = proposed above, may be a partial solution because those would never care = about value. However, the more I think about it, the more I think that this set of = strict types will be necessary to design union types, as defining a set = of rules to convert a zval to a union of weak types, while possible, = will be a mess. So, future union types could be strict-only, which will = make them suitable for analysis. I'm afraid this is probably not what you expect but, as I previously = said, I'm trying to satisfy as many people as possible. Maybe you're = right and '0.3 or nothing' proponents are a 'crowd', but I am not doing = politics. If this is the case, the 'crowd' will win and this will be = perfect. Now, if you want to collaborate on the compromise we are trying to = build, I really value your opinion. I don't pretend to be right in any = way and I understand your pov but, if you stay on '0.3 or nothing', I = cannot do much more. Regards Fran=C3=A7ois