Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81632 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14644 invoked from network); 2 Feb 2015 19:14:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 19:14:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.176 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.176 mail-vc0-f176.google.com Received: from [209.85.220.176] ([209.85.220.176:36043] helo=mail-vc0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E3/C0-34915-28CCFC45 for ; Mon, 02 Feb 2015 14:14:11 -0500 Received: by mail-vc0-f176.google.com with SMTP id kv7so15325763vcb.7 for ; Mon, 02 Feb 2015 11:14:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=55c/faJJvDys6wWmDwy8R09fGxHZ5XgY0XUN2wrwCS8=; b=mnH7XSdh3lPLUQm/m34OXo3tfUnWjLa/ObxBIhH1mM5yXBB/4LDMOrKXLPLGN2Gwi/ jLAJx0LBZO6d1Z2ZkWUqmZWT4lnOZJ5+snaPQRBSPZmUgHxzkvyDd/l41+6zcnE17if/ xUUZm1gpOGeb6icOCGIrdONWKJmOkzG+M4e3xt+YHBfna4Fm1lr1avjFIvvgFf2RmNkc rn8CVkUdBKTjxWetl8r4ik7oPeNdMflMcbewX7Eh8uR1kvEmlFKh+nk34Zgu4/C6YIG9 0X79VrIqSTBhHg7+e7ehkbPPK6B49ULjIcGQt81/4RstZ+DG6QN/e6m2nyzdBy9pJRdB j/EQ== X-Gm-Message-State: ALoCoQkXiTROoiyBGXASO5yUigAix9V4cfYlS7oozfVD3zLT3FcWWOzucQy5saL6E9VJGrPBPKih7pjHlaQolFvXIxPvMEOlJ9Z+9zPf4d2MhdZbaKvgy2erLAwsVc71iFIHMWRQNI7a5FuRQkOiChplZPSVLA6lKw== MIME-Version: 1.0 X-Received: by 10.221.18.136 with SMTP id qg8mr13387868vcb.27.1422904448342; Mon, 02 Feb 2015 11:14:08 -0800 (PST) Received: by 10.52.74.73 with HTTP; Mon, 2 Feb 2015 11:14:08 -0800 (PST) In-Reply-To: <003d01d03f17$e1c16510$a5442f30$@tutteli.ch> References: <003d01d03f17$e1c16510$a5442f30$@tutteli.ch> Date: Mon, 2 Feb 2015 23:14:08 +0400 Message-ID: To: Robert Stoll Cc: PHP Internals , Andrea Faulds , Nikita Popov Content-Type: multipart/alternative; boundary=001a113399e6317457050e1fc286 Subject: Re: [PHP-DEV] What do we need strict scalar type hints for? From: dmitry@zend.com (Dmitry Stogov) --001a113399e6317457050e1fc286 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Feb 2, 2015 at 9:41 PM, Robert Stoll wrote: > 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? > > > > hi, > > > > could you please write down few use cases, when strict scalar type hint= s > are really useful. > > > > 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 th= e > discussion so far ^^). Right now, I mainly think of functions which expec= t > an int - especially in the domain of time and money. I would expect an i= nt > 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). > 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 rul= es > 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 strp= os > in an if statement without using the identity operator -- btw. would the > strict mode affect operators and control structures as well? no. now we speak only about parameter and return value type hints. > Would somehow be the logical consequence but I suppose the impact on > performance would be too big. Or wouldn't it? > it wouldn't reduce performance. may be even increase, but it'll break every second app. > 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. > I'm not sure. If we would work on a type-safe language I would definitely agree, but PHP is a "loosely typed language" by definition. Thanks. Dmitry. > > Hope that helps. > > Cheers, > Robert > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a113399e6317457050e1fc286--