> De : Andrey Andreev [mailto:n...@devilix.net]
>
> 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));
>     }

You're right. An hexa string with no leading '0x' and containing decimal digits 
only cannot be recognized as hexa. But I keep thinking that, balancing pros and 
cons, it's not enough to justify strict mode. Maybe I'm wrong and additional 
use cases will make me change my mind, but I consider hexa with no prefix as an 
edge-case.

I don't say that's the right solution but the problem can be solved at the 
base_convert() level. If we support '0x' strings as hexadecimal numbers, it can 
generate the '0x' prefix, which removes ambiguity for PHP and any other 
software that would have to interpret the string. Unfortunately, it would 
probably have to be explicitly required through an option because of BC. No 
perfect solution here.

Another argument some may consider weak : I'm also afraid that, in your 
example, the user seeing an error raised by strict mode could change its code 
to 'foo((int)base_convert', definitely hiding the real bug, even for 11 and up. 
So, Rasmus is right when he says strict mode can sometimes and indirectly be 
counter-productive. Debugging shouldn't be considered as error suppression 
only, but it is the case more than often.

Regards

François


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to