? halt_compiler_php6.patch.txt ? namespace.patch.txt ? namespace_brackets_unsetimport.patch.txt ? namespace_smartimport.patch.txt Index: Zend/zend_compile.c =================================================================== RCS file: /repository/ZendEngine2/zend_compile.c,v retrieving revision 1.762 diff -u -r1.762 zend_compile.c --- Zend/zend_compile.c 20 Aug 2007 09:48:41 -0000 1.762 +++ Zend/zend_compile.c 22 Aug 2007 02:15:54 -0000 @@ -166,6 +166,7 @@ CG(labels) = NULL; CG(current_namespace) = NULL; CG(current_import) = NULL; + CG(saved_import) = NULL; } /* }}} */ @@ -3192,7 +3193,7 @@ /* 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' coflicts with import name", Z_TYPE(class_name->u.constant), Z_UNIVAL(class_name->u.constant)); + zend_error(E_COMPILE_ERROR, "Class name '%R' conflicts with import name", Z_TYPE(class_name->u.constant), Z_UNIVAL(class_name->u.constant)); } if (CG(current_namespace)) { @@ -4971,11 +4972,8 @@ unsigned int lcname_len; zstr lcname; - if (CG(active_op_array)->last > 0) { - zend_error(E_COMPILE_ERROR, "Namespace declaration statement has to be the very first statement in the script"); - } if (CG(current_namespace)) { - zend_error(E_COMPILE_ERROR, "Namespace cannot be declared twice"); + zend_error(E_COMPILE_ERROR, "Namespace '%R' cannot be nested (already within '%R' namespace)", Z_TYPE(name->u.constant), Z_UNIVAL(name->u.constant), Z_TYPE_P(CG(current_namespace)), Z_UNIVAL_P(CG(current_namespace))); } lcname = zend_u_str_case_fold(Z_TYPE(name->u.constant), Z_UNIVAL(name->u.constant), Z_UNILEN(name->u.constant), 0, &lcname_len); if (((lcname_len == sizeof("self")-1) && @@ -4991,6 +4989,33 @@ } /* }}} */ +void zend_do_end_namespace(TSRMLS_D) /* {{{ */ +{ + if (CG(current_namespace)) { + zval_dtor(CG(current_namespace)); + efree(CG(current_namespace)); + CG(current_namespace) = NULL; + } + if (CG(saved_import)) { + if (CG(current_import)) { + zend_hash_destroy(CG(current_import)); + efree(CG(current_import)); + CG(current_import) = NULL; + } + CG(current_import) = CG(saved_import); + CG(saved_import) = NULL; + } +} +/* }}} */ + +/* within a namespace, do not use the global import list */ +void zend_do_local_import(TSRMLS_D) /* {{{ */ +{ + CG(saved_import) = CG(current_import); + CG(current_import) = NULL; +} +/* }}} */ + void zend_do_import(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */ { unsigned int lcname_len; @@ -5042,7 +5067,7 @@ } if (zend_u_hash_exists(CG(class_table), Z_TYPE_P(name), lcname, lcname_len+1)) { - zend_error(E_COMPILE_ERROR, "Import name '%R' coflicts with defined class", Z_TYPE_P(name), Z_UNIVAL_P(name)); + zend_error(E_COMPILE_ERROR, "Import name '%R' conflicts with defined class", Z_TYPE_P(name), Z_UNIVAL_P(name)); } if (zend_u_hash_add(CG(current_import), Z_TYPE_P(name), lcname, lcname_len+1, &ns, sizeof(zval*), NULL) != SUCCESS) { @@ -5068,6 +5093,11 @@ efree(CG(current_import)); CG(current_import) = NULL; } + if (CG(saved_import)) { + zend_hash_destroy(CG(saved_import)); + efree(CG(saved_import)); + CG(saved_import) = NULL; + } } /* }}} */ Index: Zend/zend_compile.h =================================================================== RCS file: /repository/ZendEngine2/zend_compile.h,v retrieving revision 1.363 diff -u -r1.363 zend_compile.h --- Zend/zend_compile.h 20 Aug 2007 09:48:41 -0000 1.363 +++ Zend/zend_compile.h 22 Aug 2007 02:15:55 -0000 @@ -521,6 +521,8 @@ void zend_do_build_namespace_name(znode *result, znode *prefix, znode *name TSRMLS_DC); void zend_do_namespace(znode *name TSRMLS_DC); +void zend_do_end_namespace(TSRMLS_D); +void zend_do_local_import(TSRMLS_D); void zend_do_import(znode *name, znode *new_name TSRMLS_DC); void zend_do_end_compilation(TSRMLS_D); Index: Zend/zend_globals.h =================================================================== RCS file: /repository/ZendEngine2/zend_globals.h,v retrieving revision 1.168 diff -u -r1.168 zend_globals.h --- Zend/zend_globals.h 12 Jul 2007 09:23:48 -0000 1.168 +++ Zend/zend_globals.h 22 Aug 2007 02:15:55 -0000 @@ -140,6 +140,7 @@ zval *current_namespace; HashTable *current_import; + HashTable *saved_import; #ifdef ZTS HashTable **static_members; Index: Zend/zend_language_parser.y =================================================================== RCS file: /repository/ZendEngine2/zend_language_parser.y,v retrieving revision 1.188 diff -u -r1.188 zend_language_parser.y --- Zend/zend_language_parser.y 20 Aug 2007 09:48:41 -0000 1.188 +++ Zend/zend_language_parser.y 22 Aug 2007 02:15:56 -0000 @@ -171,11 +171,15 @@ | function_declaration_statement { zend_do_early_binding(TSRMLS_C); } | class_declaration_statement { zend_do_early_binding(TSRMLS_C); } | T_HALT_COMPILER '(' ')' ';' { zend_do_halt_compiler_register(TSRMLS_C); YYACCEPT; } - | T_NAMESPACE namespace_name ';' { zend_do_namespace(&$2 TSRMLS_CC); } + | T_NAMESPACE namespace_name unimport '{' { zend_do_namespace(&$2 TSRMLS_CC);} top_statement_list '}' { zend_do_end_namespace(TSRMLS_C); } + | T_NAMESPACE namespace_name '{' { zend_do_namespace(&$2 TSRMLS_CC);} top_statement_list '}' { zend_do_end_namespace(TSRMLS_C); } | T_IMPORT namespace_name ';' { zend_do_import(&$2, NULL TSRMLS_CC); } | T_IMPORT namespace_name T_AS T_STRING ';' { zend_do_import(&$2, &$4 TSRMLS_CC); } ; +unimport: + T_UNSET T_IMPORT { zend_do_local_import(TSRMLS_C); } +; inner_statement_list: inner_statement_list { zend_do_extended_info(TSRMLS_C); } inner_statement { HANDLE_INTERACTIVE(); } Index: Zend/tests/ns_001.phpt =================================================================== RCS file: /repository/ZendEngine2/tests/ns_001.phpt,v retrieving revision 1.1 diff -u -r1.1 ns_001.phpt --- Zend/tests/ns_001.phpt 12 Jul 2007 09:23:48 -0000 1.1 +++ Zend/tests/ns_001.phpt 22 Aug 2007 02:15:56 -0000 @@ -2,7 +2,7 @@ 001: Class in namespace --FILE-- bar(); test::ns1::Foo::baz(); +} --EXPECT-- test::ns1::Foo test::ns1::Foo Index: Zend/tests/ns_002.phpt =================================================================== RCS file: /repository/ZendEngine2/tests/ns_002.phpt,v retrieving revision 1.1 diff -u -r1.1 ns_002.phpt --- Zend/tests/ns_002.phpt 12 Jul 2007 09:23:48 -0000 1.1 +++ Zend/tests/ns_002.phpt 22 Aug 2007 02:15:56 -0000 @@ -2,7 +2,7 @@ 002: Import in namespace --FILE--