cvs: ZendEngine2(PHP_5_3) / zend_API.c zend_compile.c /tests ns_063.phpt

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

  Added files:                 (Branch: PHP_5_3)
    /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.296.2.27.2.34.2.33&r2=1.296.2.27.2.34.2.34&diff_format=u
Index: ZendEngine2/zend_API.c
diff -u ZendEngine2/zend_API.c:1.296.2.27.2.34.2.33 ZendEngine2/zend_API.c:1.296.2.27.2.34.2.34
--- ZendEngine2/zend_API.c:1.296.2.27.2.34.2.33	Tue Mar 25 13:04:03 2008
+++ ZendEngine2/zend_API.c	Mon May  5 09:44:39 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_API.c,v 1.296.2.27.2.34.2.33 2008/03/25 13:04:03 dmitry Exp $ */
+/* $Id: zend_API.c,v 1.296.2.27.2.34.2.34 2008/05/05 09:44:39 dmitry Exp $ */
 
 #include "zend.h"
 #include "zend_execute.h"
@@ -1792,7 +1792,13 @@
 
 	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) {
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.647.2.27.2.41.2.60&r2=1.647.2.27.2.41.2.61&diff_format=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.60 ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.61
--- ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.60	Tue Apr 29 08:15:16 2008
+++ ZendEngine2/zend_compile.c	Mon May  5 09:44:39 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_compile.c,v 1.647.2.27.2.41.2.60 2008/04/29 08:15:16 dmitry Exp $ */
+/* $Id: zend_compile.c,v 1.647.2.27.2.41.2.61 2008/05/05 09:44:39 dmitry Exp $ */
 
 #include <zend_language_parser.h>
 #include "zend.h"
@@ -1148,9 +1148,6 @@
 	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 @@
 		}
 
 		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 @@
 			} 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);

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.