[php-src] master: Zend: No longer allow block mode for declare(encoding) (#9455)

From: Date: Wed, 04 Nov 2026 15:21:56 +0000
Subject: [php-src] master: Zend: No longer allow block mode for declare(encoding) (#9455)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143325@lists.php.net to get a copy of this message
Author: Christoph M. Becker (cmb69) Committer: GitHub (web-flow) Pusher: Girgias Date: 2026-11-04T15:21:52Z Commit: https://github.com/php/php-src/commit/0174b957ff71abc9af2b7da36edf1d5b8a80ab63 Raw diff: https://github.com/php/php-src/commit/0174b957ff71abc9af2b7da36edf1d5b8a80ab63.diff 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> Changed paths: A ext/mbstring/tests/zend_multibyte_alternative_block_mode_error.phpt A ext/mbstring/tests/zend_multibyte_block_mode_error.phpt D ext/mbstring/tests/zend_multibyte-11.phpt D ext/mbstring/tests/zend_multibyte-15.phpt D ext/mbstring/tests/zend_multibyte-16.phpt M Zend/tests/declare/bug69092.2.phpt M Zend/tests/declare/bug69092.phpt M Zend/zend_compile.c M ext/mbstring/tests/zend_multibyte-12.phpt Diff: diff --git a/Zend/tests/declare/bug69092.2.phpt b/Zend/tests/declare/bug69092.2.phpt index f774820056d1..e9211bdc8154 100644 --- a/Zend/tests/declare/bug69092.2.phpt +++ b/Zend/tests/declare/bug69092.2.phpt @@ -15,4 +15,4 @@ echo "Bye" --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 bf2655b1a1b2..4ea7c62d7e29 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 834393686b31..5ecee520cd1a 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 934bf56cd62f..9357e1bb7cbb 100644 --- a/ext/mbstring/tests/zend_multibyte-12.phpt +++ b/ext/mbstring/tests/zend_multibyte-12.phpt @@ -11,4 +11,4 @@ echo 1; 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 bcf4ebe59d8e..000000000000 --- 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 ed02f6895b18..000000000000 --- 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 000000000000..4d31e08200c4 --- /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 bec2c482d659..9e7b6c747f5a 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 @@ 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 must not use block mode in %s on line %d

« previous php.cvs (#143325) next »