Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79128 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69959 invoked from network); 24 Nov 2014 16:08:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Nov 2014 16:08:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=patrick.allaert@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=patrickallaert@php.net; sender-id=unknown Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.172 as permitted sender) X-PHP-List-Original-Sender: patrick.allaert@gmail.com X-Host-Fingerprint: 209.85.217.172 mail-lb0-f172.google.com Received: from [209.85.217.172] ([209.85.217.172:44341] helo=mail-lb0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A7/D5-33396-6E753745 for ; Mon, 24 Nov 2014 11:08:07 -0500 Received: by mail-lb0-f172.google.com with SMTP id u10so7657808lbd.31 for ; Mon, 24 Nov 2014 08:08:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:references:from:date:message-id:subject:to:cc :content-type; bh=6BrPRCgKKMqb2MNmd++IjJxVMGgR4OamL9apbqTSwVE=; b=EONtNtgWxEu58Mrw9/hE6bHayF6QH4Oumn58GJ5WLmW2Nnnc6irGSPX32dWpk0CDCo Uq+4d2oaHVZT+vLb9n7NvKEv7JOaKcXL+3ubo8lHsjEoJzppdI0UImsZrtBsNxhZO8gt HoOM2MnbI9FYQgN6SD0ziRU3fJm0Z/MvRM5d7a3875zVUJkAbQpPJxotSojaV9k1kOTA +7feZaav3xxaqQHyHex6Ox4SVUlqA6jTmNCTh59RUZIowxjMEA1hjFz4pr1jeW65Lu8g a8JY1TJDm1kEZIuk7Bhokbidiwoh7JYOrk+Jzu4rH2mDSI4ynYuKmXJm07d/z3ofjiq7 BrSA== X-Received: by 10.152.87.100 with SMTP id w4mr20888181laz.27.1416845283770; Mon, 24 Nov 2014 08:08:03 -0800 (PST) MIME-Version: 1.0 References: Date: Mon, 24 Nov 2014 16:08:03 +0000 Message-ID: To: Levi Morrison , Andrea Faulds Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c365aed7476205089cffd3 Subject: Re: [PHP-DEV] [VOTE][RFC] Safe Casting Functions From: patrickallaert@php.net (Patrick ALLAERT) --001a11c365aed7476205089cffd3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Le Wed Nov 19 2014 at 10:57:39 PM, Levi Morrison a =C3=A9cr= it : > > - 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. > 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). 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). - improve ext/filter to have stricter validation/sanitizing mechanism if this is missing. I would personally appreciate a syntax closer to the current casting mechanism, e.g.: $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 $int =3D (~int) "42"; // result: (int) 42 $int =3D (~int) "foobar"; // result: E_WARNING: Can not cast (string) "foobar" strictly to an int Note that I haven't investigate any possible syntax conflict. My 2 =E2=82=ACcents. Regards, Patrick --001a11c365aed7476205089cffd3--