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 bug64329.patch for *General Issues Bug #64239

Patch version 2013-03-21 08:18 UTC

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

Obsolete patches:

Patch Revisions:

Developer: laruence@php.net

diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index ee75f52..5cb5b58 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -2053,6 +2053,58 @@ void debug_print_backtrace_args(zval *arg_array TSRMLS_DC)
 	}
 }
 
+ZEND_API void zend_resolve_method_alias_name(zend_class_entry *scope, zend_function *f, char **alias_name, int *alias_len, int fetch_origin)
+{
+	zend_function *func;
+	HashPosition iterator;
+	zend_class_entry *ce;
+	HashTable *function_table;
+
+	if (f->common.type != ZEND_USER_FUNCTION || *(f->op_array.refcount) < 2) {
+		return;
+	}
+
+	ce = f->common.scope;
+	if (!ce || !ce->trait_aliases) {
+		return;
+	}
+
+	function_table = &scope->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;
+			zend_trait_alias *alias, **alias_ptr;
+			if (zend_hash_get_current_key_ex(function_table, &name, &len, &idx, 0, &iterator) != HASH_KEY_IS_STRING) {
+				return;
+			}
+			--len;
+			if (fetch_origin) {
+				do {
+					alias_ptr = ce->trait_aliases;
+					alias = *alias_ptr;
+					while (alias) {
+						if (alias->alias_len == len && !zend_binary_strncasecmp(name, len, alias->alias, alias->alias_len, len)) {
+							*alias_name = alias->alias;
+							*alias_len = alias->alias_len;
+							return;
+						}
+						alias_ptr++;
+						alias = *alias_ptr;
+					}
+				} while ((ce = ce->parent));
+			} else {
+				*alias_name = name;
+				*alias_len = len;
+				return;
+			}
+		}
+		zend_hash_move_forward_ex(function_table, &iterator);
+	}
+}
+
 /* {{{ proto void debug_print_backtrace([int options[, int limit]]) */
 ZEND_FUNCTION(debug_print_backtrace)
 {
@@ -2106,13 +2158,16 @@ ZEND_FUNCTION(debug_print_backtrace)
 		function_name = ptr->function_state.function->common.function_name;
 
 		if (function_name) {
+			int dummy;
 			if (ptr->object) {
 				if (ptr->function_state.function->common.scope) {
+					zend_resolve_method_alias_name(ptr->function_state.function->common.scope, ptr->function_state.function, &function_name, &dummy, 1);
 					class_name = ptr->function_state.function->common.scope->name;
 				} else {
 					zend_uint class_name_len;
 					int dup;
 
+					zend_resolve_method_alias_name(Z_OBJCE_P(ptr->object), ptr->function_state.function, &function_name, &dummy, 1);
 					dup = zend_get_object_classname(ptr->object, &class_name, &class_name_len TSRMLS_CC);
 					if(!dup) {
 						free_class_name = class_name;
@@ -2121,8 +2176,9 @@ ZEND_FUNCTION(debug_print_backtrace)
 
 				call_type = "->";
 			} else if (ptr->function_state.function->common.scope) {
-				class_name = ptr->function_state.function->common.scope->name;
+				zend_resolve_method_alias_name(ptr->function_state.function->common.scope, ptr->function_state.function, &function_name, &dummy, 1);
 				call_type = "::";
+				class_name = ptr->function_state.function->common.scope->name;
 			} else {
 				class_name = NULL;
 				call_type = NULL;
@@ -2287,18 +2343,21 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
 		function_name = ptr->function_state.function->common.function_name;
 
 		if (function_name) {
-			add_assoc_string_ex(stack_frame, "function", sizeof("function"), (char*)function_name, 1);
-
+			int dummy;
 			if (ptr->object && Z_TYPE_P(ptr->object) == IS_OBJECT) {
 				if (ptr->function_state.function->common.scope) {
+					zend_resolve_method_alias_name(ptr->function_state.function->common.scope, ptr->function_state.function, &function_name, &dummy, 1);
+					add_assoc_string_ex(stack_frame, "function", sizeof("function"), (char*)function_name, 1);
 					add_assoc_string_ex(stack_frame, "class", sizeof("class"), (char*)ptr->function_state.function->common.scope->name, 1);
 				} else {
 					zend_uint class_name_len;
 					int dup;
 
+					zend_resolve_method_alias_name(Z_OBJCE_P(ptr->object), ptr->function_state.function, &function_name, &dummy, 1);
+					add_assoc_string_ex(stack_frame, "function", sizeof("function"), (char*)function_name, 1);
 					dup = zend_get_object_classname(ptr->object, &class_name, &class_name_len TSRMLS_CC);
 					add_assoc_string_ex(stack_frame, "class", sizeof("class"), (char*)class_name, dup);
-					
+
 				}
 				if ((options & DEBUG_BACKTRACE_PROVIDE_OBJECT) != 0) {
 					add_assoc_zval_ex(stack_frame, "object", sizeof("object"), ptr->object);
@@ -2307,6 +2366,8 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
 
 				add_assoc_string_ex(stack_frame, "type", sizeof("type"), "->", 1);
 			} else if (ptr->function_state.function->common.scope) {
+				zend_resolve_method_alias_name(ptr->function_state.function->common.scope, ptr->function_state.function, &function_name, &dummy, 1);
+				add_assoc_string_ex(stack_frame, "function", sizeof("function"), (char*)function_name, 1);
 				add_assoc_string_ex(stack_frame, "class", sizeof("class"), (char*)ptr->function_state.function->common.scope->name, 1);
 				add_assoc_string_ex(stack_frame, "type", sizeof("type"), "::", 1);
 			}
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 18:01:55 2014 UTC