Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81626 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3859 invoked from network); 2 Feb 2015 18:41:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 18:41:44 -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:36329] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 10/BE-34915-6E4CFC45 for ; Mon, 02 Feb 2015 13:41:43 -0500 Received: (qmail 12021 invoked from network); 2 Feb 2015 19:41:39 +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 19:41:39 +0100 To: "'Dmitry Stogov'" , "'PHP Internals'" , "'Andrea Faulds'" , "'Nikita Popov'" References: In-Reply-To: Date: Mon, 2 Feb 2015 19:41:38 +0100 Message-ID: <003d01d03f17$e1c16510$a5442f30$@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/Bqhff5wBvjlQ Content-Language: de-ch Subject: AW: [PHP-DEV] What do we need strict scalar type hints for? From: php@tutteli.ch ("Robert Stoll") Hi Dimitry, > -----Urspr=C3=BCngliche Nachricht----- > Von: Dmitry Stogov [mailto:dmitry@zend.com] > Gesendet: Montag, 2. Februar 2015 10:13 > An: PHP Internals; Andrea Faulds; Nikita Popov > Betreff: [PHP-DEV] What do we need strict scalar type hints for? >=20 > hi, >=20 > could you please write down few use cases, when strict scalar type = hints are really useful. >=20 > Thanks. Dmitry. I think strict types are beneficial in all those places where you would = put manual tests to ensure that the passed value is of a certain type = and only of this type - removing the hassle (ok, I did not add anything = to the discussion so far ^^). Right now, I mainly think of functions = which expect an int - especially in the domain of time and money. I = would expect an int and I would not want that a float can be passed = without warning and get silently converted to an int (loosing precision = in the domain of time or money can be crucial).=20 However, IMO it is not necessary to have a strict mode as presented by = Andrea -- I think it would be good enough if we use the same widening = rules as in Java, C# etc. and be strict otherwise. I am aware of that = with the support of BigInteger we would have a widening problem = (BigInteger to float) but could be solved by a BigDecimal as in Clojure. Ah... I now something I would definitely want to be strict. I guess a = typical bug, which is made by many beginners, is using the result of = strpos in an if statement without using the identity operator -- btw. = would the strict mode affect operators and control structures as well? = Would somehow be the logical consequence but I suppose the impact on = performance would be too big. Or wouldn't it? Back to the topic, if I expect a bool as parameter I would definitely = not want it to be automatically converted since this is a sink for bugs. = Hope that helps. Cheers, Robert