Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83073 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39651 invoked from network); 18 Feb 2015 14:50:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 14:50:00 -0000 Authentication-Results: pb1.pair.com smtp.mail=padraic.brady@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=padraic.brady@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.47 as permitted sender) X-PHP-List-Original-Sender: padraic.brady@gmail.com X-Host-Fingerprint: 209.85.213.47 mail-yh0-f47.google.com Received: from [209.85.213.47] ([209.85.213.47:38024] helo=mail-yh0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/95-18888-796A4E45 for ; Wed, 18 Feb 2015 09:49:59 -0500 Received: by yhzz6 with SMTP id z6so988080yhz.5 for ; Wed, 18 Feb 2015 06:49:56 -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=0sQILOSQ/9AoJtwCnv+c8zCj1IYMlzEeaj652tJkIRE=; b=Zvx+BSGbZ8XATWHck1LI7VwajLC7STvaup7w61oLe4y3x+5WqoUJFLrBu1DN1gs09m iwqdrgYxsvwJ2b07v+DPvMq/OnFk4drofu+RN4bsPILz5o/IlbCnNvGheq2/iLwSIQvq kgGZZaYNTe0HXB+YgmTijeEqurIZ+vdX9qNPnHtFQ6X2zjsFSL/lUsqYOOlSIssTtM6S pW/C9KlfJIBuUUlc6duQm8SkpqQ3wKb3OrmSkhAGJ31D8Z8qWKWQPNoiDg8hMiezu2XZ 3bD7uR28rUOm1p8NMySoVoY9/hVUE5Mln8VyHYvkdCm0ge3Q8XgWvJpHkIdfYzK26UYw JVlg== MIME-Version: 1.0 X-Received: by 10.236.28.129 with SMTP id g1mr1922577yha.7.1424270996749; Wed, 18 Feb 2015 06:49:56 -0800 (PST) Received: by 10.170.222.86 with HTTP; Wed, 18 Feb 2015 06:49:56 -0800 (PST) In-Reply-To: References: <54E3E27B.2010903@lerdorf.com> <2f99c47df51fa6c73131032ec50fade0@mail.gmail.com> Date: Wed, 18 Feb 2015 14:49:56 +0000 Message-ID: To: Andrey Andreev Cc: Zeev Suraski , Nikita Popov , Rasmus Lerdorf , Sara Golemon , PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Scalar Type Hints v0.4 From: padraic.brady@gmail.com (=?UTF-8?Q?P=C3=A1draic_Brady?=) Hi all, On 18 February 2015 at 09:14, Andrey Andreev wrote: > Hi, > > On Wed, Feb 18, 2015 at 9:00 AM, Zeev Suraski wrote: >> I am wondering what the point is indeed with preventing "123" to 123. S= o >> far, all the concrete use cases people brought up had to do with "Apple"= or >> "100 dogs", but nobody ever seems to be able to explain why converting "= 123" >> to 123 is likely to be a problem real world. Is it really just static >> analyzers? >> > > I too am curious about the potential issue with "123" to 123 > specifically, although it could be seen as a subset of another problem > that is solved with strict hints - numeric-character string > identifiers being erroneously treated as integers. If I may interject briefly (doing it anyway!), there are so many concepts being munged together that there's bound to be confusion (on the part of idle readers like me). For this specific case, would I as someone who wants strict/strong typing really care whether =E2=80=9C123=E2= =80=9D was coerced to an integer? No. Others are free to disagree. I actually don=E2=80=99t mind there being a certain amount of logical coercion between types where it makes sense. That=E2=80=99s not, per se, fully in accordance with strictest to the strict degree typing which was Nikita=E2=80=99s point= . Coercion is itself a symptom of weak typing, so the more coercion one introduces, the weaker the typing. However, =E2=80=9C123=E2=80=9D is exceptional. It=E2=80=99s redefining an i= nteger as =E2=80=9C an integer or a string comprised wholly of digits without leading zeroes, with an optional leading hyphen, and representing an integer up to PHP_INT_MAX=E2=80=9D, i.e. an integer or a string with a real number that b= e made an integer without loss. No other string need apply. That=E2=80=99s no= t strict-strict typing (there=E2=80=99s coercion) but it=E2=80=99s probably s= trict enough to pass muster (it=E2=80=99s one single obvious coercion under limit= ed circumstances). Then again, it=E2=80=99s an exception that requires a long sentence. It=E2= =80=99s just not clear, to me, if this is the sole intended exception, or if that sentence needs to be expanded to a paragraph. A section? Are we going to need a chapter? I=E2=80=99m assuming octals-in-a-string are a no-go to b= e coerced whereas others might just see an integer with superfluous leading zeroes. In a future RFC revision, it might be nice to have a table of the specific coercion rules applicable to a weak/strong/single-unified option. Granted, final implementation details may be not 100% certain, but in this case any variation in implementation can have significance as to whether something is weak/strict/or lies somewhere else on the spectrum in between. So, I agree with Nikita that this is less than strict typing, but one single logical exception doesn=E2=80=99t instantly demote it to extreme wea= k typing if its sufficiently narrow in scope. We are compromising, no? It=E2=80=99s imperfect in other ways, but I=E2=80=99ll let others debate if= those are significant or not. Paddy -- P=C3=A1draic Brady http://blog.astrumfutura.com http://www.survivethedeepend.com