Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81671 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90752 invoked from network); 2 Feb 2015 23:34:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 23:34:51 -0000 Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.17.22 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.17.22 mout.gmx.net Received: from [212.227.17.22] ([212.227.17.22:51122] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EA/AD-25089-A9900D45 for ; Mon, 02 Feb 2015 18:34:50 -0500 Received: from [192.168.0.100] ([91.67.244.80]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0MGFz9-1YOoAj0lMd-00FE6G; Tue, 03 Feb 2015 00:34:46 +0100 Message-ID: <54D00996.8010005@gmx.de> Date: Tue, 03 Feb 2015 00:34:46 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Andrea Faulds CC: Thomas Bley , Dmitry Stogov , nikita.ppv@gmail.com, internals@lists.php.net References: <20150202210349.6FB91261948@dd15934.kasserver.com> <54CFE965.2080905@gmx.de> <20150202214254.BEB88261948@dd15934.kasserver.com> <54CFFC5D.4000802@gmx.de> <619EAE9D-615B-409D-AB8C-E64B2B113A6E@ajf.me> In-Reply-To: <619EAE9D-615B-409D-AB8C-E64B2B113A6E@ajf.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:zEAKcCj0/uo/tH20EIHNdolA7QpEOfbsH3UqCM1liBe2rDNv6eX NmzYQOTt+pofoUPT+fz1YudGYjItNbl1LUwhFdWb4WHtcfKMtu+lbJ79oxNZkCeSybjh4Um ugtecr4ebbxe+TK5b6mT7sv30tQnYRJ2lsd3TM9k4JWd9hFVJ9xJvkkOnG9vHMuvgx96COc 9BX0O3TlIIv7tBOq9anJg== X-UI-Out-Filterresults: notjunk:1; Subject: Re: [PHP-DEV] What do we need strict scalar type hints for? From: cmbecker69@gmx.de (Christoph Becker) Hi Andrea, Andrea Faulds wrote: > Hi Christoph, > >> On 2 Feb 2015, at 22:38, Christoph Becker wrote: >> >> And frankly, I don't see what's wrong with a weak type hint in this case: >> >> function addVat(float $amount) {...} >> >> You're returning a float, anyway. > > Given you’re dealing with currency, and given the fairly serious issues with precision loss with int->float conversions and vice-versa… I would be highly concerned if you used a weak type hint there. Well, considering the given function body ($amount * 1.19), that doesn't seem to be an issue. In the general case, if one has to deal with currency, float is problematic anyway. I'd rather use a rational type in this case (i.e. an immutable class with GMP[1] numerator and denominator properties and the respective methods), which could be combined with the actual currency (i.e. a "Money" class), if necessary. >> OTOH, strict type hints would require a lot of manual conversions. > > Sure, they do. But they’re *explicit* manual conversions, ones you can easily grep for and that are obvious when reading code. Indeed, code is read far more often than it's written (hopefully :)), but still it might be annoying for many PHP programmers to write these explicit manual conversions in the first place.[2] [1] Or int, if your Big Integer Support RFC will pass (which I would welcome, BTW). [2] I'm aware that your current Scalar Type Hints RFC would not require these manual conversions, but that doesn't seem to be the topic of *this* thread. :) -- Christoph M. Becker