Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79129 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71442 invoked from network); 24 Nov 2014 16:11:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Nov 2014 16:11:58 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:60279] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/26-33396-AC853745 for ; Mon, 24 Nov 2014 11:11:55 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id C52DD2400A9; Mon, 24 Nov 2014 11:11:51 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 1fHSjwcfeYTj; Mon, 24 Nov 2014 11:11:51 -0500 (EST) Received: from oa-res-27-210.wireless.abdn.ac.uk (oa-res-27-210.wireless.abdn.ac.uk [137.50.27.210]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id ED60E2400AA; Mon, 24 Nov 2014 11:11:50 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: Date: Mon, 24 Nov 2014 16:11:48 +0000 Cc: Levi Morrison , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Patrick ALLAERT X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] [VOTE][RFC] Safe Casting Functions From: ajf@ajf.me (Andrea Faulds) > On 24 Nov 2014, at 16:08, Patrick ALLAERT = wrote: >=20 >=20 > Le Wed Nov 19 2014 at 10:57:39 PM, Levi Morrison a = =C3=A9crit : > - PHP suffers a lot from function bloat and this RFC provides > multiple functions that do the same thing but differ only in how they > handle errors. A simple validation of "can this be safely cast to an > integer without dataloss?" avoid the issue entirely and would be fewer > functions. >=20 > My "no" is mostly for the reason above, mentioned by Levi and also = because of the use of Exception (previously mentioned by Derick as = well). >=20 > To improve this RFC, I would: > - use errors/warnings instead of exceptions (unless there is a more = global approach on this aspect for PHP 7). Errors in PHP are horrible to handle. There=E2=80=99s absolutely no = question of this RFC being revived using errors, at all. If I must, = I=E2=80=99ll wait until exceptions are inevitably approved for core in = PHP 7. Assuming they actually are. If they aren=E2=80=99t, I might = actually quit PHP... > I would personally appreciate a syntax closer to the current casting = mechanism, e.g.: >=20 > $int =3D (=3Dint) "42"; // result: (int) 42 > $string =3D (=3Dstring) 42; // result: (string) "42" > $int =3D (=3Dint) "foobar"; // result: E_ERROR: Can not cast = (string) "foobar" strictly to an int >=20 > $int =3D (~int) "42"; // result: (int) 42 > $int =3D (~int) "foobar"; // result: E_WARNING: Can not cast = (string) "foobar" strictly to an int PHP already already has enough bizarre syntaxes, I don=E2=80=99t think = it needs even more. -- Andrea Faulds http://ajf.me/