php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch alias-reflection.patch for Reflection related Bug #68103

Patch version 2014-09-26 06:50 UTC

Return to Bug #68103 | Download this patch
Patch Revisions:

Developer: remi@php.net

diff -up ext/reflection/php_reflection.c.old ext/reflection/php_reflection.c
--- ext/reflection/php_reflection.c.old	2014-09-26 06:59:13.763565911 +0200
+++ ext/reflection/php_reflection.c	2014-09-26 07:20:00.176753361 +0200
@@ -1015,9 +1015,12 @@ static int _extension_class_string(zend_
 	int *num_classes = va_arg(args, int*);
 
 	if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) {
-		string_printf(str, "\n");
-		_class_string(str, *pce, NULL, indent TSRMLS_CC);
-		(*num_classes)++;
+		/* dump class if it is not an alias */
+		if (!zend_binary_strcasecmp((*pce)->name, (*pce)->name_length, hash_key->arKey, hash_key->nKeyLength-1)) {
+			string_printf(str, "\n");
+			_class_string(str, *pce, NULL, indent TSRMLS_CC);
+			(*num_classes)++;
+		}
 	}
 	return ZEND_HASH_APPLY_KEEP;
 }
@@ -5395,12 +5398,24 @@ static int add_extension_class(zend_clas
 	int add_reflection_class = va_arg(args, int);
 
 	if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) {
+		const char *name;
+		int nlen;
+
+		if (zend_binary_strcasecmp((*pce)->name, (*pce)->name_length, hash_key->arKey, hash_key->nKeyLength-1)) {
+			/* This is an class alias, use alias name */
+			name = hash_key->arKey;
+			nlen = hash_key->nKeyLength-1;
+		} else {
+			/* Use class name */
+			name = (*pce)->name;
+			nlen = (*pce)->name_length;
+		}
 		if (add_reflection_class) {
 			ALLOC_ZVAL(zclass);
 			zend_reflection_class_factory(*pce, zclass TSRMLS_CC);
-			add_assoc_zval_ex(class_array, (*pce)->name, (*pce)->name_length + 1, zclass);
+			add_assoc_zval_ex(class_array, name, nlen+1, zclass);
 		} else {
-			add_next_index_stringl(class_array, (*pce)->name, (*pce)->name_length, 1);
+			add_next_index_stringl(class_array, name, nlen, 1);
 		}
 	}
 	return ZEND_HASH_APPLY_KEEP;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC