cvs: ZendEngine2 / zend_API.c zend_compile.c /tests ns_063.phpt

[email protected] ("Dmitry Stogov")
Newsgroups php.zend-engine.cvs
Message-ID <cvsdmitry1209980647@cvsserver>
dmitry		Mon May  5 09:44:07 2008 UTC

  Added files:                 
    /ZendEngine2/tests	ns_063.phpt 

  Modified files:              
    /ZendEngine2	zend_API.c zend_compile.c 
  Log:
  Support for old-style constructors in namespaces
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_API.c?r1=1.467&r2=1.468&diff_format=u
Index: ZendEngine2/zend_API.c
diff -u ZendEngine2/zend_API.c:1.467 ZendEngine2/zend_API.c:1.468
--- ZendEngine2/zend_API.c:1.467	Wed Mar 26 09:09:08 2008
+++ ZendEngine2/zend_API.c	Mon May  5 09:44:07 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_API.c,v 1.467 2008/03/26 09:09:08 tony2001 Exp $ */
+/* $Id: zend_API.c,v 1.468 2008/05/05 09:44:07 dmitry Exp $ */
 
 #include "zend.h"
 #include "zend_execute.h"
@@ -2118,7 +2118,23 @@
 	internal_function->module = EG(current_module);
 
 	if (scope) {
-		lc_class_name = zend_u_str_case_fold(ZEND_STR_TYPE, scope->name, scope->name_length, 0, &lc_class_name_len);
+		lc_class_name_len = scope->name_length;
+		if (UG(unicode)) {
+			if ((lc_class_name.u = u_memrchr(scope->name.u, ':', lc_class_name_len))) {
+				lc_class_name.u++;
+				lc_class_name_len -= (lc_class_name.u - scope->name.u);
+			} else {
+				lc_class_name = scope->name;
+			}
+		} else {
+			if ((lc_class_name.s = zend_memrchr(scope->name.s, ':', lc_class_name_len))) {
+				lc_class_name.s++;
+				lc_class_name_len -= (lc_class_name.s - scope->name.s);
+			} else {
+				lc_class_name = scope->name;
+			}
+		}
+		lc_class_name = zend_u_str_case_fold(ZEND_STR_TYPE, lc_class_name, lc_class_name_len, 0, &lc_class_name_len);
 	}
 
 	while (ptr->fname) {
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.820&r2=1.821&diff_format=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.820 ZendEngine2/zend_compile.c:1.821
--- ZendEngine2/zend_compile.c:1.820	Tue Apr 29 08:15:48 2008
+++ ZendEngine2/zend_compile.c	Mon May  5 09:44:07 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_compile.c,v 1.820 2008/04/29 08:15:48 dmitry Exp $ */
+/* $Id: zend_compile.c,v 1.821 2008/05/05 09:44:07 dmitry Exp $ */
 
 #include <zend_language_parser.h>
 #include "zend.h"
@@ -1238,9 +1238,6 @@
 	op_array.line_start = zend_get_compiled_lineno(TSRMLS_C);
 
 	if (is_method) {
-		zstr short_class_name = CG(active_class_entry)->name;
-		unsigned int short_class_name_length = CG(active_class_entry)->name_length;
-
 		if (zend_u_hash_add(&CG(active_class_entry)->function_table, Z_TYPE(function_name->u.constant), lcname, lcname_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
@@ -1263,10 +1260,31 @@
 		}
 
 		if (!(CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE)) {
-			short_class_name = zend_u_str_case_fold(UG(unicode)?IS_UNICODE:IS_STRING, CG(active_class_entry)->name, short_class_name_length, 0, &short_class_name_length);
+			zstr short_class_name;
+			unsigned int short_class_name_length;
+			zstr short_class_lcname;
+
+			if (UG(unicode)) {
+				if ((short_class_name.u = u_memrchr(CG(active_class_entry)->name.u, ':', CG(active_class_entry)->name_length))) {
+					short_class_name.u++;
+					short_class_name_length = CG(active_class_entry)->name_length - (short_class_name.u - CG(active_class_entry)->name.u);
+				} else {
+					short_class_name = CG(active_class_entry)->name;
+					short_class_name_length = CG(active_class_entry)->name_length;
+				}
+			} else {
+				if ((short_class_name.s = zend_memrchr(CG(active_class_entry)->name.s, ':', CG(active_class_entry)->name_length))) {
+					short_class_name.s++;
+					short_class_name_length = CG(active_class_entry)->name_length - (short_class_name.s - CG(active_class_entry)->name.s);
+				} else {
+					short_class_name = CG(active_class_entry)->name;
+					short_class_name_length = CG(active_class_entry)->name_length;
+				}
+			}
+			short_class_lcname = zend_u_str_case_fold(UG(unicode)?IS_UNICODE:IS_STRING, short_class_name, short_class_name_length, 0, &short_class_name_length);
 			/* Improve after RC: cache the lowercase class name */
 
-			if ((short_class_name_length == name_len) && (!memcmp(short_class_name.v, lcname.v, UG(unicode)?UBYTES(lcname_len):lcname_len))) {
+			if ((short_class_name_length == name_len) && (!memcmp(short_class_lcname.v, lcname.v, UG(unicode)?UBYTES(lcname_len):lcname_len))) {
 				if (CG(active_class_entry)->constructor) {
 					zend_error(E_STRICT, "Redefining already defined constructor for class %v", CG(active_class_entry)->name);
 				} else {
@@ -1298,7 +1316,7 @@
 			} else if (!(fn_flags & ZEND_ACC_STATIC)) {
 				CG(active_op_array)->fn_flags |= ZEND_ACC_ALLOW_STATIC;
 			}
-			efree(short_class_name.v);
+			efree(short_class_lcname.v);
 		}
 
 		efree(lcname.v);

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_063.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_063.phpt
+++ ZendEngine2/tests/ns_063.phpt
--TEST--
063: Support for old-style constructors in namesapces
--FILE--
<?php
namespace Foo;
class Bar {
	function Bar() {
		echo "ok\n";
	}
}
new Bar();
--EXPECT--
ok
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.