Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83055 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99823 invoked from network); 18 Feb 2015 12:31:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 12:31:16 -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 209.85.223.170 as permitted sender) X-PHP-List-Original-Sender: zeev@zend.com X-Host-Fingerprint: 209.85.223.170 mail-ie0-f170.google.com Received: from [209.85.223.170] ([209.85.223.170:45305] helo=mail-ie0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/FD-18888-31684E45 for ; Wed, 18 Feb 2015 07:31:16 -0500 Received: by iecat20 with SMTP id at20so764028iec.12 for ; Wed, 18 Feb 2015 04:31:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:cc:content-type; bh=7Or9gJBrGVa5p8G6UhhtXCYecCSxtPnRsxShEvnQi5U=; b=RI8WmvpJllqhlYetN/ZIc2EWng7oMVB2Y+a7ZOeKca/IL3nIBymJNvgHionHRraC49 2sQYVZRxkCHQXekm1q9/GJaUCLhx5NMN2KmDcjB8bs3JlYJpbVzVl7lTlDNZ/SRqvY6t n6cuOoqjXCzimqMpGAPU8OIb1iJ7cOy13I/zTqs93cFlHZOAkHeli3shjl4mIVsLSPIR Vq9LSbgLZXe3Wl1neCFRUvmIEdD6p5rIWYo7yTn0mxd/pQbxXiwJ6LhX02DxTLdtc9nU /ayTDEliyehA2qaT59L5pNpaYOb4rHmSU3Zc9Cy6As5/0DFB96/VoIX6sim9WYuMBCHW mLbw== X-Gm-Message-State: ALoCoQlQG/bImVANL8yEwfLYAM3perK6T5bYk/1lnz0LLNYT+t4e4+FFJrA8HBfacq+ASjU6tkoUqdIPjtLeVT3tlLiR1KLB1nFmZL3iy/CmNmjhY9sWzWy8JjwBtRajqN97rwQP77Lck3js1Nm2hTiGlZYPMrWsWQ== X-Received: by 10.107.137.17 with SMTP id l17mr40504847iod.33.1424262672023; Wed, 18 Feb 2015 04:31:12 -0800 (PST) References: <54E3E27B.2010903@lerdorf.com> <2f99c47df51fa6c73131032ec50fade0@mail.gmail.com> <54E46171.3010805@lsces.co.uk> In-Reply-To: MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQKz6wpj8b81mnwJq1LfxWbU4ZJyQgGjcksIAbrU1N8Bn0wufQGLyLi6AmixSwcCFGxi7gFUJDhrmsw+cBA= Date: Wed, 18 Feb 2015 14:31:10 +0200 Message-ID: To: Andrey Andreev Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: RE: [PHP-DEV] Scalar Type Hints v0.4 From: zeev@zend.com (Zeev Suraski) > 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. 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. Thanks! Zeev