Skip to content

Commit 5d2142e

Browse files
committed
Remove deprecated iconv INI settings
Also deprecated relevant function to set/get iconv encodings.
1 parent 19de727 commit 5d2142e

10 files changed

+135
-269
lines changed

ext/iconv/iconv.c

Lines changed: 26 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "ext/standard/info.h"
2626
#include "main/php_output.h"
2727
#include "SAPI.h"
28-
#include "php_ini.h"
2928

3029
#include <stdlib.h>
3130
#include <errno.h>
@@ -56,9 +55,6 @@
5655
#define _php_iconv_memequal(a, b, c) \
5756
(memcmp(a, b, c) == 0)
5857

59-
ZEND_DECLARE_MODULE_GLOBALS(iconv)
60-
static PHP_GINIT_FUNCTION(iconv);
61-
6258
/* {{{ iconv_module_entry */
6359
zend_module_entry iconv_module_entry = {
6460
STANDARD_MODULE_HEADER,
@@ -70,11 +66,7 @@ zend_module_entry iconv_module_entry = {
7066
NULL,
7167
PHP_MINFO(miconv),
7268
PHP_ICONV_VERSION,
73-
PHP_MODULE_GLOBALS(iconv),
74-
PHP_GINIT(iconv),
75-
NULL,
76-
NULL,
77-
STANDARD_MODULE_PROPERTIES_EX
69+
STANDARD_MODULE_PROPERTIES,
7870
};
7971
/* }}} */
8072

@@ -85,18 +77,6 @@ ZEND_TSRMLS_CACHE_DEFINE()
8577
ZEND_GET_MODULE(iconv)
8678
#endif
8779

88-
/* {{{ PHP_GINIT_FUNCTION */
89-
static PHP_GINIT_FUNCTION(iconv)
90-
{
91-
#if defined(COMPILE_DL_ICONV) && defined(ZTS)
92-
ZEND_TSRMLS_CACHE_UPDATE();
93-
#endif
94-
iconv_globals->input_encoding = NULL;
95-
iconv_globals->output_encoding = NULL;
96-
iconv_globals->internal_encoding = NULL;
97-
}
98-
/* }}} */
99-
10080
#if defined(HAVE_LIBICONV) && defined(ICONV_ALIASED_LIBICONV)
10181
#define iconv libiconv
10282
#endif
@@ -141,61 +121,11 @@ static const char _generic_superset_name[] = ICONV_UCS4_ENCODING;
141121
#define GENERIC_SUPERSET_NBYTES 4
142122
/* }}} */
143123

144-
145-
static PHP_INI_MH(OnUpdateInputEncoding)
146-
{
147-
if (ZSTR_LEN(new_value) >= ICONV_CSNMAXLEN) {
148-
return FAILURE;
149-
}
150-
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
151-
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.input_encoding is deprecated");
152-
}
153-
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
154-
return SUCCESS;
155-
}
156-
157-
158-
static PHP_INI_MH(OnUpdateOutputEncoding)
159-
{
160-
if (ZSTR_LEN(new_value) >= ICONV_CSNMAXLEN) {
161-
return FAILURE;
162-
}
163-
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
164-
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.output_encoding is deprecated");
165-
}
166-
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
167-
return SUCCESS;
168-
}
169-
170-
171-
static PHP_INI_MH(OnUpdateInternalEncoding)
172-
{
173-
if (ZSTR_LEN(new_value) >= ICONV_CSNMAXLEN) {
174-
return FAILURE;
175-
}
176-
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
177-
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.internal_encoding is deprecated");
178-
}
179-
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
180-
return SUCCESS;
181-
}
182-
183-
184-
/* {{{ PHP_INI */
185-
PHP_INI_BEGIN()
186-
STD_PHP_INI_ENTRY("iconv.input_encoding", "", PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, zend_iconv_globals, iconv_globals)
187-
STD_PHP_INI_ENTRY("iconv.output_encoding", "", PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, zend_iconv_globals, iconv_globals)
188-
STD_PHP_INI_ENTRY("iconv.internal_encoding", "", PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, zend_iconv_globals, iconv_globals)
189-
PHP_INI_END()
190-
/* }}} */
191-
192124
/* {{{ PHP_MINIT_FUNCTION */
193125
PHP_MINIT_FUNCTION(miconv)
194126
{
195127
char *version = "unknown";
196128

197-
REGISTER_INI_ENTRIES();
198-
199129
#ifdef HAVE_LIBICONV
200130
{
201131
static char buf[16];
@@ -234,7 +164,6 @@ PHP_MINIT_FUNCTION(miconv)
234164
PHP_MSHUTDOWN_FUNCTION(miconv)
235165
{
236166
php_iconv_stream_filter_unregister_factory();
237-
UNREGISTER_INI_ENTRIES();
238167
return SUCCESS;
239168
}
240169
/* }}} */
@@ -252,33 +181,9 @@ PHP_MINFO_FUNCTION(miconv)
252181
php_info_print_table_row(2, "iconv implementation", Z_STRVAL_P(iconv_impl));
253182
php_info_print_table_row(2, "iconv library version", Z_STRVAL_P(iconv_ver));
254183
php_info_print_table_end();
255-
256-
DISPLAY_INI_ENTRIES();
257184
}
258185
/* }}} */
259186

260-
static const char *get_internal_encoding(void) {
261-
if (ICONVG(internal_encoding) && ICONVG(internal_encoding)[0]) {
262-
return ICONVG(internal_encoding);
263-
}
264-
return php_get_internal_encoding();
265-
}
266-
267-
static const char *get_input_encoding(void) {
268-
if (ICONVG(input_encoding) && ICONVG(input_encoding)[0]) {
269-
return ICONVG(input_encoding);
270-
}
271-
return php_get_input_encoding();
272-
}
273-
274-
static const char *get_output_encoding(void) {
275-
if (ICONVG(output_encoding) && ICONVG(output_encoding)[0]) {
276-
return ICONVG(output_encoding);
277-
}
278-
return php_get_output_encoding();
279-
}
280-
281-
282187
static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len)
283188
{
284189
if (php_output_get_level()) {
@@ -319,12 +224,16 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c
319224

320225
if (mimetype != NULL && !(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) {
321226
size_t len;
322-
char *p = strstr(get_output_encoding(), "//");
227+
char *p = strstr(php_get_output_encoding(), "//");
323228

324229
if (p) {
325-
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, (int) (p - get_output_encoding()), get_output_encoding());
230+
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s",
231+
mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype,
232+
(int) (p - php_get_output_encoding()), php_get_output_encoding());
326233
} else {
327-
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, get_output_encoding());
234+
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s",
235+
mimetype_len ? mimetype_len : (int) strlen(mimetype),
236+
mimetype, php_get_output_encoding());
328237
}
329238
if (content_type && SUCCESS == sapi_add_header(content_type, len, 0)) {
330239
SG(sapi_headers).send_default_content_type = 0;
@@ -336,7 +245,9 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c
336245
if (output_context->in.used) {
337246
zend_string *out;
338247
output_context->out.free = 1;
339-
_php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &out, get_output_encoding(), get_internal_encoding()), get_output_encoding(), get_internal_encoding());
248+
_php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &out,
249+
php_get_output_encoding(), php_get_internal_encoding()), php_get_output_encoding(),
250+
php_get_internal_encoding());
340251
if (out) {
341252
output_context->out.data = estrndup(ZSTR_VAL(out), ZSTR_LEN(out));
342253
output_context->out.used = ZSTR_LEN(out);
@@ -1836,7 +1747,7 @@ PHP_FUNCTION(iconv_strlen)
18361747
}
18371748

18381749
if (charset == NULL) {
1839-
charset = get_internal_encoding();
1750+
charset = php_get_internal_encoding();
18401751
} else if (charset_len >= ICONV_CSNMAXLEN) {
18411752
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
18421753
RETURN_FALSE;
@@ -1872,7 +1783,7 @@ PHP_FUNCTION(iconv_substr)
18721783
}
18731784

18741785
if (charset == NULL) {
1875-
charset = get_internal_encoding();
1786+
charset = php_get_internal_encoding();
18761787
} else if (charset_len >= ICONV_CSNMAXLEN) {
18771788
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
18781789
RETURN_FALSE;
@@ -1913,7 +1824,7 @@ PHP_FUNCTION(iconv_strpos)
19131824
}
19141825

19151826
if (charset == NULL) {
1916-
charset = get_internal_encoding();
1827+
charset = php_get_internal_encoding();
19171828
} else if (charset_len >= ICONV_CSNMAXLEN) {
19181829
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
19191830
RETURN_FALSE;
@@ -1972,7 +1883,7 @@ PHP_FUNCTION(iconv_strrpos)
19721883
}
19731884

19741885
if (charset == NULL) {
1975-
charset = get_internal_encoding();
1886+
charset = php_get_internal_encoding();
19761887
} else if (charset_len >= ICONV_CSNMAXLEN) {
19771888
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
19781889
RETURN_FALSE;
@@ -2000,7 +1911,7 @@ PHP_FUNCTION(iconv_mime_encode)
20001911
smart_str retval = {0};
20011912
php_iconv_err_t err;
20021913

2003-
const char *in_charset = get_internal_encoding();
1914+
const char *in_charset = php_get_internal_encoding();
20041915
const char *out_charset = in_charset;
20051916
zend_long line_len = 76;
20061917
const char *lfchars = "\r\n";
@@ -2111,7 +2022,7 @@ PHP_FUNCTION(iconv_mime_decode)
21112022
}
21122023

21132024
if (charset == NULL) {
2114-
charset = get_internal_encoding();
2025+
charset = php_get_internal_encoding();
21152026
} else if (charset_len >= ICONV_CSNMAXLEN) {
21162027
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
21172028
RETURN_FALSE;
@@ -2152,7 +2063,7 @@ PHP_FUNCTION(iconv_mime_decode_headers)
21522063
}
21532064

21542065
if (charset == NULL) {
2155-
charset = get_internal_encoding();
2066+
charset = php_get_internal_encoding();
21562067
} else if (charset_len >= ICONV_CSNMAXLEN) {
21572068
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
21582069
RETURN_FALSE;
@@ -2269,8 +2180,7 @@ PHP_FUNCTION(iconv_set_encoding)
22692180
{
22702181
char *type;
22712182
zend_string *charset;
2272-
size_t type_len, retval;
2273-
zend_string *name;
2183+
size_t type_len;
22742184

22752185
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sS", &type, &type_len, &charset) == FAILURE) {
22762186
RETURN_THROWS();
@@ -2281,24 +2191,7 @@ PHP_FUNCTION(iconv_set_encoding)
22812191
RETURN_FALSE;
22822192
}
22832193

2284-
if(!strcasecmp("input_encoding", type)) {
2285-
name = zend_string_init("iconv.input_encoding", sizeof("iconv.input_encoding") - 1, 0);
2286-
} else if(!strcasecmp("output_encoding", type)) {
2287-
name = zend_string_init("iconv.output_encoding", sizeof("iconv.output_encoding") - 1, 0);
2288-
} else if(!strcasecmp("internal_encoding", type)) {
2289-
name = zend_string_init("iconv.internal_encoding", sizeof("iconv.internal_encoding") - 1, 0);
2290-
} else {
2291-
RETURN_FALSE;
2292-
}
2293-
2294-
retval = zend_alter_ini_entry(name, charset, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
2295-
zend_string_release_ex(name, 0);
2296-
2297-
if (retval == SUCCESS) {
2298-
RETURN_TRUE;
2299-
} else {
2300-
RETURN_FALSE;
2301-
}
2194+
RETURN_FALSE;
23022195
}
23032196
/* }}} */
23042197

@@ -2314,15 +2207,15 @@ PHP_FUNCTION(iconv_get_encoding)
23142207

23152208
if (!strcasecmp("all", type)) {
23162209
array_init(return_value);
2317-
add_assoc_string(return_value, "input_encoding", get_input_encoding());
2318-
add_assoc_string(return_value, "output_encoding", get_output_encoding());
2319-
add_assoc_string(return_value, "internal_encoding", get_internal_encoding());
2210+
add_assoc_string(return_value, "input_encoding", php_get_input_encoding());
2211+
add_assoc_string(return_value, "output_encoding", php_get_output_encoding());
2212+
add_assoc_string(return_value, "internal_encoding", php_get_internal_encoding());
23202213
} else if (!strcasecmp("input_encoding", type)) {
2321-
RETVAL_STRING(get_input_encoding());
2214+
RETVAL_STRING(php_get_input_encoding());
23222215
} else if (!strcasecmp("output_encoding", type)) {
2323-
RETVAL_STRING(get_output_encoding());
2216+
RETVAL_STRING(php_get_output_encoding());
23242217
} else if (!strcasecmp("internal_encoding", type)) {
2325-
RETVAL_STRING(get_internal_encoding());
2218+
RETVAL_STRING(php_get_internal_encoding());
23262219
} else {
23272220
RETURN_FALSE;
23282221
}

ext/iconv/iconv.stub.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function iconv_mime_decode_headers(string $headers, int $mode = 0, ?string $char
1818

1919
function iconv(string $in_charset, string $out_charset, string $str): string|false {}
2020

21+
/** @deprecated */
2122
function iconv_set_encoding(string $type, string $charset): bool {}
2223

23-
function iconv_get_encoding(string $type = "all"): array|string|false {}
24+
/** @deprecated */
25+
function iconv_get_encoding(string $type = 'all'): array|string|false {}

ext/iconv/iconv_arginfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 4e26168b04450adf510a4e638184c46757679ac1 */
2+
* Stub hash: c299905ab2225a1d5d4f3dff5dbab019ccbb18b4 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_strlen, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
@@ -56,7 +56,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_iconv_set_encoding, 0, 2, _IS_BO
5656
ZEND_END_ARG_INFO()
5757

5858
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_get_encoding, 0, 0, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_FALSE)
59-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 0, "\"all\"")
59+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 0, "\'all\'")
6060
ZEND_END_ARG_INFO()
6161

6262

@@ -81,7 +81,7 @@ static const zend_function_entry ext_functions[] = {
8181
ZEND_FE(iconv_mime_decode, arginfo_iconv_mime_decode)
8282
ZEND_FE(iconv_mime_decode_headers, arginfo_iconv_mime_decode_headers)
8383
ZEND_FE(iconv, arginfo_iconv)
84-
ZEND_FE(iconv_set_encoding, arginfo_iconv_set_encoding)
85-
ZEND_FE(iconv_get_encoding, arginfo_iconv_get_encoding)
84+
ZEND_DEP_FE(iconv_set_encoding, arginfo_iconv_set_encoding)
85+
ZEND_DEP_FE(iconv_get_encoding, arginfo_iconv_get_encoding)
8686
ZEND_FE_END
8787
};

ext/iconv/php_iconv.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,6 @@ PHP_FUNCTION(iconv_mime_encode);
6565
PHP_FUNCTION(iconv_mime_decode);
6666
PHP_FUNCTION(iconv_mime_decode_headers);
6767

68-
ZEND_BEGIN_MODULE_GLOBALS(iconv)
69-
char *input_encoding;
70-
char *internal_encoding;
71-
char *output_encoding;
72-
ZEND_END_MODULE_GLOBALS(iconv)
73-
74-
#define ICONVG(v) ZEND_MODULE_GLOBALS_ACCESSOR(iconv, v)
75-
76-
#if defined(ZTS) && defined(COMPILE_DL_ICONV)
77-
ZEND_TSRMLS_CACHE_EXTERN()
78-
#endif
79-
8068
#ifdef HAVE_IBM_ICONV
8169
# define ICONV_ASCII_ENCODING "IBM-850"
8270
# define ICONV_UCS4_ENCODING "UCS-4"

0 commit comments

Comments
 (0)