Hi all, On 18 February 2015 at 09:14, Andrey Andreev <n...@devilix.net> wrote: > Hi, > > On Wed, Feb 18, 2015 at 9:00 AM, Zeev Suraski <z...@zend.com> wrote: >> I am wondering what the point is indeed with preventing "123" to 123. So >> far, all the concrete use cases people brought up had to do with "Apple" or >> "100 dogs", but nobody ever seems to be able to explain why converting "123" >> to 123 is likely to be a problem real world. Is it really just static >> analyzers? >> > > I too am curious about the potential issue with "123" to 123 > specifically, although it could be seen as a subset of another problem > that is solved with strict hints - numeric-character string > identifiers being erroneously treated as integers.
If I may interject briefly (doing it anyway!), there are so many concepts being munged together that there's bound to be confusion (on the part of idle readers like me). For this specific case, would I as someone who wants strict/strong typing really care whether “123” was coerced to an integer? No. Others are free to disagree. I actually don’t mind there being a certain amount of logical coercion between types where it makes sense. That’s not, per se, fully in accordance with strictest to the strict degree typing which was Nikita’s point. Coercion is itself a symptom of weak typing, so the more coercion one introduces, the weaker the typing. However, “123” is exceptional. It’s redefining an integer as “ an integer or a string comprised wholly of digits without leading zeroes, with an optional leading hyphen, and representing an integer up to PHP_INT_MAX”, i.e. an integer or a string with a real number that be made an integer without loss. No other string need apply. That’s not strict-strict typing (there’s coercion) but it’s probably strict enough to pass muster (it’s one single obvious coercion under limited circumstances). Then again, it’s an exception that requires a long sentence. It’s just not clear, to me, if this is the sole intended exception, or if that sentence needs to be expanded to a paragraph. A section? Are we going to need a chapter? I’m assuming octals-in-a-string are a no-go to be coerced whereas others might just see an integer with superfluous leading zeroes. In a future RFC revision, it might be nice to have a table of the specific coercion rules applicable to a weak/strong/single-unified option. Granted, final implementation details may be not 100% certain, but in this case any variation in implementation can have significance as to whether something is weak/strict/or lies somewhere else on the spectrum in between. So, I agree with Nikita that this is less than strict typing, but one single logical exception doesn’t instantly demote it to extreme weak typing if its sufficiently narrow in scope. We are compromising, no? It’s imperfect in other ways, but I’ll let others debate if those are significant or not. Paddy -- Pádraic Brady http://blog.astrumfutura.com http://www.survivethedeepend.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php