On Tue, Apr 17, 2012 at 1:44 PM, Gustavo Lopes <glo...@nebm.ist.utl.pt> wrote:
> On Tue, 17 Apr 2012 13:20:33 +0200, Nikita Popov <nikita....@googlemail.com>
> wrote:
>
>> The internal is_numeric_string [1] function is used to check whether a
>> string contains a number (and to extract that number).
>>
>> Currently is_numeric_string also accepts hexadecimal strings [2]
>> (apart from the normal decimal integers and doubles).
>>
>> [...]
>>
>> In my eyes accepting hex strings in is_numeric_string leads to a quite
>> big WTF effect and causes problems and as such should be dropped.
>>
>> I don't think this has much BC impact, so it should be possible to change
>> it.
>>
>
> I think definitely has a larger BC impact than you're portraying, I can see
> some people making comparisons against '0xA' instead of 0xA.
Yes, this definitely does have BC impact, but I don't think it is
particularly large.

The affected areas mainly would be:
 * String comparisons using ==
 * Strings passed to internal functions which accept the value through
an "l" zend_parse_parameters (functions doing manual type handling via
the Z_TYPE and convert_to_long do not accept hex already now)
 * The userland function is_numeric

The first two would mainly be a problem if somebody - as you already
mention - has written '0xA' == $foo style comparisons or did stuff
like round($number, '0xA'). Both cases - in my eyes - aren't
particularly probably as anyone who knows what a hex number is
probably also knows the difference between a string literal and a
number literal.

The last one is more problematic. It is explicitly documented as
accepting hexadecimal numbers. In my eyes it too should not accept
them, but I could imagine that people rely on this.

> Besides, this is part of the Zend API. It's already used in many extensions
> (though possibly some of these should be using a stricter function) and
> changing its behavior is a stable branch is not wise:
>
> http://lxr.php.net/opengrok/search?q=&project=PHP_TRUNK&defs=&refs=is_numeric_string
I've already looked at some of these and in most (all?) cases the
intended behavior seems to be to not allow hex (passing hex in those
situations actually creates some kind of broken behavior).

Nikita

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

Reply via email to