From 4d7d294120ff744d4fd674d2a177dc8063d72b98 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Wed, 31 Aug 2022 16:07:05 +0200 Subject: [PATCH 1/2] No longer allow block mode for declare(encoding) As discussed in #9446, this isn't properly supported, and it is doubtful if it ever can be useful, let alone if it could be properly supported. Therefore, we disallow the confusing block mode in the first place. --- Zend/zend_compile.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 03faf9c96e445..c56c9a68d7814 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6109,6 +6109,11 @@ static void zend_compile_declare(zend_ast *ast) /* {{{ */ zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration pragma must be " "the very first statement in the script"); } + + if (ast->child[1] != NULL) { + zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration pragma must not " + "use block mode"); + } } else if (zend_string_equals_literal_ci(name, "strict_types")) { zval value_zv; From bc2367d65290c484a47657e86083b0181b9f48bd Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Wed, 31 Aug 2022 16:30:47 +0200 Subject: [PATCH 2/2] Adjust tests --- ext/mbstring/tests/zend_multibyte-11.phpt | 2 +- ext/mbstring/tests/zend_multibyte-15.phpt | 5 ++--- ext/mbstring/tests/zend_multibyte-16.phpt | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ext/mbstring/tests/zend_multibyte-11.phpt b/ext/mbstring/tests/zend_multibyte-11.phpt index bec2c482d6594..5f9d1a82b4be8 100644 --- a/ext/mbstring/tests/zend_multibyte-11.phpt +++ b/ext/mbstring/tests/zend_multibyte-11.phpt @@ -12,4 +12,4 @@ declare(encoding="ISO-8859-15") { } ?> --EXPECTF-- -Fatal error: Encoding declaration pragma must be the very first statement in the script in %s on line %d +Fatal error: Encoding declaration pragma must not use block mode in %s on line %d diff --git a/ext/mbstring/tests/zend_multibyte-15.phpt b/ext/mbstring/tests/zend_multibyte-15.phpt index bcf4ebe59d8ed..030869e0c5679 100644 --- a/ext/mbstring/tests/zend_multibyte-15.phpt +++ b/ext/mbstring/tests/zend_multibyte-15.phpt @@ -13,6 +13,5 @@ declare(encoding="UTF-8") { echo "ok\n"; } ?> ---EXPECT-- -ok -ok +--EXPECTF-- +Fatal error: Encoding declaration pragma must not use block mode in %s on line %d diff --git a/ext/mbstring/tests/zend_multibyte-16.phpt b/ext/mbstring/tests/zend_multibyte-16.phpt index ed02f6895b18d..d560fdcaa9659 100644 --- a/ext/mbstring/tests/zend_multibyte-16.phpt +++ b/ext/mbstring/tests/zend_multibyte-16.phpt @@ -11,6 +11,5 @@ declare(encoding="ISO-8859-15") { } echo "ok\n"; ?> ---EXPECT-- -ok -ok +--EXPECTF-- +Fatal error: Encoding declaration pragma must not use block mode in %s on line %d