@@ -5864,20 +5864,19 @@ zend_bool zend_handle_encoding_declaration(zend_ast *ast) /* {{{ */
5864
5864
}
5865
5865
/* }}} */
5866
5866
5867
- static zend_result zend_declare_is_first_statement (zend_ast * ast ) /* {{{ */
5867
+ /* Check whether this is the first statement, not counting declares. */
5868
+ static zend_result zend_is_first_statement (zend_ast * ast ) /* {{{ */
5868
5869
{
5869
5870
uint32_t i = 0 ;
5870
5871
zend_ast_list * file_ast = zend_ast_get_list (CG (ast ));
5871
5872
5872
- /* Check to see if this declare is preceded only by declare statements */
5873
5873
while (i < file_ast -> children ) {
5874
5874
if (file_ast -> child [i ] == ast ) {
5875
5875
return SUCCESS ;
5876
5876
} else if (file_ast -> child [i ] == NULL ) {
5877
- /* Empty statements are not allowed prior to a declare */
5877
+ /* Empty statements count as statements. */
5878
5878
return FAILURE ;
5879
5879
} else if (file_ast -> child [i ]-> kind != ZEND_AST_DECLARE ) {
5880
- /* declares can only be preceded by other declares */
5881
5880
return FAILURE ;
5882
5881
}
5883
5882
i ++ ;
@@ -5910,14 +5909,14 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */
5910
5909
zval_ptr_dtor_nogc (& value_zv );
5911
5910
} else if (zend_string_equals_literal_ci (name , "encoding" )) {
5912
5911
5913
- if (FAILURE == zend_declare_is_first_statement (ast )) {
5912
+ if (FAILURE == zend_is_first_statement (ast )) {
5914
5913
zend_error_noreturn (E_COMPILE_ERROR , "Encoding declaration pragma must be "
5915
5914
"the very first statement in the script" );
5916
5915
}
5917
5916
} else if (zend_string_equals_literal_ci (name , "strict_types" )) {
5918
5917
zval value_zv ;
5919
5918
5920
- if (FAILURE == zend_declare_is_first_statement (ast )) {
5919
+ if (FAILURE == zend_is_first_statement (ast )) {
5921
5920
zend_error_noreturn (E_COMPILE_ERROR , "strict_types declaration must be "
5922
5921
"the very first statement in the script" );
5923
5922
}
@@ -7682,20 +7681,11 @@ void zend_compile_namespace(zend_ast *ast) /* {{{ */
7682
7681
}
7683
7682
}
7684
7683
7685
- if (((!with_bracket && !FC (current_namespace ))
7686
- || (with_bracket && !FC (has_bracketed_namespaces ))) && CG (active_op_array )-> last > 0
7687
- ) {
7688
- /* ignore ZEND_EXT_STMT and ZEND_TICKS */
7689
- uint32_t num = CG (active_op_array )-> last ;
7690
- while (num > 0 &&
7691
- (CG (active_op_array )-> opcodes [num - 1 ].opcode == ZEND_EXT_STMT ||
7692
- CG (active_op_array )-> opcodes [num - 1 ].opcode == ZEND_TICKS )) {
7693
- -- num ;
7694
- }
7695
- if (num > 0 ) {
7696
- zend_error_noreturn (E_COMPILE_ERROR , "Namespace declaration statement has to be "
7697
- "the very first statement or after any declare call in the script" );
7698
- }
7684
+ zend_bool is_first_namespace = (!with_bracket && !FC (current_namespace ))
7685
+ || (with_bracket && !FC (has_bracketed_namespaces ));
7686
+ if (is_first_namespace && FAILURE == zend_is_first_statement (ast )) {
7687
+ zend_error_noreturn (E_COMPILE_ERROR , "Namespace declaration statement has to be "
7688
+ "the very first statement or after any declare call in the script" );
7699
7689
}
7700
7690
7701
7691
if (FC (current_namespace )) {
0 commit comments