Hi!

> I'm currently working on https://github.com/php/php-src/pull/186,
> which fixes a problem with PostgreSQL when passing a float to
> pg_query_params() with a locale setting that uses "," as a decimal
> point. pg_query_params() uses convert_to_string(), which uses %G as a
> format string for floats, which is locale sensitive (and therefore
> converts e.g. in hr_HR or de_DE to "1,1"). The proposed fix is to
> introduce a new API convert_to_cstring() in the Zend Engine to allow
> converting types to C-locale strings.

I'm not sure adding new engine API for this specific use case is a good
idea. If it's just for query parameters with specific type, can't it
just use printf with needed settings there? PHP generic settings may be
not good there in any case, as it is probably also influenced by
precision, which is not a good idea for database - if I set precision to
1, do I really want all my DB data be rounded to 1 digit?

> This kind of fix is very likely needed in other places, where floats
> are converted using convert_to_string(). I haven’t found time to try

If you specifically set locale to hr_HR - i.e. say "PHP, please know
that my floats use , as a separator" - why PHP should not do exactly
what you asked it to do?

> What’s your take on the proposed fix of introducing
> convert_to_cstring() and using it where external protocols require a
> locale insensitive float conversion?

I'm afraid figuring out in each case which conversion to use will create
a mess, especially that the requirements is likely to be contradictory
in different cases. I'd rather recommend avoiding using locales for that
and instead use ICU number formatting functions when you need to format
numbers. Locale kind of implies all your data behave the same, and it's
obviously not the case here, and rarely the case anymore in systems
involving so many components.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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

Reply via email to