cvs: ZendEngine2 / zend_compile.c /tests bug43183.phpt

From: Date: Mon, 12 Nov 2007 15:52:11 +0000
Subject: cvs: ZendEngine2 / zend_compile.c /tests bug43183.phpt
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-6154@lists.php.net to get a copy of this message
dmitry Mon Nov 12 15:52:11 2007 UTC Added files: /ZendEngine2/tests bug43183.phpt Modified files: /ZendEngine2 zend_compile.c Log: Fixed bug #43183 ("use" of the same class in difference scripts results in a fatal error) http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.780&r2=1.781&diff_format=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.780 ZendEngine2/zend_compile.c:1.781 --- ZendEngine2/zend_compile.c:1.780 Fri Nov 9 13:35:22 2007 +++ ZendEngine2/zend_compile.c Mon Nov 12 15:52:11 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.780 2007/11/09 13:35:22 dmitry Exp $ */ +/* $Id: zend_compile.c,v 1.781 2007/11/12 15:52:11 dmitry Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -3199,6 +3199,8 @@ zend_class_entry *new_class_entry; unsigned int lcname_len; zstr lcname; + int error = 0; + zval **ns_name; if (CG(active_class_entry)) { zend_error(E_COMPILE_ERROR, "Class declarations may not be nested"); @@ -3217,8 +3219,8 @@ /* Class name must not conflict with import names */ if (CG(current_import) && - zend_u_hash_exists(CG(current_import), Z_TYPE(class_name->u.constant), lcname, lcname_len+1)) { - zend_error(E_COMPILE_ERROR, "Class name '%R' conflicts with import name", Z_TYPE(class_name->u.constant), Z_UNIVAL(class_name->u.constant)); + zend_u_hash_find(CG(current_import), Z_TYPE(class_name->u.constant), lcname, lcname_len+1, (void**)&ns_name) == SUCCESS) { + error = 1; } if (CG(current_namespace)) { @@ -3233,6 +3235,17 @@ lcname = zend_u_str_case_fold(Z_TYPE(class_name->u.constant), Z_UNIVAL(class_name->u.constant), Z_UNILEN(class_name->u.constant), 0, &lcname_len); } + if (error) { + unsigned int tmp_len; + zstr tmp = zend_u_str_case_fold(Z_TYPE_PP(ns_name), Z_UNIVAL_PP(ns_name), Z_UNILEN_PP(ns_name), 0, &tmp_len); + + if (tmp_len != lcname_len || + memcmp(tmp.v, lcname.v, UG(unicode)?UBYTES(lcname_len):lcname_len)) { + zend_error(E_COMPILE_ERROR, "Class name '%R' conflicts with import name", Z_TYPE(class_name->u.constant), Z_UNIVAL(class_name->u.constant)); + } + efree(tmp.v); + } + new_class_entry = emalloc(sizeof(zend_class_entry)); new_class_entry->type = ZEND_USER_CLASS; new_class_entry->name = Z_UNIVAL(class_name->u.constant); @@ -5204,11 +5217,25 @@ memcpy(ns_name.s + ns_name_len + 2, lcname.s, lcname_len + 1); } if (zend_u_hash_exists(CG(class_table), Z_TYPE_P(CG(current_namespace)), ns_name, ns_name_len + 2 + lcname_len + 1)) { - zend_error(E_COMPILE_ERROR, "Import name '%R' conflicts with defined class", Z_TYPE_P(name), Z_STRVAL_P(name)); + unsigned int tmp_len; + zstr tmp = zend_u_str_case_fold(Z_TYPE_P(ns), Z_UNIVAL_P(ns), Z_UNILEN_P(ns), 0, &tmp_len); + + if (tmp_len != ns_name_len + 2 + lcname_len || + memcmp(tmp.v, ns_name.v, UG(unicode)?UBYTES(tmp_len):tmp_len)) { + zend_error(E_COMPILE_ERROR, "Import name '%R' conflicts with defined class", Z_TYPE_P(name), Z_STRVAL_P(name)); + } + efree(tmp.v); } efree(ns_name.v); } else if (zend_u_hash_exists(CG(class_table), Z_TYPE_P(name), lcname, lcname_len+1)) { - zend_error(E_COMPILE_ERROR, "Import name '%R' conflicts with defined class", Z_TYPE_P(name), Z_UNIVAL_P(name)); + unsigned int tmp_len; + zstr tmp = zend_u_str_case_fold(Z_TYPE_P(ns), Z_UNIVAL_P(ns), Z_UNILEN_P(ns), 0, &tmp_len); + + if (tmp_len != lcname_len || + memcmp(tmp.v, lcname.v, UG(unicode)?UBYTES(tmp_len):tmp_len)) { + zend_error(E_COMPILE_ERROR, "Import name '%R' conflicts with defined class", Z_TYPE_P(name), Z_UNIVAL_P(name)); + } + efree(tmp.v); } if (zend_u_hash_add(CG(current_import), Z_TYPE_P(name), lcname, lcname_len+1, &ns, sizeof(zval*), NULL) != SUCCESS) { http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug43183.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/bug43183.phpt +++ ZendEngine2/tests/bug43183.phpt --TEST-- Bug #43183 ("use" of the same class in difference scripts results in a fatal error) --FILE-- <?php namespace Test; use Test::Foo; class Foo {} class Bar {} use Test::Bar; echo "ok\n"; --EXPECT-- ok

« previous php.zend-engine.cvs (#6154) next »