File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,4 @@ function foo() {
1313echo "Bye "
1414?>
1515--EXPECTF--
16- Warning: declare(encoding=...) ignored because Zend multibyte feature is turned off by settings in %s on line %d
17-
1816Fatal error: Encoding declaration pragma must be the very first statement in the script in %s on line %d
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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 */
71917199bool 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 }
You can’t perform that action at this time.
0 commit comments