diff options
| -rw-r--r-- | Zend/tests/ns_063.phpt | 13 | ||||
| -rw-r--r-- | Zend/zend_API.c | 8 | ||||
| -rw-r--r-- | Zend/zend_compile.c | 22 | 
3 files changed, 35 insertions, 8 deletions
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-- +<?php +namespace Foo; +class Bar { +	function Bar() { +		echo "ok\n"; +	} +} +new Bar(); +--EXPECT-- +ok diff --git a/Zend/zend_API.c b/Zend/zend_API.c index bfa2dcf296..3676026d81 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1792,7 +1792,13 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio  	if (scope) {  		class_name_len = strlen(scope->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);  | 
