Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82134 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61246 invoked from network); 8 Feb 2015 11:30:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2015 11:30:33 -0000 Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; 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:40896] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/C5-24707-8D847D45 for ; Sun, 08 Feb 2015 06:30:33 -0500 Received: (qmail 14997 invoked from network); 8 Feb 2015 12:30:28 +0100 Received: from cm56-153-252.liwest.at (HELO RoLaptop) (86.56.153.252) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 8 Feb 2015 12:30:28 +0100 To: "'Rasmus Lerdorf'" , "'Andrea Faulds'" Cc: =?UTF-8?Q?'Pavel_Kou=C5=99il'?= , "'PHP Internals'" References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> <9E1C2427-0295-4F3E-BD29-04DA84321067@ajf.me> <54D6CC39.50708@lerdorf.com> <93AAEA55-1C03-46AD-88D0-6A2F5531FCA6@ajf.me> <54D6DD7E.5060602@lerdorf.com> In-Reply-To: <54D6DD7E.5060602@lerdorf.com> Date: Sun, 8 Feb 2015 12:30:25 +0100 Message-ID: <004e01d04392$a28d4d80$e7a7e880$@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: AQJMIZG9mXkdirFXmuP9r5ZK3xIuzQGDaawwAnrtyKcCuwHGEQIyYeJtAUNmku0BgxSC3wCUOjjZm4yVjjA= Content-Language: de-ch Subject: AW: [PHP-DEV] [VOTE] Scalar Type Hints From: php@tutteli.ch ("Robert Stoll") > -----Urspr=C3=BCngliche Nachricht----- > Von: Rasmus Lerdorf [mailto:rasmus@lerdorf.com] > Gesendet: Sonntag, 8. Februar 2015 04:53 > An: Andrea Faulds > Cc: Pavel Kou=C5=99il; PHP Internals > Betreff: Re: [PHP-DEV] [VOTE] Scalar Type Hints >=20 > On 02/07/2015 09:51 PM, Andrea Faulds wrote: > >> tan(1); > >> echo strstr("test", "est", 1); > > > > Banning int->float and float->int is both a pain point and sometimes = a life-saver. It=E2=80=99s annoying that tan(1) doesn=E2=80=99t work. > On the other hand, you discover if your ints floats would be silently = truncated (as I did with PictoSwap). > > > > I wouldn=E2=80=99t say that int->string not working is a problem, = though. Seeing something like strstr(=E2=80=9Ctest=E2=80=9D, = =E2=80=9Cest=E2=80=9D, 1); is rather > confusing. Looking at it, I=E2=80=99d think the third parameter is = some sort of number for you to want to pass an integer to it. If I > want a string, I=E2=80=99ll use one. >=20 > This isn't int->string. This is int->boolean. The 3rd arg to strstr() = is a boolean and passing 1 instead of true makes it blow up. > It is very very common for people to pass 0 or 1 in place of = true/false to all sorts of things in PHP. >=20 > > Yes, the RFC is somewhat inaccurate in that respect. It is per-file = in one sense (like encoding, but unlike ticks, it has no > effect on the including or included files). However, it technically = affects the remainder of the file, not the whole file. >=20 > Well, no, not the remainder of the file either since it can be = switched again. It only affects the part of the file between > declares if there is a second one. >=20 > -Rasmus >=20 I think that it is a perfect example why strict typing has its merits. = It is funny to see how confusing it seems to be that you passed 1 = instead true but anyway...=20 I already mentioned once that we could handle number literals as = different types depending on its context (like Haskell does it). For instance: sin(1) is perfectly fine as well, since 1 is an integer literal and can be used = as float literal as well. I would only allow int -> float but not int -> = bool (see confusion above). Cheers, Robert