Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

T_IMPORT -> T_USE

  • Loading branch information...
commit b7d87bebc93e9937ed46f6762eed4a20c4e5b8d6 1 parent 38e93fe
Dmitry Stogov authored
18 README.namespaces
@@ -39,8 +39,8 @@ Namespace or class name can be imported:
39 39
40 40 <?php
41 41 require 'Zend/Db/Connection.php';
42   -import Zend::DB;
43   -import Zend::DB::Connection as DbConnection;
  42 +use Zend::DB;
  43 +use Zend::DB::Connection as DbConnection;
44 44
45 45 $x = new Zend::DB::Connection();
46 46 $y = new DB::connection();
@@ -48,13 +48,13 @@ $z = new DbConnection();
48 48 DB::connect();
49 49 ?>
50 50
51   -import statement only defines name aliasing. It may create name alias for
52   -namespace or class. The simple form of statement "import A::B::C::D;" is
53   -equivalent to "import A::B::C::D as D;". Import statement can be used at any
  51 +The use statement only defines name aliasing. It may create name alias for
  52 +namespace or class. The simple form of statement "use A::B::C::D;" is
  53 +equivalent to "use A::B::C::D as D;". The use statement can be used at any
54 54 time in the global scope (not inside function/class) and takes effect from
55 55 the point of definition down to the end of file. It is recommended however to
56   -place imports at the beginning of the file. Import statements have effect
57   -only on the file where they appear.
  56 +place the use statements at the beginning of the file. The use statements have
  57 +effect only on the file where they appear.
58 58
59 59 The special "empty" namespace (:: prefix) is useful as explicit global
60 60 namespace qualification. All class and function names started from ::
@@ -83,10 +83,10 @@ In global namespace __NAMESPACE__ constant has the value of empty string.
83 83 Names inside namespace are resolved according to the following rules:
84 84
85 85 1) all qualified names are translated during compilation according to
86   -current import rules. So if we have "import A::B::C" and then "C::D::e()"
  86 +current import rules. So if we have "use A::B::C" and then "C::D::e()"
87 87 it is translated to "A::B::C::D::e()".
88 88 2) unqualified class names translated during compilation according to
89   -current import rules. So if we have "import A::B::C" and then "new C()" it
  89 +current import rules. So if we have "use A::B::C" and then "new C()" it
90 90 is translated to "new A::B::C()".
91 91 3) inside namespace, calls to unqualified functions that are defined in
92 92 current namespace (and are known at the time the call is parsed) are
4 Zend/tests/bug42859.phpt
@@ -5,8 +5,8 @@ Bug #42859 import always conflicts with internal classes
5 5 namespace Foo;
6 6 class Ex {}
7 7
8   -import Blah::Exception;
9   -import Blah::Ex;
  8 +use Blah::Exception;
  9 +use Blah::Ex;
10 10 ?>
11 11 --EXPECTF--
12 12 Fatal error: Import name 'Ex' conflicts with defined class in %sbug42859.php on line 6
6 Zend/tests/ns_002.phpt
@@ -10,9 +10,9 @@ class Foo {
10 10 }
11 11 }
12 12
13   -import test::ns1::Foo as Bar;
14   -import test::ns1 as ns2;
15   -import test::ns1;
  13 +use test::ns1::Foo as Bar;
  14 +use test::ns1 as ns2;
  15 +use test::ns1;
16 16
17 17 Foo::bar();
18 18 test::ns1::Foo::bar();
2  Zend/tests/ns_010.phpt
@@ -3,7 +3,7 @@
3 3 --FILE--
4 4 <?php
5 5 namespace X;
6   -import X as Y;
  6 +use X as Y;
7 7 class Foo {
8 8 const C = "const ok\n";
9 9 static $var = "var ok\n";
4 Zend/tests/ns_012.phpt
@@ -8,8 +8,8 @@ function foo() {
8 8 echo __FUNCTION__,"\n";
9 9 }
10 10
11   -import test::ns1 as ns2;
12   -import test as ns3;
  11 +use test::ns1 as ns2;
  12 +use test as ns3;
13 13
14 14 foo();
15 15 bar();
2  Zend/tests/ns_020.phpt
@@ -3,7 +3,7 @@
3 3 --FILE--
4 4 <?php
5 5 namespace X;
6   -import X as Y;
  6 +use X as Y;
7 7 function foo() {
8 8 echo __FUNCTION__,"\n";
9 9 }
2  Zend/tests/ns_022.phpt
@@ -4,7 +4,7 @@
4 4 <?php
5 5 namespace a::b::c;
6 6
7   -import a::b::c as test;
  7 +use a::b::c as test;
8 8
9 9 require "ns_022.inc";
10 10
2  Zend/tests/ns_029.phpt
@@ -2,7 +2,7 @@
2 2 029: Name ambiguity (class name & import name)
3 3 --FILE--
4 4 <?php
5   -import A::B as Foo;
  5 +use A::B as Foo;
6 6
7 7 class Foo {
8 8 }
2  Zend/tests/ns_030.phpt
@@ -5,7 +5,7 @@
5 5 class Foo {
6 6 }
7 7
8   -import A::B as Foo;
  8 +use A::B as Foo;
9 9
10 10 new Foo();
11 11 --EXPECTF--
4 Zend/tests/ns_033.phpt
@@ -2,7 +2,7 @@
2 2 033: Import statement with non-compound name
3 3 --FILE--
4 4 <?php
5   -import A;
  5 +use A;
6 6 --EXPECTF--
7   -Warning: The import statement with non-compound name 'A' has no effect in %sns_033.php on line 2
  7 +Warning: The use statement with non-compound name 'A' has no effect in %sns_033.php on line 2
8 8
2  Zend/tests/ns_034.phpt
@@ -3,7 +3,7 @@
3 3 --FILE--
4 4 <?php
5 5 namespace A;
6   -import A as B;
  6 +use A as B;
7 7 class Foo {
8 8 const C = "ok\n";
9 9 }
2  Zend/tests/ns_036.phpt
@@ -5,7 +5,7 @@
5 5 --FILE--
6 6 <?php
7 7 namespace A;
8   -import A as B;
  8 +use A as B;
9 9 class ArrayObject {
10 10 const STD_PROP_LIST = 2;
11 11 }
2  Zend/tests/ns_037.phpt
@@ -3,7 +3,7 @@
3 3 --FILE--
4 4 <?php
5 5 namespace X;
6   -import X as Y;
  6 +use X as Y;
7 7 class X {
8 8 const C = "const ok\n";
9 9 static $var = "var ok\n";
2  Zend/tests/ns_040.phpt
@@ -3,7 +3,7 @@
3 3 --FILE--
4 4 <?php
5 5 namespace X;
6   -import X as Y;
  6 +use X as Y;
7 7 const A = "ok\n";
8 8 const B = A;
9 9 const C = array(A);
4 Zend/tests/ns_042.phpt
@@ -6,8 +6,8 @@ namespace test::ns1;
6 6
7 7 const FOO = "ok\n";
8 8
9   -import test::ns1 as ns2;
10   -import test as ns3;
  9 +use test::ns1 as ns2;
  10 +use test as ns3;
11 11
12 12 echo FOO;
13 13 echo test::ns1::FOO;
6 Zend/zend_compile.c
@@ -4600,7 +4600,7 @@ void zend_do_namespace(znode *name TSRMLS_DC) /* {{{ */
4600 4600 }
4601 4601 /* }}} */
4602 4602
4603   -void zend_do_import(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */
  4603 +void zend_do_use(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */
4604 4604 {
4605 4605 char *lcname;
4606 4606 zval *name, *ns, tmp;
@@ -4618,7 +4618,7 @@ void zend_do_import(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */
4618 4618 } else {
4619 4619 char *p;
4620 4620
4621   - /* The form "import A::B" is eqivalent to "import A::B as B".
  4621 + /* The form "use A::B" is eqivalent to "use A::B as B".
4622 4622 So we extract the last part of compound name ti use as a new_name */
4623 4623 name = &tmp;
4624 4624 p = zend_memrchr(Z_STRVAL_P(ns), ':', Z_STRLEN_P(ns));
@@ -4660,7 +4660,7 @@ void zend_do_import(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */
4660 4660 zend_error(E_COMPILE_ERROR, "Cannot reuse import name");
4661 4661 }
4662 4662 if (warn) {
4663   - zend_error(E_WARNING, "The import statement with non-compound name '%s' has no effect", Z_STRVAL_P(name));
  4663 + zend_error(E_WARNING, "The use statement with non-compound name '%s' has no effect", Z_STRVAL_P(name));
4664 4664 }
4665 4665 efree(lcname);
4666 4666 zval_dtor(name);
2  Zend/zend_compile.h
@@ -506,7 +506,7 @@ void zend_do_abstract_method(znode *function_name, znode *modifiers, znode *body
506 506 void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC);
507 507 void zend_do_build_namespace_name(znode *result, znode *prefix, znode *name TSRMLS_DC);
508 508 void zend_do_namespace(znode *name TSRMLS_DC);
509   -void zend_do_import(znode *name, znode *new_name TSRMLS_DC);
  509 +void zend_do_use(znode *name, znode *new_name TSRMLS_DC);
510 510 void zend_do_end_compilation(TSRMLS_D);
511 511
512 512 ZEND_API void function_add_ref(zend_function *function);
12 Zend/zend_language_parser.y
@@ -144,7 +144,6 @@
144 144 %token T_CURLY_OPEN
145 145 %token T_PAAMAYIM_NEKUDOTAYIM
146 146 %token T_NAMESPACE
147   -%token T_IMPORT
148 147 %token T_NS_C
149 148
150 149 %% /* Rules */
@@ -169,8 +168,8 @@ top_statement:
169 168 | class_declaration_statement { zend_do_early_binding(TSRMLS_C); }
170 169 | T_HALT_COMPILER '(' ')' ';' { zend_do_halt_compiler_register(TSRMLS_C); YYACCEPT; }
171 170 | T_NAMESPACE namespace_name ';' { zend_do_namespace(&$2 TSRMLS_CC); }
172   - | T_IMPORT namespace_name ';' { zend_do_import(&$2, NULL TSRMLS_CC); }
173   - | T_IMPORT namespace_name T_AS T_STRING ';' { zend_do_import(&$2, &$4 TSRMLS_CC); }
  171 + | T_USE namespace_name ';' { zend_do_use(&$2, NULL TSRMLS_CC); }
  172 + | T_USE namespace_name T_AS T_STRING ';' { zend_do_use(&$2, &$4 TSRMLS_CC); }
174 173 | constant_declaration ';'
175 174 ;
176 175
@@ -225,7 +224,6 @@ unticked_statement:
225 224 | T_ECHO echo_expr_list ';'
226 225 | T_INLINE_HTML { zend_do_echo(&$1 TSRMLS_CC); }
227 226 | expr ';' { zend_do_free(&$1 TSRMLS_CC); }
228   - | T_USE use_filename ';' { zend_error(E_COMPILE_ERROR,"use: Not yet supported. Please use include_once() or require_once()"); zval_dtor(&$2.u.constant); }
229 227 | T_UNSET '(' unset_variables ')' ';'
230 228 | T_FOREACH '(' variable T_AS
231 229 { zend_do_foreach_begin(&$1, &$2, &$3, &$4, 1 TSRMLS_CC); }
@@ -272,12 +270,6 @@ unset_variable:
272 270 variable { zend_do_end_variable_parse(BP_VAR_UNSET, 0 TSRMLS_CC); zend_do_unset(&$1 TSRMLS_CC); }
273 271 ;
274 272
275   -use_filename:
276   - T_CONSTANT_ENCAPSED_STRING { $$ = $1; }
277   - | '(' T_CONSTANT_ENCAPSED_STRING ')' { $$ = $2; }
278   -;
279   -
280   -
281 273 function_declaration_statement:
282 274 unticked_function_declaration_statement { zend_do_ticks(TSRMLS_C); }
283 275 ;
4 Zend/zend_language_scanner.l
@@ -1202,10 +1202,6 @@ HEREDOC_CHARS ("{"*([^$\n\r\\{]|("\\"[^\n\r]))|{HEREDOC_LITERAL_DOLLAR}|({
1202 1202 return T_NAMESPACE;
1203 1203 }
1204 1204
1205   -<ST_IN_SCRIPTING>"import" {
1206   - return T_IMPORT;
1207   -}
1208   -
1209 1205 <ST_IN_SCRIPTING>"use" {
1210 1206 return T_USE;
1211 1207 }

0 comments on commit b7d87be

Please sign in to comment.
Something went wrong with that request. Please try again.