Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83061 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12013 invoked from network); 18 Feb 2015 13:10:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 13:10:34 -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.181 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.214.181 mail-ob0-f181.google.com Received: from [209.85.214.181] ([209.85.214.181:36551] helo=mail-ob0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/50-18888-A4F84E45 for ; Wed, 18 Feb 2015 08:10:34 -0500 Received: by mail-ob0-f181.google.com with SMTP id vb8so1514269obc.12 for ; Wed, 18 Feb 2015 05:10:32 -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=imqvb+w4c29gAsjo986zEjTkxG52/ELYZXxgs6M/RNw=; b=GsqLlHTrLoR5KeiCGmKsP8UoSDJufiVo09ubVjgHVYsH+un7vBliYr8Y9bCKrKvYst eSICDbWoBUlYPaqE6mpwJyvSBmhCKfgIBu4AcWwfoteLzDtBQLJx+xZaM8NFtlUoT4Pp bxgsBbvquxzN1weXivj6rW52E/6uS19Ass3X4= 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=imqvb+w4c29gAsjo986zEjTkxG52/ELYZXxgs6M/RNw=; b=IMsv0cpsOL6zbuV2Wm2A71yNLJx3hJppqsFBgeXwoP47YA4DwdxCT+drZQKbKPyzy4 Z8pquBj5XCdoihrkaf5tHrKPlUARI5jfqxFymXr/g5M0SkFpvbz2QiSxf/eXMiaP0CRt 5bHTazxjxQDZ4/fg0ldRDW49EtuSwHjqmU9wvVf3rqi+T4uaIDXy7OgKPk8ApFHZX0PP Du1HYnxExd/2joukLML7Q4ACvqG0Ln9RAHW4CvEfv6dR5FqhsY4e21y9CBKOvkF2uf33 g3EpLkTTyOCQyO+fB4hVTDnNsK7yL7uUmtTctveTv1+TVFdHsUVevsBl1j3XZ64M8vZP bpUw== X-Gm-Message-State: ALoCoQn2m03V23Mz3XX37fcESvJp+Het8Mrk0RN270DhQfc7yTlxw/iDxEFsEFqGgG3A0vhBXHIJ MIME-Version: 1.0 X-Received: by 10.202.64.9 with SMTP id n9mr20570091oia.20.1424265031891; Wed, 18 Feb 2015 05:10:31 -0800 (PST) Received: by 10.202.214.205 with HTTP; Wed, 18 Feb 2015 05:10:31 -0800 (PST) In-Reply-To: References: <54E3E27B.2010903@lerdorf.com> <2f99c47df51fa6c73131032ec50fade0@mail.gmail.com> <54E46171.3010805@lsces.co.uk> Date: Wed, 18 Feb 2015 15:10:31 +0200 Message-ID: To: Zeev Suraski 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 Zeev, On Wed, Feb 18, 2015 at 2:31 PM, Zeev Suraski wrote: >> 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. > > Thanks the example Andrey, it's helpful. > > My goal with asking for these use cases isn't to claim that they never > exist, and I certainly don't want to get into a theological discussion. My > goal is to try and figure out whether many, if not all, proponents of strict > typing would be willing to live with a compromise on single set of rules, > that on one hand would be a lot stricter than what was proposed for weak > typing in the v0.3 RFC (bool->anything fails, any string that's not strictly > looking like a number incl. "100 dogs" -> int/float fails, float->int > fails), but on the other hand, would allow certain lossless conversions > (numeric string -> int/float, int->float, toString() to string, etc.) to > work. > I didn't imply that you meant any of that, not in this thread anyway ... If I've done it previously, it's only because your choice of words had made it appear that way. You don't need to defend yourself everytime I quote you. :) > When people from both schools of thought (strict/weak) come to evaluate this > possibility, remember that we don't need a solution that works in 100.0% of > the cases. Edge cases, again, be them strict or weak, can always be > implemented with a bit of custom code inside the function - the important > thing is to get a system that addresses the vast majority of cases. > Well, that's usually the case because you simply can't provide a 100% solution. In this case, I believe we can satisfy if not 100%, then 99% of the use cases by simply providing both weak and strict hints simultaneously. From my POV, further restricting conversion rules for weak hints is deffinately an improvement, but still a limited one. There's no *technical* limitation to including two solutions to the problem, so I'd rather do that and be practical instead of following a belief for what does or doesn't belong in PHP. I know you're on the flip side, so we shall agree to disagree on that. Cheers, Andrey.