Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82929 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39383 invoked from network); 17 Feb 2015 06:34:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 06:34:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=zeev@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=zeev@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 74.125.82.47 as permitted sender) X-PHP-List-Original-Sender: zeev@zend.com X-Host-Fingerprint: 74.125.82.47 mail-wg0-f47.google.com Received: from [74.125.82.47] ([74.125.82.47:51607] helo=mail-wg0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/B2-24654-EF0E2E45 for ; Tue, 17 Feb 2015 01:34:40 -0500 Received: by mail-wg0-f47.google.com with SMTP id x12so19640125wgg.6 for ; Mon, 16 Feb 2015 22:34:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:content-type:mime-version:subject:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to; bh=Uj4YMczzN+FLFIgsvZbPq3Swl+h7njvJafMtMCZ1u/0=; b=b0vwoS+lT0hrnnQgEx7lOC9Gx2BJNrrnJRb67wt2SOoA8hNqrH5NTBg7wXT+1jRvwq NF1sLLmomcIxgZCWQSSpQP/dTYunvzEkIk0ThcBYyXZ96+PjVJZG1Jn1K5Anko6g53Y4 zKw45NppX4Uyvljac9uBOkFu5cXGaNpC2PRYJ/JB5S/Lvz5QqLC6JpGB5mlf+tjRcnzc Pr7B5TwOAAEEsEgyajpy/5iZev0epZUzT0uEuAjflrq91yK0HVBmGGpLcvt4QEXizX80 iopjye2W9sL+nIR6wqEo2elLZjK+1t2qxa6V7F9hoYdsm/Xv6+9/RAEYRqZrtdT6tQPn fcEQ== X-Gm-Message-State: ALoCoQnPp3WfklxxPhCVdTrfZmN2wOM8R1KPgSfxAljnyS62e7PiQI/b0LdfRa9VUVAVeSGLuiWfXxIqFiywznKsqWu02jVARsC+Rqfyd+vS4jxpOQTEkubtOLbUUgnKAI1dqHCCdjF5TsX+BMtbtVto2WuHUeVUYA== X-Received: by 10.180.20.167 with SMTP id o7mr52899650wie.50.1424154876150; Mon, 16 Feb 2015 22:34:36 -0800 (PST) Received: from [10.160.90.193] ([2.54.36.198]) by mx.google.com with ESMTPSA id jg3sm22731980wid.0.2015.02.16.22.34.34 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Feb 2015 22:34:35 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) X-Mailer: iPhone Mail (12B466) In-Reply-To: Date: Tue, 17 Feb 2015 08:34:32 +0200 Cc: "francois@php.net" , PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <011801d04a07$83ab1c00$8b015400$@php.net> <016f01d04a3a$e9183220$bb489660$@php.net> To: Sara Golemon Subject: Re: [PHP-DEV] Reviving scalar type hints From: zeev@zend.com (Zeev Suraski) In a word, yes. Have to say you're abilities to compile Zeev -> formal decl= aration are pretty amazing :) Zeev > On 17 =D7=91=D7=A4=D7=91=D7=A8=D7=B3 2015, at 08:20, Sara Golemon wrote: >=20 >> 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, a= nd >> 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%: >>=20 >> 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 goi= ng >> to give us the most trouble - and is most probably the use case that by f= ar >> is going to result the largest amount of explicit casts to work around th= at >> problem. >>=20 >> 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? >>=20 >> No bool to int. No Apple to int. No "123 testing" to float. Just "32" t= o >> 32 and "37.7" to 37.7. >>=20 >> 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. >>=20 >> 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 o= f >> accuracy is lost. Rejecting this particular conversion places us at bein= g >> 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 stri= ng >> one. >>=20 >> Last, regarding internal functions, I do agree with Rasmus and Drew. Aga= in, >> 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 d= o >> 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 se= e >> fit. With internal functions, we have type requirements EVERYWHERE alrea= dy, >> 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. >>=20 >> I think addressing these issues could get us a LOT closer to consensus an= d >> 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? >=20 > * 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...) >=20 > * Exclude internal functions from the strict switch. (Perhaps have a > separate switch for internal functions at a later date) >=20 > With option to introduce features such as the following at a later date: >=20 > * 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) >=20 > -Sara