Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75600 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34928 invoked from network); 16 Jul 2014 19:52:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2014 19:52:31 -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.207 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.207 imap2-2.ox.privateemail.com Received: from [192.64.116.207] ([192.64.116.207:45724] helo=imap2-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6C/E5-31820-EF7D6C35 for ; Wed, 16 Jul 2014 15:52:31 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 21C948C007D; Wed, 16 Jul 2014 15:52:28 -0400 (EDT) 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 xsSQJdOm3oJY; Wed, 16 Jul 2014 15:52:27 -0400 (EDT) Received: from [192.168.0.15] (unknown [90.210.122.167]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 887438C007B; Wed, 16 Jul 2014 15:52:26 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <53C6D6E4.4030006@gmail.com> Date: Wed, 16 Jul 2014 20:52:21 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <08D4D9FE-DF48-4DBC-8577-351520606566@ajf.me> References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <16D48604-0C0A-4613-91A4-21392E3A2636@ajf.me> <53C3DB42.7090205@gmail.com> <3158105795AAC1408619EC8BA03384A93D0214F5@EXC-PUB01A.leedsmet.ac.uk> <53C5673D.8030201@gmail.com> <99B9138F-3E18-4DF6-8934-DADD6C99E438@ajf.me> <53C57A02.8020001@gmail.com> <1366DEE2-8B5C-4814-89A5-0A191F963CB4@ajf.me> <53C6D6E4.4030006@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: ajf@ajf.me (Andrea Faulds) On 16 Jul 2014, at 20:47, Rowan Collins wrote: > I think this would be quite nice - keeps things relatively short = without introducing so much punctuation that it starts looking like a = Perl script ;) >=20 > The only problem is that either you need a whole set of functions = (safe_int($foo), safe_float($foo), etc) or you need some format for that = second argument, which gets you into some odd meta-validation: if you = take a string, or an integer (expected to be in the form of a constant = like PHP_INT), then it would be possible to write safe_cast($foo, $bar), = and now we need rules on validating $bar, and what happens if it's = wrong. >=20 > The magic form with a keyword like you've written avoids that, but it = feels kind of weird - like when SQL date functions take things like = "day" and "hour" as barewords rather than strings. Perhaps this could work? if (safe_cast((int!)$foobar)) { $foobar =3D (int!)$foobar; } else { $foobar =3D 1; } With safe_cast() being a pseudo-function =E0 la isset() et al. I=92m not really sure adding a new set of safe casts is really such a = good idea; we don=92t really need (int!) even, we could just have = can_cast_int_strict (or something like that) given that (int) and (int!) = do the same thing for the non-failure cases. And perhaps it=92d be better just to leave this to scalar type hints, = I=92m not sure I really want to add this stuff... -- Andrea Faulds http://ajf.me/