php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #64239
Patch bug64239-2.patch revision 2013-03-21 09:06 UTC by dmitry@php.net
revision 2013-03-21 07:55 UTC by dmitry at zend dot com
Patch bug64329.patch revision 2013-03-21 08:18 UTC by laruence@php.net
Patch bug64239.patch revision 2013-03-21 06:04 UTC by laruence@php.net

Patch bug64239-2.patch for *General Issues Bug #64239

Patch version 2013-03-21 09:06 UTC

Return to Bug #64239 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: dmitry@php.net

diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index dcb1818..97f1297 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1033,6 +1033,60 @@ static int same_name(const char *key, const char *name, zend_uint name_len)
 	return ret;
 }
 
+static const char* zend_find_alias_name(zend_class_entry *ce, const char *name, zend_uint len)
+{
+	zend_trait_alias *alias, **alias_ptr;
+
+	alias_ptr = ce->trait_aliases;
+	alias = *alias_ptr;
+	while (alias) {
+		if (alias->alias_len == len &&
+		    same_name(name, alias->alias, alias->alias_len)) {
+			return alias->alias;
+		}
+		alias_ptr++;
+		alias = *alias_ptr;
+	}
+
+	return name;
+}
+
+ZEND_API const char* zend_resolve_method_name(zend_class_entry *ce, zend_function *f)
+{
+	zend_function *func;
+	HashPosition iterator;
+	HashTable *function_table;
+
+	if (f->common.type != ZEND_USER_FUNCTION ||
+	    *(f->op_array.refcount) < 2 ||
+	    !f->common.scope ||
+	    !f->common.scope->trait_aliases) {
+		return f->common.function_name;
+	}
+
+	function_table = &ce->function_table;
+	zend_hash_internal_pointer_reset_ex(function_table, &iterator);
+	while (zend_hash_get_current_data_ex(function_table, (void **)&func, &iterator) == SUCCESS) {
+		if (func == f) {
+			char *name;
+			uint len;
+			ulong idx;
+
+			if (zend_hash_get_current_key_ex(function_table, &name, &len, &idx, 0, &iterator) != HASH_KEY_IS_STRING) {
+				return f->common.function_name;
+			}
+			--len;
+			if (len == strlen(f->common.function_name) &&
+			    same_name(name, f->common.function_name, len)) {
+				return f->common.function_name;
+			}
+			return zend_find_alias_name(f->common.scope, name, len);
+		}
+		zend_hash_move_forward_ex(function_table, &iterator);
+	}
+	return f->common.function_name;
+}
+
 /* {{{ proto array get_class_methods(mixed class)
    Returns an array of method names for class or class instance. */
 ZEND_FUNCTION(get_class_methods)
@@ -1092,7 +1146,7 @@ ZEND_FUNCTION(get_class_methods)
 			    	(len != key_len - 1 ||
 			    	 !same_name(key, mptr->common.function_name, len))) {
 					MAKE_STD_ZVAL(method_name);
-					ZVAL_STRINGL(method_name, key, key_len - 1, 1);
+					ZVAL_STRINGL(method_name, zend_find_alias_name(mptr->common.scope, key, key_len - 1), key_len - 1, 1);
 					zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL);
 				} else {
 					MAKE_STD_ZVAL(method_name);
@@ -2118,7 +2172,14 @@ ZEND_FUNCTION(debug_print_backtrace)
 			lineno = 0;
 		}
 
-		function_name = ptr->function_state.function->common.function_name;
+		function_name = (ptr->function_state.function->common.scope &&
+			ptr->function_state.function->common.scope->trait_aliases) ?
+				zend_resolve_method_name(
+					ptr->object ?
+						Z_OBJCE_P(ptr->object) : 
+						ptr->function_state.function->common.scope,
+					ptr->function_state.function) :
+				ptr->function_state.function->common.function_name;
 
 		if (function_name) {
 			if (ptr->object) {
@@ -2299,7 +2360,14 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
 			filename = NULL;
 		}
 
-		function_name = ptr->function_state.function->common.function_name;
+		function_name = (ptr->function_state.function->common.scope &&
+			ptr->function_state.function->common.scope->trait_aliases) ?
+				zend_resolve_method_name(
+					ptr->object ?
+						Z_OBJCE_P(ptr->object) : 
+						ptr->function_state.function->common.scope,
+					ptr->function_state.function) :
+				ptr->function_state.function->common.function_name;
 
 		if (function_name) {
 			add_assoc_string_ex(stack_frame, "function", sizeof("function"), (char*)function_name, 1);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 07 07:01:29 2024 UTC