diff options
| author | Dmitry Stogov <dmitry@php.net> | 2007-10-17 10:01:37 +0000 |
|---|---|---|
| committer | Dmitry Stogov <dmitry@php.net> | 2007-10-17 10:01:37 +0000 |
| commit | 8cae2e56e4dc5f9a138e237b89937ac1b16d5fe1 (patch) | |
| tree | 1f8164bbacc05f87a958a2720dce4e393badaf0c | |
| parent | 29fd758310635536cb9e7174bf0c54d6b4a0af5b (diff) | |
| download | php-git-8cae2e56e4dc5f9a138e237b89937ac1b16d5fe1.tar.gz | |
Fixed bug #42859 (import always conflicts with internal classes). (cellog@php.net, Dmitry)
| -rwxr-xr-x | Zend/tests/bug42859.phpt | 12 | ||||
| -rw-r--r-- | Zend/zend_compile.c | 22 |
2 files changed, 33 insertions, 1 deletions
diff --git a/Zend/tests/bug42859.phpt b/Zend/tests/bug42859.phpt new file mode 100755 index 0000000000..6464f9b4c7 --- /dev/null +++ b/Zend/tests/bug42859.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #42859 import always conflicts with internal classes +--FILE-- +<?php +namespace Foo; +class Ex {} + +import Blah::Exception; +import Blah::Ex; +?> +--EXPECTF-- +Fatal error: Import name 'Ex' conflicts with defined class in %sbug42859.php on line 6
\ No newline at end of file diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 8e0b331b73..7ea34c5d6c 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5149,7 +5149,27 @@ void zend_do_import(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */ zend_error(E_COMPILE_ERROR, "Cannot use '%R' as import name", Z_TYPE_P(name), Z_UNIVAL_P(name)); } - if (zend_u_hash_exists(CG(class_table), Z_TYPE_P(name), lcname, lcname_len+1)) { + if (CG(current_namespace)) { + /* Prefix import name with current namespace name to avoid conflicts with classes */ + uint ns_name_len; + zstr ns_name = zend_u_str_case_fold(Z_TYPE_P(CG(current_namespace)), Z_UNIVAL_P(CG(current_namespace)), Z_UNILEN_P(CG(current_namespace)), 0, &ns_name_len); + + if (Z_TYPE_P(CG(current_namespace)) == IS_UNICODE) { + ns_name.u = eurealloc(ns_name.u, ns_name_len + 2 + lcname_len + 1); + ns_name.u[ns_name_len] = ':'; + ns_name.u[ns_name_len+1] = ':'; + memcpy(ns_name.u + ns_name_len + 2, lcname.u, UBYTES(lcname_len + 1)); + } else { + ns_name.s = erealloc(ns_name.s, ns_name_len + 2 + lcname_len + 1); + ns_name.s[ns_name_len] = ':'; + ns_name.s[ns_name_len+1] = ':'; + 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)); + } + 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)); } |
