diff options
Diffstat (limited to 'ext/standard/string.c')
-rw-r--r-- | ext/standard/string.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c index c57885fff1..483e8b4f1d 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -4343,27 +4343,31 @@ PHP_FUNCTION(setlocale) if (retval) { if (loc) { /* Remember if locale was changed */ - size_t len; + size_t len = strlen(retval); - if (BG(locale_string)) { - zend_string_release(BG(locale_string)); - } - len = strlen(retval); - if (len == loc->len && !memcmp(loc->val, retval, len)) { - BG(locale_string) = zend_string_copy(loc); - } else { - BG(locale_string) = zend_string_init(retval, len, 0); + BG(locale_changed) = 1; + if (cat == LC_CTYPE || cat == LC_ALL) { + if (BG(locale_string)) { + zend_string_release(BG(locale_string)); + } + if (len == loc->len && !memcmp(loc->val, retval, len)) { + BG(locale_string) = zend_string_copy(loc); + RETURN_STR(BG(locale_string)); + } else { + BG(locale_string) = zend_string_init(retval, len, 0); + zend_string_release(loc); + RETURN_STR(BG(locale_string)); + } + } else if (len == loc->len && !memcmp(loc->val, retval, len)) { + RETURN_STR(loc); } - zend_string_release(loc); } - if (BG(locale_string)) { - RETURN_STR(zend_string_copy(BG(locale_string))); - } else { - RETURN_EMPTY_STRING(); - } + RETURN_STRING(retval); + } + if (loc) { + zend_string_release(loc); } - zend_string_release(loc); if (Z_TYPE(args[0]) == IS_ARRAY) { if (zend_hash_move_forward_ex(Z_ARRVAL(args[0]), &pos) == FAILURE) break; |