Hi, On Wed, Feb 18, 2015 at 9:00 AM, Zeev Suraski <z...@zend.com> wrote: >> -----Original Message----- >> From: Nikita Popov [mailto:nikita....@gmail.com] >> Sent: Wednesday, February 18, 2015 3:06 AM >> To: Rasmus Lerdorf >> Cc: Sara Golemon; PHP internals >> Subject: Re: [PHP-DEV] Scalar Type Hints v0.4 >> >> The inability to implicitly cast "123" to int is pretty much the KEY >> distinction >> between weak and strict scalar typehints (those pesky value-dependent type >> checks). If the strict typing mode doesn't offer this, what's the point at >> all? > > 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. That is especially bad when such identifiers are in fact generated as integers first so that they are incremental, but the program/database/business logic requires them to be fixed-length strings and/or in hexadecimal format. In such cases, even silently discarding leading zeros can prove to be problematic, while in the case of hexadecimal representations you'd need more than 10 data samples to notice the problem if you don't use a strict hint. Obviously, that would be solved with automated testing, but unfortunately even code with high test coverage % often lacks depth in its test cases. I believe reduced amount of necessary unit tests was already brought up as an advantage of strict type hints, so I'm just explaining one such use case in detail here. Cheers, Andrey. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php