Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83485 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43772 invoked from network); 22 Feb 2015 20:42:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Feb 2015 20:42:25 -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:50651] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7D/04-18531-E2F3AE45 for ; Sun, 22 Feb 2015 15:42:23 -0500 Received: (qmail 15830 invoked from network); 22 Feb 2015 21:42:18 +0100 Received: from cm56-153-252.liwest.at (HELO RoLaptop) (86.56.153.252) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 22 Feb 2015 21:42:18 +0100 To: =?utf-8?Q?'Pavel_Kou=C5=99il'?= Cc: "'Zeev Suraski'" , "'PHP internals'" References: <7ef509ef10bb345c792f9d259c7a3fbb@mail.gmail.com> <002101d04ea0$d92ea0f0$8b8be2d0$@tutteli.ch> <000601d04ecd$95545aa0$bffd0fe0$@tutteli.ch> In-Reply-To: Date: Sun, 22 Feb 2015 21:42:17 +0100 Message-ID: <000d01d04ee0$0d03fb70$270bf250$@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: AQKcPg+jpyYspJS11b5G1A7RBHpKTgIhFZZKAamJpWwBSbXevgLCo6mHmyZyHVA= Content-Language: de-ch Subject: AW: [PHP-DEV] Coercive Scalar Type Hints RFC From: php@tutteli.ch ("Robert Stoll") > -----Urspr=C3=BCngliche Nachricht----- > Von: Pavel Kou=C5=99il [mailto:pajousek@gmail.com] > Gesendet: Sonntag, 22. Februar 2015 20:02 > An: Robert Stoll > Cc: Zeev Suraski; PHP internals > Betreff: Re: [PHP-DEV] Coercive Scalar Type Hints RFC >=20 > On Sun, Feb 22, 2015 at 7:30 PM, Robert Stoll wrote: > > Hi Pavel, > > > > Yes, I am suggesting to make conversions behave the same regardless = if it is implicit or explicit. The only difference > between the two should be that one is stated explicitly by the user = where the other is applied implicitly. Other > programming languages behave like this and are more predictable for = users as well as developers because one does not > need to learn two sets of conversion rules. > > >=20 > Actually this is not true. Other languages have differences between = explicit conversions (aka casting) and implicit > conversions as well. > C# is the language I use the most after PHP, so I'll bring that one up = (see https://msdn.microsoft.com/en- > us/library/ms173105.aspx), but I believe other languages (probably = Java?) act the same way. >=20 > Regards > Pavel Kouril >=20 Hm... I reconsidered my statements and that is a good thing :) I am not sure if I got your view point. I will try to elaborate more on = mine and explain how I interpret your statement. Probably it is a philosophical question how to look at it. IMO the only = difference in C# (as well as in Java) lies in the way the conversions = are applied. Implicit conversions are applied automatically by the = compiler where explicit conversions are applied by the user. The = difference lies in the fact that C# is statically typed and implicit = conversions are only applied when it is certainly safe to apply one. = However, Implicit conversions in C# behave the same as explicit = conversion since implicit conversion which fail simply do not exist = (there is no implicit conversion from double to int for instance). That = is the way I look at it. You probably look at it from another point of = view and would claim an implicit conversion from double to int in C# = exists but just fails all the time =3D> ergo implicit and explicit are = different (that is my interpretation of your statement above). In this = sense I would agree. But even when you think in this terms then you have = to admit, they are fundamentally different in the way that implicit = conversion which are different than explicit conversion always fail, in = all cases - pretty much as if they do not exist. There are no cases, = neither in C# nor in Java which I am aware of, where an implicit cast = succeeds in certain cases but not in all and an explicit conversion = succeeds in at least more cases than the implicit conversion. Hence, = something like "a" should also not work in an explicit conversion in PHP = IMO if it is not supported by the implicit conversion (otherwise strict = mode is useless btw.) Try out the following C# code: dynamic d1 =3D 1.0; int d =3D d1; You will get the error "Cannot implicitly convert type `double` to = `int`" at runtime. We see a fundamental difference between C# and PHP here. PHP is = dynamically typed an relies on values rather than types (in contrast to = C#). Therefore, the above code emits a runtime error even though the = data could be converted to int without precision loss. This shall be different in PHP according to this RFC and I think that is = perfectly fine. Yet, even more important it seems to me that = implicit/explicit conversions behave the same way.=20 At first it might seem strange to have just one conversion rule set in = PHP since PHP is not known to be a language which shines due to its = consistency...=20 OK, I am serious again. If you think about it from the following point = of view: A user writes an explicit conversion in order to state = explicitly that some value will be converted (this is something which = will be necessary in a strict mode). Why should this explicit conversion = be different from the implicit one? There should not be any difference = between explicit knowledge and implicit one. That is my opinion. If you = really do not care about data loss and just want to squeeze a = float/string into an int no matter what the value really is then you can = use the @ in conjunction with ?? and provide the desired default value = to fall back on if the conversion fails. If conversions like "a" to int = really matters that much to the users of PHP then we could keep the = oldSchoolIntConversion function (as propose in my first email) even in = PHP 10 (I would probably get rid of them at some point). Cheers,=20 Robert