Commit 0174b957ff7 for php

commit 0174b957ff71abc9af2b7da36edf1d5b8a80ab63
Author: Christoph M. Becker <cmbecker69@gmx.de>
Date:   Wed Nov 4 16:21:52 2026 +0100

    Zend: No longer allow block mode for declare(encoding) (#9455)

    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.

    Closes GH-9446

    Co-authored-by: Gina Peter Banyard <girgias@php.net>

diff --git a/Zend/tests/declare/bug69092.2.phpt b/Zend/tests/declare/bug69092.2.phpt
index f774820056d..e9211bdc815 100644
--- a/Zend/tests/declare/bug69092.2.phpt
+++ b/Zend/tests/declare/bug69092.2.phpt
@@ -15,4 +15,4 @@ function foo() {
 --EXPECTF--
 Warning: declare(encoding=...) ignored because Zend multibyte feature is turned off by settings in %s on line %d

-Fatal error: Encoding declaration pragma must be the very first statement in the script in %s on line %d
+Fatal error: Encoding declaration must be the very first statement in the script in %s on line %d
diff --git a/Zend/tests/declare/bug69092.phpt b/Zend/tests/declare/bug69092.phpt
index bf2655b1a1b..4ea7c62d7e2 100644
--- a/Zend/tests/declare/bug69092.phpt
+++ b/Zend/tests/declare/bug69092.phpt
@@ -15,4 +15,4 @@ function foo() {
 echo "Bye"
 ?>
 --EXPECTF--
-Fatal error: Encoding declaration pragma must be the very first statement in the script in %s on line %d
+Fatal error: Encoding declaration must be the very first statement in the script in %s on line %d
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 834393686b3..5ecee520cd1 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -7708,9 +7708,14 @@ static void zend_compile_declare(const zend_ast *ast) /* {{{ */
 		} else if (zend_string_equals_literal_ci(name, "encoding")) {

 			if (FAILURE == zend_is_first_statement(ast, /* allow_nop */ false)) {
-				zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration pragma must be "
+				zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration must be "
 					"the very first statement in the script");
 			}
+
+			if (ast->child[1] != NULL) {
+				zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration must not "
+					"use block mode");
+			}
 		} else if (zend_string_equals_literal_ci(name, "strict_types")) {
 			zval value_zv;

diff --git a/ext/mbstring/tests/zend_multibyte-12.phpt b/ext/mbstring/tests/zend_multibyte-12.phpt
index 934bf56cd62..9357e1bb7cb 100644
--- a/ext/mbstring/tests/zend_multibyte-12.phpt
+++ b/ext/mbstring/tests/zend_multibyte-12.phpt
@@ -11,4 +11,4 @@
 declare(encoding="ISO-8859-1");
 ?>
 --EXPECTF--
-Fatal error: Encoding declaration pragma must be the very first statement in the script in %s on line 4
+Fatal error: Encoding declaration must be the very first statement in the script in %s on line 4
diff --git a/ext/mbstring/tests/zend_multibyte-15.phpt b/ext/mbstring/tests/zend_multibyte-15.phpt
deleted file mode 100644
index bcf4ebe59d8..00000000000
--- a/ext/mbstring/tests/zend_multibyte-15.phpt
+++ /dev/null
@@ -1,18 +0,0 @@
---TEST--
-zend multibyte (15)
---EXTENSIONS--
-mbstring
---INI--
-zend.multibyte=1
---FILE--
-<?php
-declare(encoding="ISO-8859-15") {
-    echo "ok\n";
-}
-declare(encoding="UTF-8") {
-    echo "ok\n";
-}
-?>
---EXPECT--
-ok
-ok
diff --git a/ext/mbstring/tests/zend_multibyte-16.phpt b/ext/mbstring/tests/zend_multibyte-16.phpt
deleted file mode 100644
index ed02f6895b1..00000000000
--- a/ext/mbstring/tests/zend_multibyte-16.phpt
+++ /dev/null
@@ -1,16 +0,0 @@
---TEST--
-zend multibyte (16)
---EXTENSIONS--
-mbstring
---INI--
-zend.multibyte=1
---FILE--
-<?php
-declare(encoding="ISO-8859-15") {
-    echo "ok\n";
-}
-echo "ok\n";
-?>
---EXPECT--
-ok
-ok
diff --git a/ext/mbstring/tests/zend_multibyte_alternative_block_mode_error.phpt b/ext/mbstring/tests/zend_multibyte_alternative_block_mode_error.phpt
new file mode 100644
index 00000000000..4d31e08200c
--- /dev/null
+++ b/ext/mbstring/tests/zend_multibyte_alternative_block_mode_error.phpt
@@ -0,0 +1,14 @@
+--TEST--
+zend multibyte encoding declare cannot use block mode
+--EXTENSIONS--
+mbstring
+--INI--
+zend.multibyte=1
+--FILE--
+<?php
+declare(encoding="ISO-8859-15"):
+    echo "ok\n";
+enddeclare;
+?>
+--EXPECTF--
+Fatal error: Encoding declaration must not use block mode in %s on line %d
diff --git a/ext/mbstring/tests/zend_multibyte-11.phpt b/ext/mbstring/tests/zend_multibyte_block_mode_error.phpt
similarity index 57%
rename from ext/mbstring/tests/zend_multibyte-11.phpt
rename to ext/mbstring/tests/zend_multibyte_block_mode_error.phpt
index bec2c482d65..9e7b6c747f5 100644
--- a/ext/mbstring/tests/zend_multibyte-11.phpt
+++ b/ext/mbstring/tests/zend_multibyte_block_mode_error.phpt
@@ -1,5 +1,5 @@
 --TEST--
-zend multibyte (11)
+zend multibyte encoding declare cannot use block mode
 --EXTENSIONS--
 mbstring
 --INI--
@@ -12,4 +12,4 @@
 }
 ?>
 --EXPECTF--
-Fatal error: Encoding declaration pragma must be the very first statement in the script in %s on line %d
+Fatal error: Encoding declaration must not use block mode in %s on line %d