Skip to content

Commit bbc6aac

Browse files
committed
initial fix
1 parent c45b2be commit bbc6aac

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

Zend/tests/declare/bug69092.2.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ function foo() {
1313
echo "Bye"
1414
?>
1515
--EXPECTF--
16-
Warning: declare(encoding=...) ignored because Zend multibyte feature is turned off by settings in %s on line %d
17-
1816
Fatal error: Encoding declaration pragma must be the very first statement in the script in %s on line %d

Zend/tests/declare/gh21538.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-21538 (declare(encoding=...) warning with zend.multibyte=0 should be skipped for UTF-8 and ASCII)
3+
--INI--
4+
zend.multibyte=0
5+
--FILE--
6+
<?php
7+
eval("declare(encoding='UTF-8');");
8+
eval("declare(encoding='ASCII');");
9+
eval("declare(encoding='ISO-8859-1');");
10+
echo "Done\n";
11+
?>
12+
--EXPECTF--
13+
Warning: declare(encoding=...) ignored because Zend multibyte feature is turned off by settings in %s on line %d
14+
Done

Zend/zend_compile.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7187,6 +7187,14 @@ static void zend_compile_try(const zend_ast *ast) /* {{{ */
71877187
}
71887188
/* }}} */
71897189

7190+
static bool zend_encoding_declaration_can_be_ignored_without_warning(const zend_string *encoding_name)
7191+
{
7192+
return zend_string_equals_literal_ci(encoding_name, "UTF-8")
7193+
|| zend_string_equals_literal_ci(encoding_name, "UTF8")
7194+
|| zend_string_equals_literal_ci(encoding_name, "ASCII")
7195+
|| zend_string_equals_literal_ci(encoding_name, "US-ASCII");
7196+
}
7197+
71907198
/* Encoding declarations must already be handled during parsing */
71917199
bool zend_handle_encoding_declaration(zend_ast *ast) /* {{{ */
71927200
{
@@ -7229,8 +7237,14 @@ bool zend_handle_encoding_declaration(zend_ast *ast) /* {{{ */
72297237

72307238
zend_string_release_ex(encoding_name, 0);
72317239
} else {
7232-
zend_error(E_COMPILE_WARNING, "declare(encoding=...) ignored because "
7233-
"Zend multibyte feature is turned off by settings");
7240+
zend_string *encoding_name = zval_get_string(zend_ast_get_zval(value_ast));
7241+
7242+
if (!zend_encoding_declaration_can_be_ignored_without_warning(encoding_name)) {
7243+
zend_error(E_COMPILE_WARNING, "declare(encoding=...) ignored because "
7244+
"Zend multibyte feature is turned off by settings");
7245+
}
7246+
7247+
zend_string_release_ex(encoding_name, 0);
72347248
}
72357249
}
72367250
}

0 commit comments

Comments
 (0)