Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81646 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37070 invoked from network); 2 Feb 2015 20:15:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 20:15:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:51269] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 28/72-25089-7FADFC45 for ; Mon, 02 Feb 2015 15:15:52 -0500 Received: (qmail 29205 invoked from network); 2 Feb 2015 21:15:48 +0100 Received: from cm56-153-252.liwest.at (HELO RoLaptop) (86.56.153.252) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 2 Feb 2015 21:15:48 +0100 To: "'Lester Caine'" , References: <54CFD8B3.9080208@lsces.co.uk> In-Reply-To: <54CFD8B3.9080208@lsces.co.uk> Date: Mon, 2 Feb 2015 21:15:47 +0100 Message-ID: <005101d03f25$08e157b0$1aa40710$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQI+MKsMv6zrm7KCv5jpZIs/BqhffwFEc745m/fDE5A= Content-Language: de-ch Subject: AW: [PHP-DEV] What do we need strict scalar type hints for? From: php@tutteli.ch ("Robert Stoll") > -----Urspr=C3=BCngliche Nachricht----- > Von: Lester Caine [mailto:lester@lsces.co.uk] > Gesendet: Montag, 2. Februar 2015 21:06 > An: internals@lists.php.net > Betreff: Re: [PHP-DEV] What do we need strict scalar type hints for? >=20 > On 02/02/15 09:12, Dmitry Stogov wrote: > > could you please write down few use cases, when strict scalar type > > hints are really useful. >=20 > Do we NEED strict scalar type control ... No Are there situations = where strict scalar type control may be useful ...Yes Can a > library be built ONLY using strict scalar type control ... Maybe ... = provided that it only requires a set of data that can be 'strict' >=20 > Much has been made of the idea that automatically causing errors when = a wrong scalar type has been passed will simplify > things, and in some cases that may be true, A few examples have been = thrown up which suggest that integer values are a > magic bullet when dealing with time or currency for example, but only = some elements of that can easily be constrained to > integers, other parts will require float or even string. > When there is an error in any of this would one not expect any good = library to produce a sensible set of error messages? A > generic 'value not integer' needs to be augmented, so error checking = against those elements that may be constrained > would be mixed with error checking with the more weakly typed elements = anyway? >=20 > I can see that for some cases there may be an advantage but would it = not be better to provide something that can act as a > validity check against any input rather than some limited set of data? = One 'class' that can identify where a scalar can be > constrained or give a more relaxed result when required ... rather = than having one rule for one and one for the other? >=20 > -- > Lester Caine - G8HFL Nobody would stop you from implementing a utility class Money or = likewise and providing a better error message instead of using int if = PHP would be strict only (what is not proposed in the RFC anyway). You = could also just omit the type hint, it is entirely up to you.=20 There are plenty of strongly typed languages out there which work very = well without the mentioned lack of specific error messages for each = individual use case. And btw. PHP is strict for array and class type hints as well - of = course you can also omit those type hints.=20