]> granicus.if.org Git - php/commitdiff
Fix anon class handling in ext mode
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 22 Feb 2019 14:42:37 +0000 (15:42 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 22 Feb 2019 14:43:08 +0000 (15:43 +0100)
Opcode order changes in 7.4 and the EXT_STMT is now declare the
DECLARE_ANON. Fix this by returning the opline from compile_class_decl
to avoid any fragile opcode searching.

Zend/zend_compile.c

index eee2347f494f26b56e6f32bf03661271cd0beb99..bd7139eb5db8f0a07796e485c0180936b78d4f5d 100644 (file)
@@ -3972,7 +3972,7 @@ void zend_compile_static_call(znode *result, zend_ast *ast, uint32_t type) /* {{
 }
 /* }}} */
 
-void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel);
+zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel);
 
 void zend_compile_new(znode *result, zend_ast *ast) /* {{{ */
 {
@@ -3983,13 +3983,8 @@ void zend_compile_new(znode *result, zend_ast *ast) /* {{{ */
        zend_op *opline;
 
        if (class_ast->kind == ZEND_AST_CLASS) {
-               uint32_t dcl_opnum = get_next_op_number();
-               zend_compile_class_decl(class_ast, 0);
                /* jump over anon class declaration */
-               opline = &CG(active_op_array)->opcodes[dcl_opnum];
-               if (opline->opcode == ZEND_FETCH_CLASS) {
-                       opline++;
-               }
+               opline = zend_compile_class_decl(class_ast, 0);
                class_node.op_type = opline->result_type;
                class_node.u.op.var = opline->result.var;
                opline->extended_value = get_next_op_number();
@@ -6181,7 +6176,7 @@ static zend_string *zend_generate_anon_class_name(unsigned char *lex_pos) /* {{{
 }
 /* }}} */
 
-void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
+zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
 {
        zend_ast_decl *decl = (zend_ast_decl *) ast;
        zend_ast *extends_ast = decl->child[0];
@@ -6341,7 +6336,7 @@ void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
                                        }
                                        CG(zend_lineno) = ast->lineno;
                                        zend_string_release(lcname);
-                                       return;
+                                       return NULL;
                                }
                        }
                } else {
@@ -6349,7 +6344,7 @@ void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
                                zend_string_release(lcname);
                                zend_build_properties_info_table(ce);
                                ce->ce_flags |= ZEND_ACC_LINKED;
-                               return;
+                               return NULL;
                        }
                }
        }
@@ -6375,7 +6370,7 @@ void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
                        zval zv;
                        ZVAL_PTR(&zv, ce);
                        destroy_zend_class(&zv);
-                       return;
+                       return opline;
                }
        } else {
                zend_string *key = zend_build_runtime_definition_key(lcname, decl->lex_pos);
@@ -6402,6 +6397,7 @@ void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
                        opline->opcode = ZEND_DECLARE_CLASS;
                }
        }
+       return opline;
 }
 /* }}} */