@@ -5865,7 +5865,7 @@ zend_bool zend_handle_encoding_declaration(zend_ast *ast) /* {{{ */
5865
5865
/* }}} */
5866
5866
5867
5867
/* Check whether this is the first statement, not counting declares. */
5868
- static zend_result zend_is_first_statement (zend_ast * ast ) /* {{{ */
5868
+ static zend_result zend_is_first_statement (zend_ast * ast , zend_bool allow_nop ) /* {{{ */
5869
5869
{
5870
5870
uint32_t i = 0 ;
5871
5871
zend_ast_list * file_ast = zend_ast_get_list (CG (ast ));
@@ -5874,8 +5874,9 @@ static zend_result zend_is_first_statement(zend_ast *ast) /* {{{ */
5874
5874
if (file_ast -> child [i ] == ast ) {
5875
5875
return SUCCESS ;
5876
5876
} else if (file_ast -> child [i ] == NULL ) {
5877
- /* Empty statements count as statements. */
5878
- return FAILURE ;
5877
+ if (!allow_nop ) {
5878
+ return FAILURE ;
5879
+ }
5879
5880
} else if (file_ast -> child [i ]-> kind != ZEND_AST_DECLARE ) {
5880
5881
return FAILURE ;
5881
5882
}
@@ -5909,14 +5910,14 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */
5909
5910
zval_ptr_dtor_nogc (& value_zv );
5910
5911
} else if (zend_string_equals_literal_ci (name , "encoding" )) {
5911
5912
5912
- if (FAILURE == zend_is_first_statement (ast )) {
5913
+ if (FAILURE == zend_is_first_statement (ast , /* allow_nop */ 0 )) {
5913
5914
zend_error_noreturn (E_COMPILE_ERROR , "Encoding declaration pragma must be "
5914
5915
"the very first statement in the script" );
5915
5916
}
5916
5917
} else if (zend_string_equals_literal_ci (name , "strict_types" )) {
5917
5918
zval value_zv ;
5918
5919
5919
- if (FAILURE == zend_is_first_statement (ast )) {
5920
+ if (FAILURE == zend_is_first_statement (ast , /* allow_nop */ 0 )) {
5920
5921
zend_error_noreturn (E_COMPILE_ERROR , "strict_types declaration must be "
5921
5922
"the very first statement in the script" );
5922
5923
}
@@ -7669,7 +7670,7 @@ void zend_compile_namespace(zend_ast *ast) /* {{{ */
7669
7670
7670
7671
zend_bool is_first_namespace = (!with_bracket && !FC (current_namespace ))
7671
7672
|| (with_bracket && !FC (has_bracketed_namespaces ));
7672
- if (is_first_namespace && FAILURE == zend_is_first_statement (ast )) {
7673
+ if (is_first_namespace && FAILURE == zend_is_first_statement (ast , /* allow_nop */ 1 )) {
7673
7674
zend_error_noreturn (E_COMPILE_ERROR , "Namespace declaration statement has to be "
7674
7675
"the very first statement or after any declare call in the script" );
7675
7676
}
0 commit comments