Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79007 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71042 invoked from network); 19 Nov 2014 18:47:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2014 18:47:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.208 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.208 imap2-3.ox.privateemail.com Received: from [192.64.116.208] ([192.64.116.208:42101] helo=imap2-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6B/43-51809-BA5EC645 for ; Wed, 19 Nov 2014 13:47:07 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id AFCB38C0080; Wed, 19 Nov 2014 13:47:04 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap2.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap2.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 4rV1oWGYfRUi; Wed, 19 Nov 2014 13:47:04 -0500 (EST) Received: from oa-res-27-29.wireless.abdn.ac.uk (oa-res-27-29.wireless.abdn.ac.uk [137.50.27.29]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 4D27C8C0083; Wed, 19 Nov 2014 13:47:03 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: Date: Wed, 19 Nov 2014 18:47:00 +0000 Cc: Yasuo Ohgaki , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <81B335A0-28EA-421E-B568-994E14A68604@ajf.me> References: <66B7B28C-2651-4A71-AC2A-55D4C7BB3DDC@ajf.me> <656B2A54-572B-4E6A-892B-25FAE428F434@ajf.me> <3844e0dd17eef0f8991dd01eda533e2e.squirrel@webmail.klapt.com> <1433D80F-85DF-45A9-B9E8-2E48E0B6321C@ajf.me> To: Anatol Belski X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] [RFC] Safe Casting Functions From: ajf@ajf.me (Andrea Faulds) > On 19 Nov 2014, at 18:28, Anatol Belski wrote: >=20 > On Wed, November 19, 2014 15:49, Andrea Faulds wrote: >>=20 >>> On 19 Nov 2014, at 08:33, Anatol Belski = wrote: >>> object(Stringable)#2 (0) {} - and similar actually, what if = _toString() >>> returns some int/float literal? that should pass as well, no? >>=20 >> __toString() always errors if it doesn=E2=80=99t return a string, I = see no reason >> to change that. > But in the other cases it converts strings to numbers. I mean like > class A {function __toString(){return '10';}} $a =3D (string) (new A); > //numeric literal ? I see no numbers? > IMHO it's a new rule set around the old thing. There's no way to = foresee > all the scenarios. Say I expect an an input to be less than 3. It's up = to > a programmer whether to check that the input is (int)'3' > 3 and give = up, > or to try sscanf('2e+22', '%f')[0] > 3. Even not talking about regex. > There are already mechanisms allowing to implement that, customizable = to a > high level and usually one can come up with them. Maybe that rule set > would sometimes let spare a line, still it depends on concrete use = case. It=E2=80=99s not meant to cover all scenarios. It=E2=80=99s meant to = failsafe on edge cases, rather than producing apparently valid values = which the user didn=E2=80=99t actually intend (so =E2=80=9CN/A=E2=80=9D = won=E2=80=99t become 0). -- Andrea Faulds http://ajf.me/