From: Dmitry Stogov Date: Mon, 5 May 2008 09:44:39 +0000 (+0000) Subject: Support for old-style constructors in namespaces X-Git-Tag: BEFORE_NEW_PARAMETER_PARSE~284 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5a0253c14cf197c42731c7a2aef37920d6009ee3;p=php Support for old-style constructors in namespaces --- diff --git a/Zend/tests/ns_063.phpt b/Zend/tests/ns_063.phpt new file mode 100644 index 0000000000..1be000983f --- /dev/null +++ b/Zend/tests/ns_063.phpt @@ -0,0 +1,13 @@ +--TEST-- +063: Support for old-style constructors in namesapces +--FILE-- +name); - lc_class_name = zend_str_tolower_dup(scope->name, class_name_len); + if ((lc_class_name = zend_memrchr(scope->name, ':', class_name_len))) { + lc_class_name++; + class_name_len -= (lc_class_name - scope->name); + lc_class_name = zend_str_tolower_dup(lc_class_name, class_name_len); + } else { + lc_class_name = zend_str_tolower_dup(scope->name, class_name_len); + } } while (ptr->fname) { diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 910c5a442c..09bf537156 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1148,9 +1148,6 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n op_array.line_start = zend_get_compiled_lineno(TSRMLS_C); if (is_method) { - char *short_class_name = CG(active_class_entry)->name; - int short_class_name_length = CG(active_class_entry)->name_length; - if (zend_hash_add(&CG(active_class_entry)->function_table, lcname, name_len+1, &op_array, sizeof(zend_op_array), (void **) &CG(active_op_array)) == FAILURE) { zend_op_array *child_op_array, *parent_op_array; if (CG(active_class_entry)->parent @@ -1173,11 +1170,22 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n } if (!(CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE)) { - short_class_name = do_alloca(short_class_name_length + 1, use_heap); - zend_str_tolower_copy(short_class_name, CG(active_class_entry)->name, short_class_name_length); + char *short_class_name; + int short_class_name_length; + char *short_class_lcname; + + if ((short_class_name = zend_memrchr(CG(active_class_entry)->name, ':', CG(active_class_entry)->name_length))) { + short_class_name++; + short_class_name_length = CG(active_class_entry)->name_length - (short_class_name - CG(active_class_entry)->name); + } else { + short_class_name = CG(active_class_entry)->name; + short_class_name_length = CG(active_class_entry)->name_length; + } + short_class_lcname = do_alloca(short_class_name_length + 1, use_heap); + zend_str_tolower_copy(short_class_lcname, short_class_name, short_class_name_length); /* Improve after RC: cache the lowercase class name */ - if ((short_class_name_length == name_len) && (!memcmp(short_class_name, lcname, name_len))) { + if ((short_class_name_length == name_len) && (!memcmp(short_class_lcname, lcname, name_len))) { if (CG(active_class_entry)->constructor) { zend_error(E_STRICT, "Redefining already defined constructor for class %s", CG(active_class_entry)->name); } else { @@ -1209,7 +1217,7 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n } else if (!(fn_flags & ZEND_ACC_STATIC)) { CG(active_op_array)->fn_flags |= ZEND_ACC_ALLOW_STATIC; } - free_alloca(short_class_name, use_heap); + free_alloca(short_class_lcname, use_heap); } efree(lcname);