Hi internals!

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).

This can cause some quite odd behavior at times. E.g. string
comparisons also use is_numeric_string, resulting in the behavior:

var_dump('123' == '0x7b'); // true

In all other parts of the engine hexadecimal strings are not recognized [3]:

var_dump((int) '0x7b'); // int(0)

This also causes minor problems in other parts of the engine where
is_numeric_string is used. E.g.

$string = 'abc';
var_dump($string['0xabc']); // string("a")
// 0xabc is first accepted as a number by is_numeric_string, but then
cast to 0 by convert_to_long

But:

$string = 'abc';
var_dump($string['0abc']);
// outputs (as expected):
Notice: A non well formed numeric value encountered in /code/8KXrYZ on line 9
NULL

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.

Nikita

 [1]: http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.h#is_numeric_string
 [2]: http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.h#131
 [3]: 
http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion

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

Reply via email to