From e8a6d91dfdda9870ad8503faec489dc0f136f581 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 --- Zend/tests/gh19719.phpt | 21 +++++++++++++++++++++ Zend/zend_compile.c | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/gh19719.phpt diff --git a/Zend/tests/gh19719.phpt b/Zend/tests/gh19719.phpt new file mode 100644 index 0000000000000..715e847846fe1 --- /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 ad735c41acaff..f43fdd7b31827 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"); }