Skip to content

Commit 1f6ac30

Browse files
nielsdosiluuu1994
authored andcommitted
Allow empty statements before declare(strict_types)
Fixes GH-19719 Closes GH-19859
1 parent 5c6f25b commit 1f6ac30

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ PHP NEWS
1313
using OPcache). (timwolla)
1414
. Fixed bug GH-19480 (error_log php.ini cannot be unset when open_basedir is
1515
configured). (nielsdos)
16+
. Fixed bug GH-19719 (Allow empty statements before declare(strict_types)).
17+
(nielsdos)
1618

1719
- Curl:
1820
. Fix cloning of CURLOPT_POSTFIELDS when using the clone operator instead

Zend/tests/gh19719.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-19719: Allow empty expressions before declare(strict_types)
3+
--FILE--
4+
<?php
5+
// e.g some comments
6+
?>
7+
<?php
8+
9+
declare(strict_types=1);
10+
11+
function takesInt(int $x) {}
12+
13+
try {
14+
takesInt('42');
15+
} catch (Error $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
19+
?>
20+
--EXPECTF--
21+
takesInt(): Argument #1 ($x) must be of type int, string given, called in %s on line %d

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7008,7 +7008,7 @@ static void zend_compile_declare(zend_ast *ast) /* {{{ */
70087008
} else if (zend_string_equals_literal_ci(name, "strict_types")) {
70097009
zval value_zv;
70107010

7011-
if (FAILURE == zend_is_first_statement(ast, /* allow_nop */ 0)) {
7011+
if (FAILURE == zend_is_first_statement(ast, /* allow_nop */ true)) {
70127012
zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must be "
70137013
"the very first statement in the script");
70147014
}

0 commit comments

Comments
 (0)