@@ -7302,11 +7302,7 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
73027302 }
73037303
73047304 zend_register_seen_symbol (lcname , ZEND_SYMBOL_FUNCTION );
7305- if (toplevel ) {
7306- if (UNEXPECTED (zend_hash_add_ptr (CG (function_table ), lcname , op_array ) == NULL )) {
7307- do_bind_function_error (lcname , op_array , 1 );
7308- }
7309- } else {
7305+ if (!toplevel ) {
73107306 uint32_t func_ref = zend_add_dynamic_func_def (op_array );
73117307 if (op_array -> fn_flags & ZEND_ACC_CLOSURE ) {
73127308 opline = zend_emit_op_tmp (result , ZEND_DECLARE_LAMBDA_FUNCTION , NULL , NULL );
@@ -7331,7 +7327,7 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
73317327 zend_ast * stmt_ast = decl -> child [2 ];
73327328 zend_ast * return_type_ast = decl -> child [3 ];
73337329 bool is_method = decl -> kind == ZEND_AST_METHOD ;
7334- zend_string * lcname = NULL ;
7330+ zend_string * lcname ;
73357331
73367332 zend_class_entry * orig_class_entry = CG (active_class_entry );
73377333 zend_op_array * orig_op_array = CG (active_op_array );
@@ -7435,6 +7431,11 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
74357431 CG (zend_lineno ) = decl -> start_lineno ;
74367432 zend_check_magic_method_implementation (
74377433 CG (active_class_entry ), (zend_function * ) op_array , lcname , E_COMPILE_ERROR );
7434+ } else if (toplevel ) {
7435+ /* Only register the function after a successful compile */
7436+ if (UNEXPECTED (zend_hash_add_ptr (CG (function_table ), lcname , op_array ) == NULL )) {
7437+ do_bind_function_error (lcname , op_array , true);
7438+ }
74387439 }
74397440
74407441 /* put the implicit return on the really last line */
0 commit comments