Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83039 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71344 invoked from network); 18 Feb 2015 10:51:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 10:51:07 -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.173 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.214.173 mail-ob0-f173.google.com Received: from [209.85.214.173] ([209.85.214.173:62271] helo=mail-ob0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CD/38-18888-99E64E45 for ; Wed, 18 Feb 2015 05:51:06 -0500 Received: by mail-ob0-f173.google.com with SMTP id uy5so518267obc.4 for ; Wed, 18 Feb 2015 02:51:02 -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; bh=FUfYt3HAQpf742nJI7Fuv/Brv9mWNqQFHP13b/+fr1M=; b=JM6IbSurkj+4NWA1iU9zRNhySVIViF20sAQ1ia2+0Lwoc9QHGibu180KpkRUtwbHnC N6jl1sRqO1Qpl80lIgusLsfUotEZgByTUpu2SybxDKkh67VdJFe+5dnBrqi04S3FBCNk O5KqO1N9EV3PZNBQf+N+XlRWzIn4VcA9f6v8U= 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; bh=FUfYt3HAQpf742nJI7Fuv/Brv9mWNqQFHP13b/+fr1M=; b=dvYawd4XIaNPLTsdSxTx6vozUGeAKsed3pM9cwPFJ16cLAiWE0xBc0N8RBxh0W/Wdx RucxXSBUXfjwGZTu4EF6o4SOWJbjPmxG108R1PkJHvLs6TYfvyofgIK0zGjv421VZTq8 Df7fOtWZIyh36JlVzIqqPT4AMYPKoVwWTGz9aTFCrCtJQUV+ncaXOrAHYznF1Dnyv/FC G4j1+S/39K26rr3c2Us5GDG3p1K27xw4dRVsAGw4l6AKpHDL95oDr4XaI4UQgZMAJCGd eHtTVYdXzduOfeNAioHeGpshU/Wi228DHs+50ionKxvz2LQvrc3TkuYQuF6NUZsnl/gP +JGg== X-Gm-Message-State: ALoCoQmUDzbSejU8WuKm/Dzs5Xk08DxdnWvoVsL5fr3sOfCp3Qjd5udJxm0gEcpUNGh5tq6wD28Z MIME-Version: 1.0 X-Received: by 10.60.63.97 with SMTP id f1mr21614209oes.16.1424256662203; Wed, 18 Feb 2015 02:51:02 -0800 (PST) Received: by 10.202.214.205 with HTTP; Wed, 18 Feb 2015 02:51:02 -0800 (PST) In-Reply-To: <54E46171.3010805@lsces.co.uk> References: <54E3E27B.2010903@lerdorf.com> <2f99c47df51fa6c73131032ec50fade0@mail.gmail.com> <54E46171.3010805@lsces.co.uk> Date: Wed, 18 Feb 2015 12:51:02 +0200 Message-ID: To: Lester Caine Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Scalar Type Hints v0.4 From: narf@devilix.net (Andrey Andreev) Hi, On Wed, Feb 18, 2015 at 11:54 AM, Lester Caine wrote: > On 18/02/15 09:14, Andrey Andreev wrote: >> 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. >> Obviously, that would be solved with automated testing, but >> unfortunately even code with high test coverage % often lacks depth in >> its test cases. > > Octal is something that can often be miss converted since it IS the same > as an integer with only a '0' in front in PHP. But that is not something > that can be fixed with the current proposals? Again we have to ensure > that the pre-processing takes care of the problem and how would static > analysis even know there was a problem? A type hint following the SQL > standards would be more helpful than the javascript approach of giving > an error in strict mode. > I'm not talking about octal, and nobody's talking about SQL here. 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 = 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.