Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75480 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17952 invoked from network); 14 Jul 2014 16:04:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2014 16:04:45 -0000 Authentication-Results: pb1.pair.com header.from=zeev@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=zeev@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.176 as permitted sender) X-PHP-List-Original-Sender: zeev@zend.com X-Host-Fingerprint: 209.85.220.176 mail-vc0-f176.google.com Received: from [209.85.220.176] ([209.85.220.176:48029] helo=mail-vc0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3A/95-25444-B9FF3C35 for ; Mon, 14 Jul 2014 12:04:45 -0400 Received: by mail-vc0-f176.google.com with SMTP id ik5so7548263vcb.21 for ; Mon, 14 Jul 2014 09:04:41 -0700 (PDT) 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=Wat06w6QzvG8HAq8Vr+GhFp2efV0QQb6RRqyDp2tfB4=; b=ewp4/au+Ri7OHNd/23WEV0qx4v5+wEBXV29MZZSmnxANPdlBPsKvKsEXy7vOj7Nujw y2YFr/inWHFzHXwb5rTRJF4vHFld8JyWmwvBSDdfG00/LKqL3452kX6GIRFEAzmp9TK7 8DUmKbsN/gSdLr4bgCFqVZSH+iohAAjsk6SsvRXdBysJfgq3owBe6UKmsO2y+hwOga64 bh9f1wZJXpngQ2chvQAn/pqJSiE0FJ8Jn8xt/uH5E2+mTqDhcjOSiRsq7sd66Xok14dC ut2JQJHqN1prrqfquqUKBsG6xYZSEwC3cGE2sB9HlN2w+UawxItV+mGBbGlbKoILn34H c4eQ== X-Gm-Message-State: ALoCoQlPc/f2vpiEQrZCYnIdR6eg5t4FK4zZVnwnitZXr2NLxzLwX/+AwshAkgnL8krLarPaXfp5bdn+gWzaQt/kJ8jpdOh0DDHEiKckD9k2JDvcewb2F2joQhqgAN4P7qxTZzBjFFIZ X-Received: by 10.220.200.71 with SMTP id ev7mr3843145vcb.24.1405353880956; Mon, 14 Jul 2014 09:04:40 -0700 (PDT) References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <53C3F70A.7010706@gmail.com> <3aa29e080d70c843713e19a952dfbad6@mail.gmail.com> In-Reply-To: MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQJuUFVOlGiX172RfpkkW7aXwqSXwwHleMkPAd/qfJcBzHP03AGqtGtJAmKS0moBHXfO1poMclIw Date: Mon, 14 Jul 2014 19:04:40 +0300 Message-ID: <3b06c592b0b88bb95d3ae7ea7a93d86f@mail.gmail.com> To: Andrea Faulds Cc: Rowan Collins , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: zeev@zend.com (Zeev Suraski) > -----Original Message----- > From: Andrea Faulds [mailto:ajf@ajf.me] > Sent: Monday, July 14, 2014 6:49 PM > To: Zeev Suraski > Cc: Rowan Collins; internals@lists.php.net > Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) > > > On 14 Jul 2014, at 16:46, Zeev Suraski wrote: > > > Actually there's a pretty simple way that's not strict type hints: > > > > 5) Add type hints using existing syntax, which are casts; Change > > casts (both existing and these new ones) to emit a new E_CAST in case > > of data loss or 'bogus' conversions. > > How is emitting a new E_CAST useful? Most people are not going to write > error handlers that will act on it, so it'll just be an E_WARNING so far as most > people care, and we'll just end up with casts, which you can already do: > > function foo($a) { > $a = (int)$a; > } I already mentioned before that I don't think consistency is a bad thing (and that's an understatement). Having the syntax differ and have a separate, similar set of rules/behaviors is a disadvantage, not an advantage in my book. There are several advantages of adding this syntax with the simple casting behavior: 1. It saves a bit of code and improves readability for a *very* common use case. 2. It encourages developers to get the types straight instead of relying on implicit casts. 3. It reuses syntax we already use for type hinting so it doesn't drive complexity up significantly. 4. It allows people to go extra strict very easily, by turning E_CASE into errors. My guesstimate is that the majority of people won't, but it'll be possible and easy to do nonetheless. 5. It maintains consistency with casts (that's a feature, not a bug :) Zeev