Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58207 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81791 invoked from network); 27 Feb 2012 22:31:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2012 22:31:30 -0000 Authentication-Results: pb1.pair.com header.from=johncrenshaw@priacta.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=johncrenshaw@priacta.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain priacta.com designates 64.95.72.244 as permitted sender) X-PHP-List-Original-Sender: johncrenshaw@priacta.com X-Host-Fingerprint: 64.95.72.244 mxout.myoutlookonline.com Received: from [64.95.72.244] ([64.95.72.244:6910] helo=mxout.myoutlookonline.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C1/11-11273-1440C4F4 for ; Mon, 27 Feb 2012 17:31:29 -0500 Received: from mxout.myoutlookonline.com (localhost [127.0.0.1]) by mxout.myoutlookonline.com (Postfix) with ESMTP id 04A398BECF8; Mon, 27 Feb 2012 17:31:27 -0500 (EST) X-Virus-Scanned: by SpamTitan at mail.lan Received: from HUB013.mail.lan (unknown [10.110.2.1]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by mxout.myoutlookonline.com (Postfix) with ESMTPS id AD2E38BECB2; Mon, 27 Feb 2012 17:31:26 -0500 (EST) Received: from MAILR001.mail.lan ([10.110.18.27]) by HUB013.mail.lan ([10.110.17.13]) with mapi; Mon, 27 Feb 2012 17:31:21 -0500 To: Richard Lynch , "internals@lists.php.net" Date: Mon, 27 Feb 2012 17:31:20 -0500 Thread-Topic: [PHP-DEV] Scalar type hinting Thread-Index: Acz1h8YL9jgZiux6Q7yqIbi+nebpzAAEje0w Message-ID: References: <1330357150.2159.30.camel@guybrush> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: RE: [PHP-DEV] Scalar type hinting From: johncrenshaw@priacta.com (John Crenshaw) Inline > -----Original Message----- > From: Richard Lynch [mailto:ceo@l-i-e.com]=20 >=20 > On Mon, February 27, 2012 1:15 pm, Kris Craig wrote: > > Now, to rewind a bit past the latest chunk of "I hate this idea" > > posts.... > > > > I'd like to suggest a new term: "strong". > > > > This term would be similar to "weak", except with a few key > > differences: > > > > - Weak would behave very much like Arvids suggested in his earlier=20 > > post; > > i.e. if the variable is an integer but you pass a string (like > > "aaa") to > > it, a warning would be thrown and PHP would attempt to convert it=20 > > (i.e. it > > would become 1). >=20 > Nitpick: > Two backwards compatibility breaks: > 1) Throwing E_WARNING > 2) "aaa" converted to (int) is 0. Sorry, I don't understand the BC break on the warning. Old code doesn't hav= e this anyway, so what exactly would break? Shouldn't all existing scripts = continue to work exactly the same as before unless they add a type check? (I'm sure the example was just wrong, "aaa" should convert to 0) > > strong int $ii =3D "aaa"; // Throws a fatal error. >=20 > Okay. >=20 > E_FATAL seems drastic to me, but I'm not even going to use "strong" so do= n't really care either way, I suppose. I totally agree. E_RECOVERABLE_ERROR is the most severe that this should be= (also matches the behavior of current type hints). > > weak int $i =3D "1"; // Converts to 1. >=20 > Again, old-school (int) or set_type covers this. Unfortunately it doesn't completely. Yes, behavior is the same so long as t= he conversion is good, but a cast will silently accept impossible conversio= ns, which is not what you really want here. John Crenshaw Priacta, Inc.