Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83057 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3738 invoked from network); 18 Feb 2015 12:45:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 12:45:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.214.171 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.214.171 mail-ob0-f171.google.com Received: from [209.85.214.171] ([209.85.214.171:43497] helo=mail-ob0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BF/9E-18888-C5984E45 for ; Wed, 18 Feb 2015 07:45:17 -0500 Received: by mail-ob0-f171.google.com with SMTP id gq1so1444935obb.2 for ; Wed, 18 Feb 2015 04:45:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=dYNUZtM0T/iUtU/YDDL2zAHgsK849KFeuIjgeFUCv8I=; b=gSGikUxgomEXBHUMPPqQhWy+neJ5XnW46wm1a/UxNpGFQSp+Un3hsLHdIXH+AoRmPW bLjFsvMyCx/+T9zewuIIZQwxrpgdLJxkle+7qPdjTyQ/owbqIYihVEyGpu9liSiGpAR3 pNMD9Gg65VNGfhBcozNcpI3stHRH+ICDrhGQU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=dYNUZtM0T/iUtU/YDDL2zAHgsK849KFeuIjgeFUCv8I=; b=R5IgznZ3H7Drw0DZEWqoGjTVpiRSdgLASkjJqCrTcaxh9olK8S95MB3k9oaseMIuy7 GHKvCr1rxRa8JvGkJoLSz4aQLILxRa7nPHQJxKfPyJ4YwbKaqkFEQuXpvoovpZykwldS XOn8J7V9H1d0VcDKtD504lg7/f0UFTh2sBUOlL8ooskIZYWogrN3O+aPQy8zwJJ1Ca34 e+rZlSpbNLGzKdRJlmP4dnbbOhDEscD5qZL/RecpNkLG395VX+HcJtnEx0+RT+BZE5ct Lp1B38y4TTmcsO5QMIDhqMN3NvOsyb8haL35l+plJUUDpERfQOe339/9KGDXSqWjGH52 Lo2g== X-Gm-Message-State: ALoCoQlglUSoC5dfirc2Z/vNdE6dvWcWA7c12sPT2340sbxLHXWMrvRLhuyvbDlShWTGiF3Z18qa MIME-Version: 1.0 X-Received: by 10.202.202.14 with SMTP id a14mr20788307oig.5.1424263512857; Wed, 18 Feb 2015 04:45:12 -0800 (PST) Received: by 10.202.214.205 with HTTP; Wed, 18 Feb 2015 04:45:12 -0800 (PST) In-Reply-To: <030901d04b76$4a1fb340$de5f19c0$@php.net> References: <54E3E27B.2010903@lerdorf.com> <2f99c47df51fa6c73131032ec50fade0@mail.gmail.com> <030901d04b76$4a1fb340$de5f19c0$@php.net> Date: Wed, 18 Feb 2015 14:45:12 +0200 Message-ID: To: francois@php.net 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: narf@devilix.net (Andrey Andreev) Hi, On Wed, Feb 18, 2015 at 2:27 PM, Fran=C3=A7ois Laupretre = wrote: > Hi Andrey, > >> De : Andrey Andreev [mailto:narf@devilix.net] >> >> 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. > > Please give use cases. Do you want to support '0xhexa' strings ? that's p= ossible. We are not only restricting possible conversions, we can also supp= ort additional syntaxes. Just give use cases for what you think should be e= nabled or disabled, compared to the current behavior. > > The only change we have in list so far about (string -> number) is reject= ing trailing chars (but accepting trailing blanks). > > We are in the process of changing these rules so, please give examples of= ' numeric-character string identifiers being erroneously treated as intege= rs'. If you mean '7 years', it's in list already. If others, tell us. > >> That is especially bad when such identifiers are in fact generated as >> integers first so that they are incremental, but the >> program/database/business logic requires them to be fixed-length >> strings and/or in hexadecimal format. In such cases, even silently >> discarding leading zeros can prove to be problematic, while in the >> case of hexadecimal representations you'd need more than 10 data >> samples to notice the problem if you don't use a strict hint. > > Do you mean we should accept hexadecimal string as int ? why not ? Give e= xact syntax(es) you want to support (except leading/trailing blanks, which = are default now). > No, I meant the opposite ... I was trying to explain cases where a weak hint would be insufficient. Sorry for not including examples in my first mail, I did that in my next reply: > Consider the following signature: > > function foo(int $bar) {} > > In the case of a *string* representation of a hexadecimal number, the > following would error only on the last iteration with a weak hint, and > on the very first if it was a strict hint: > > for ($i =3D 0; $i < 11; $i++) > { > foo(base_convert($i, 10, 16)); > } > > And when I said leading zeros, I was talking about fixed-length string > identifiers such as '001', '002', etc. where you may *unintentionally* > pass such a value to a function that deals with ... quantities, for > example. A strict hint in that case would immediately catch this > logical error while a weak hint would silently ignore the leading > zeros and will happily treat the value as an integer. Again, the > precondition here is that it's not an integer value that happens to be > stored as a string, but a non-integer value that just looks like an > integer. Cheers, Andrey.