From 1f6ac30769f58b1c304e4e9fda44097fa6d4f29e Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 17 Sep 2025 15:06:25 +0200 Subject: [PATCH] Allow empty statements before declare(strict_types) Fixes GH-19719 Closes GH-19859 --- NEWS | 2 ++ Zend/tests/gh19719.phpt | 21 +++++++++++++++++++++ Zend/zend_compile.c | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/gh19719.phpt diff --git a/NEWS b/NEWS index 6bd00000a10..7b6f8f9440d 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,8 @@ PHP NEWS using OPcache). (timwolla) . Fixed bug GH-19480 (error_log php.ini cannot be unset when open_basedir is configured). (nielsdos) + . Fixed bug GH-19719 (Allow empty statements before declare(strict_types)). + (nielsdos) - Curl: . Fix cloning of CURLOPT_POSTFIELDS when using the clone operator instead diff --git a/Zend/tests/gh19719.phpt b/Zend/tests/gh19719.phpt new file mode 100644 index 00000000000..715e847846f --- /dev/null +++ b/Zend/tests/gh19719.phpt @@ -0,0 +1,21 @@ +--TEST-- +GH-19719: Allow empty expressions before declare(strict_types) +--FILE-- + +getMessage(), "\n"; +} + +?> +--EXPECTF-- +takesInt(): Argument #1 ($x) must be of type int, string given, called in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ad735c41aca..f43fdd7b318 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -7008,7 +7008,7 @@ static void zend_compile_declare(zend_ast *ast) /* {{{ */ } else if (zend_string_equals_literal_ci(name, "strict_types")) { zval value_zv; - if (FAILURE == zend_is_first_statement(ast, /* allow_nop */ 0)) { + if (FAILURE == zend_is_first_statement(ast, /* allow_nop */ true)) { zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must be " "the very first statement in the script"); }