Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82928 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36710 invoked from network); 17 Feb 2015 06:20:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 06:20:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.215.54 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.215.54 mail-la0-f54.google.com Received: from [209.85.215.54] ([209.85.215.54:36613] helo=mail-la0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/42-24654-69DD2E45 for ; Tue, 17 Feb 2015 01:20:07 -0500 Received: by labgq15 with SMTP id gq15so34011820lab.3 for ; Mon, 16 Feb 2015 22:20:03 -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:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=NBwITJLtUxj6eOTGDry2WI+NbdeT/8iaf03jngeA7Cw=; b=HsXGdJzh5f0tV7SwHoNUCMMkDXWYEufI7XIKeHCPjQgTwOO5qZrRObrlXhZe9x8eNA J/04hAgY8xue4Nwr5E3+wzibY71CEglMqdZHIsK2J/uzOQ6Up1Qu2743EhTyCcwHfbkP VwTwofCohC8h6W9vkDgrnb1qmUgx7LsI2a5BvuQDDfEsqVR4nKAMj0OAa+SUrgEGMTdX T+z2Iivf1IzYZbqvwJW4SqyDozRpycLk6KY/UaLrZxajlS+SkBI+lwsNJ6VdnSIborRa i5cMDB8ZYPPOgKClczofH6AEcz/YlLOUdzhyAe6dvIJ/5swEJ93vt168C2v2WHMJy2L0 Slyw== X-Gm-Message-State: ALoCoQmTPliXtnlgReyalKPCi9GKtR0jS6kK5Ly+QzeREarXSbVWVzE9aPEqWIC4j+OdmmViiRmM MIME-Version: 1.0 X-Received: by 10.112.137.38 with SMTP id qf6mr27172700lbb.59.1424154003185; Mon, 16 Feb 2015 22:20:03 -0800 (PST) Sender: php@golemon.com Received: by 10.112.126.65 with HTTP; Mon, 16 Feb 2015 22:20:03 -0800 (PST) X-Originating-IP: [199.201.64.2] In-Reply-To: References: <011801d04a07$83ab1c00$8b015400$@php.net> <016f01d04a3a$e9183220$bb489660$@php.net> Date: Mon, 16 Feb 2015 22:20:03 -0800 X-Google-Sender-Auth: uMIn-WMuA-6McEEvjMN7Xr0yRgc Message-ID: To: Zeev Suraski Cc: francois@php.net, PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Reviving scalar type hints From: pollita@php.net (Sara Golemon) On Mon, Feb 16, 2015 at 10:04 PM, Zeev Suraski wrote: > That syntax poll aside, I had what I hope is some sort an enlightenment, and > I think I know what will get me to cast my vote in favor of 'strict', as a > true supporter. There's one very special conversion that's too common in > PHP to dismiss (IMHO), and is also completely harmless in 99.999% of the > cases, if not strictly 100%: > > string->int or string->float conversions, when the string looks *exactly* > like a number. Given almost all of our inputs (from databases, forms, > files, etc.) come in string form, that's by far the conversion that's going > to give us the most trouble - and is most probably the use case that by far > is going to result the largest amount of explicit casts to work around that > problem. > > What if strict mode didn't just blindly check zval.type, but actually > allowed for this one type of conversion to go through without a problem? > > No bool to int. No Apple to int. No "123 testing" to float. Just "32" to > 32 and "37.7" to 37.7. > > Can the strict supporting camp consider that option? Judging by the > examples brought up by proponents of v0.3, this type of conversion isn't > their issue. It's the 'obviously wrong' conversions that bug them. > > As a secondary concern I'd put int to float conversions where no > (meaningful) data is being lost, e.g. 37 -> 37.0, even though a tiny bit of > accuracy is lost. Rejecting this particular conversion places us at being > stricter than mostly all other languages. That said, it's a much less > common conversion so I don't feel nearly as strongly about it as the string > one. > > Last, regarding internal functions, I do agree with Rasmus and Drew. Again, > judging by the examples brought up as a part of the discussion, it seems as > if we gave ZPP developers a standard easy way of being a lot more picky > about the types of values of particular arguments, and allowing them to do > this selectively for those places that are very sensitive (e.g. > curl_setopt()) would be a more suitable solution than just turning strict > validation for all internal functions, which were built with very very > different assumptions in mind. The biggest difference between internal > functions and userland functions in the context of this RFC is that with > userland functions, we're starting with a clean slate. There are no type > hint definitions anywhere, developers can selectively add them as they see > fit. With internal functions, we have type requirements EVERYWHERE already, > but with semantics that didn't take strict typing into account at all and > evolved for almost 20 years. Strict typing the way it is now would > radically change these semantics overnight, and will make the adoption of > strict a much bigger headache than it can be, as I believe Rasmus > demonstrated. > > I think addressing these issues could get us a LOT closer to consensus and > make a lot of those who voted 'no' on v0.3 vote yes on v0.4. > So, if you'll permit me to summarize your message. The following would be palatable to you? * Lossless coercion. This would sit somewhere between strict types and weak types as lossy conversions (object->__toString() for objects passed where string expected, any->bool) would be disallowed, but lossless conversions (numeric strings to number types, int to float, whole floats to ints, numbers to strings -- But no implicit conversions to bools, no non-numeric strings to numerics, etc...) * Exclude internal functions from the strict switch. (Perhaps have a separate switch for internal functions at a later date) With option to introduce features such as the following at a later date: * Union types (e.g. function foo((int | float) $value): (bool | string) { ... }) * Typedefs (e.g. TypeDef (int|float) numeric; -- Some defined as standard (like numeric), others user-definable) -Sara