Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81115 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59094 invoked from network); 25 Jan 2015 08:38:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jan 2015 08:38:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=pajousek@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pajousek@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.182 as permitted sender) X-PHP-List-Original-Sender: pajousek@gmail.com X-Host-Fingerprint: 209.85.216.182 mail-qc0-f182.google.com Received: from [209.85.216.182] ([209.85.216.182:49907] helo=mail-qc0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/23-36889-77BA4C45 for ; Sun, 25 Jan 2015 03:38:15 -0500 Received: by mail-qc0-f182.google.com with SMTP id l6so3427667qcy.13 for ; Sun, 25 Jan 2015 00:38:11 -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:content-transfer-encoding; bh=QlKwJXp8Do8likq+Dp/qbdFzpObzaSiKJS/ui5TO7yY=; b=l/fmVxYOeC2Nqgf2zFESoJHFfrpnMome69F2uhJJQ0yMEPLVT2W562sE0kS7kWKOz7 YeSvO0nBjwi791NWkshhK6ng/sJDSF+YiiReLIR7sKp9HPo9Mp9aUAMkkKkGQ82foGMk EVi1wuidf2bqWYCxIE2p6YVM7Y5ufCncJvefzdLjeaa4KQ19daMQJyAdoQ5e3NvBun/V ys9p4yCLn+ydlmIaQab+dLlX0BEMvxFB8MjgtDotyGw6AnLJ4/pjAauvIC5mmzi8R/Qt b7KeiMiIyJInI3Z6cBy8l6hYYZ0mG5I8mPCNQdyWdtlOKCYCZAc3tC1GzZJUb/JPH1VJ Q6nA== MIME-Version: 1.0 X-Received: by 10.224.99.3 with SMTP id s3mr31026250qan.79.1422175091587; Sun, 25 Jan 2015 00:38:11 -0800 (PST) Received: by 10.96.209.97 with HTTP; Sun, 25 Jan 2015 00:38:11 -0800 (PST) In-Reply-To: <90B1885A-E767-484E-8F38-A791E8A3FE9B@ajf.me> References: <41D5BB0B-73AF-488E-968D-90B2878E3178@ajf.me> <90B1885A-E767-484E-8F38-A791E8A3FE9B@ajf.me> Date: Sun, 25 Jan 2015 09:38:11 +0100 Message-ID: To: Andrea Faulds Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints From: pajousek@gmail.com (=?UTF-8?Q?Pavel_Kou=C5=99il?=) On Sun, Jan 25, 2015 at 5:02 AM, Andrea Faulds wrote: > Hi everyone, > > Just a few small updates. > > I=E2=80=99ve made a small change to this RFC. Instead of the strict mode = syntax being declare(strict_typehints=3DTRUE), it=E2=80=99s now declare(str= ict_types=3D1) instead. This makes it a bit quicker to type - important giv= en you=E2=80=99d need to type it a lot - without sacrificing much readabili= ty. It also avoids using the words =E2=80=9Ctype hint=E2=80=9D, which I und= erstand are contentious to some people. > > The patch now includes a more extensive set of tests: https://github.com/= TazeTSchnitzel/php-src/tree/scalar_type_hints_2_strict_mode/Zend/tests/type= hints/ > > The pull request is also now green on Travis (aside from two failures on = the debug build - but they also fail in master). > > Levi=E2=80=99s Return Types RFC has now passed, so now the RFC needs to c= over that. The RFC currently doesn=E2=80=99t discuss return types, save for= a paragraph in the Future Scope section. When the return types patch is me= rged, I=E2=80=99ll update the scalars patch, and then update the RFC. A poi= nt of contention here is whether or not return types should always be stric= t, or whether they should also obey the strict/weak modes. I=E2=80=99m not = entirely sure on that one, that specific item may end up going to a vote. T= hat said, I do lean towards always strict, given you can usually ensure you= r return type=E2=80=99s correct. > > Thanks. > > -- > Andrea Faulds > http://ajf.me/ > Hello, personally I still don't like this RFC in it's current form and "shorter" declare won't change it. I was thinking a lot about the typehints in PHP for last few days and I think having only one way would be the best - and it's somewhere between the curent weak and strict typing. My main "issue" is that the current weak typing is too loose and the strict typing is too strict. The problem with the current strict typing is that you cannot pass "int" to a "float" parameter, even though there can be a totally lossless conversion and it works in other strongly typed languages. And being able to pass a float(1.5) to int and lose the 0.5 value doesn't make sense as well, because data will get lost. Neither of those feels somehow "predictable" and "natural". Also, after a little bit of thinking, if someone needs to do a type conversion while calling a method, writing foo((int) $bar) isn't that hard. So, I think it would be best to choose just one of these two approaches and either loosen it a little or make it more strict (so data loss doesn't happen). But I guess this approach would be inconsistent with how the built-in PHP functions work? PS: Ideally, the data loss rules should be made for types and not values (like the old scalar type hints RFC had), so you don't get unpredictable results. The only ones I can think of right now are basically int -> bool, int -> float, object (w/ __toString) -> string, int -> string, float -> string? Regards Pavel Kouril