Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75599 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33433 invoked from network); 16 Jul 2014 19:48:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2014 19:48:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wg0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:52101] helo=mail-wg0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/95-31820-2F6D6C35 for ; Wed, 16 Jul 2014 15:48:02 -0400 Received: by mail-wg0-f42.google.com with SMTP id l18so1417511wgh.25 for ; Wed, 16 Jul 2014 12:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=sm0LBpHva08xfK+uPYIqyYwxHuu7JxrkkXQIHsiBORw=; b=qu10mHrNJkbpGompTLbXfAkIkybWiArRZKfQllAMEhVUniv6chRRoarMkKyFyO7MIi jXfmGHulJlEWfXtk5yk3egMHXcyFSHA12U6aVo9l7KccTD6yQkX3lFBQ2/fbtNwrpdtA wQRuphcNH9e/QS9Mc1bVrBpbsZIXCzaGOjUjWxiXB/qxSQs5O7GH+IxkPaC/A9hQoPng fraOecDPXYsqwl1JtgL9bYIW2KYLWqjiW7Y5LimkopbmMO7Sknow+9fa1lqNWxabb/Na nto08WgVDw0txAU6L7Ys9STjVTw+3/TnRoRHykZ5AafEXMhAFlg7vEi/y7KoDEP/kNIu QBiA== X-Received: by 10.180.21.172 with SMTP id w12mr16521609wie.31.1405540079255; Wed, 16 Jul 2014 12:47:59 -0700 (PDT) Received: from [192.168.0.2] (cpc19-brig17-2-0-cust25.3-3.cable.virginm.net. [81.101.201.26]) by mx.google.com with ESMTPSA id w10sm12455657wie.22.2014.07.16.12.47.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 16 Jul 2014 12:47:58 -0700 (PDT) Message-ID: <53C6D6E4.4030006@gmail.com> Date: Wed, 16 Jul 2014 20:47:48 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: internals@lists.php.net 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> In-Reply-To: <1366DEE2-8B5C-4814-89A5-0A191F963CB4@ajf.me> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: rowan.collins@gmail.com (Rowan Collins) On 15/07/2014 20:44, Andrea Faulds wrote: > PHP has pseudo-functions, maybe we could use that format? cast_int($foo)? > > Actually, perhaps the solution is an ahead-of-time check: > > if (safe_cast($foo, int)) { > $bar = (int!)$foo; > } else { > $bar = 1; > } I think this would be quite nice - keeps things relatively short without introducing so much punctuation that it starts looking like a Perl script ;) 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. 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. Maybe I'm overthinking it though. -- Rowan Collins [IMSoP]