Hi, On Wed, Feb 18, 2015 at 11:54 AM, Lester Caine <les...@lsces.co.uk> wrote: > On 18/02/15 09:14, Andrey Andreev wrote: >> 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. > > Octal is something that can often be miss converted since it IS the same > as an integer with only a '0' in front in PHP. But that is not something > that can be fixed with the current proposals? Again we have to ensure > that the pre-processing takes care of the problem and how would static > analysis even know there was a problem? A type hint following the SQL > standards would be more helpful than the javascript approach of giving > an error in strict mode. >
I'm not talking about octal, and nobody's talking about SQL here. Consider the following signature: function foo(int $bar) {} In the case of a *string* representation of a hexadecimal number, the following would error only on the last iteration with a weak hint, and on the very first if it was a strict hint: for ($i = 0; $i < 11; $i++) { foo(base_convert($i, 10, 16)); } And when I said leading zeros, I was talking about fixed-length string identifiers such as '001', '002', etc. where you may *unintentionally* pass such a value to a function that deals with ... quantities, for example. A strict hint in that case would immediately catch this logical error while a weak hint would silently ignore the leading zeros and will happily treat the value as an integer. Again, the precondition here is that it's not an integer value that happens to be stored as a string, but a non-integer value that just looks like an integer. Cheers, Andrey. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php