Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Zend/tests/gh19719.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
GH-19719: Allow empty expressions before declare(strict_types)
--FILE--
<?php
// e.g some comments
?>
<?php

declare(strict_types=1);

function takesInt(int $x) {}

try {
takesInt('42');
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECTF--
takesInt(): Argument #1 ($x) must be of type int, string given, called in %s on line %d
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down