> -----Ursprüngliche Nachricht----- > Von: Rasmus Lerdorf [mailto:ras...@lerdorf.com] > Gesendet: Sonntag, 8. Februar 2015 04:53 > An: Andrea Faulds > Cc: Pavel Kouřil; PHP Internals > Betreff: Re: [PHP-DEV] [VOTE] Scalar Type Hints > > 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’s annoying that tan(1) doesn’t work. > On the other hand, you discover if your ints floats would be silently > truncated (as I did with PictoSwap). > > > > I wouldn’t say that int->string not working is a problem, though. Seeing > > something like strstr(“test”, “est”, 1); is rather > confusing. Looking at it, I’d 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’ll use one. > > 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. > > > 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. > > 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. > > -Rasmus >
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... 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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php