mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
T_IMPORT -> T_USE
This commit is contained in:
parent
38e93fe401
commit
b7d87bebc9
@ -39,8 +39,8 @@ Namespace or class name can be imported:
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
require 'Zend/Db/Connection.php';
|
require 'Zend/Db/Connection.php';
|
||||||
import Zend::DB;
|
use Zend::DB;
|
||||||
import Zend::DB::Connection as DbConnection;
|
use Zend::DB::Connection as DbConnection;
|
||||||
|
|
||||||
$x = new Zend::DB::Connection();
|
$x = new Zend::DB::Connection();
|
||||||
$y = new DB::connection();
|
$y = new DB::connection();
|
||||||
@ -48,13 +48,13 @@ $z = new DbConnection();
|
|||||||
DB::connect();
|
DB::connect();
|
||||||
?>
|
?>
|
||||||
|
|
||||||
import statement only defines name aliasing. It may create name alias for
|
The use statement only defines name aliasing. It may create name alias for
|
||||||
namespace or class. The simple form of statement "import A::B::C::D;" is
|
namespace or class. The simple form of statement "use A::B::C::D;" is
|
||||||
equivalent to "import A::B::C::D as D;". Import statement can be used at any
|
equivalent to "use A::B::C::D as D;". The use statement can be used at any
|
||||||
time in the global scope (not inside function/class) and takes effect from
|
time in the global scope (not inside function/class) and takes effect from
|
||||||
the point of definition down to the end of file. It is recommended however to
|
the point of definition down to the end of file. It is recommended however to
|
||||||
place imports at the beginning of the file. Import statements have effect
|
place the use statements at the beginning of the file. The use statements have
|
||||||
only on the file where they appear.
|
effect only on the file where they appear.
|
||||||
|
|
||||||
The special "empty" namespace (:: prefix) is useful as explicit global
|
The special "empty" namespace (:: prefix) is useful as explicit global
|
||||||
namespace qualification. All class and function names started from ::
|
namespace qualification. All class and function names started from ::
|
||||||
@ -83,10 +83,10 @@ In global namespace __NAMESPACE__ constant has the value of empty string.
|
|||||||
Names inside namespace are resolved according to the following rules:
|
Names inside namespace are resolved according to the following rules:
|
||||||
|
|
||||||
1) all qualified names are translated during compilation according to
|
1) all qualified names are translated during compilation according to
|
||||||
current import rules. So if we have "import A::B::C" and then "C::D::e()"
|
current import rules. So if we have "use A::B::C" and then "C::D::e()"
|
||||||
it is translated to "A::B::C::D::e()".
|
it is translated to "A::B::C::D::e()".
|
||||||
2) unqualified class names translated during compilation according to
|
2) unqualified class names translated during compilation according to
|
||||||
current import rules. So if we have "import A::B::C" and then "new C()" it
|
current import rules. So if we have "use A::B::C" and then "new C()" it
|
||||||
is translated to "new A::B::C()".
|
is translated to "new A::B::C()".
|
||||||
3) inside namespace, calls to unqualified functions that are defined in
|
3) inside namespace, calls to unqualified functions that are defined in
|
||||||
current namespace (and are known at the time the call is parsed) are
|
current namespace (and are known at the time the call is parsed) are
|
||||||
|
@ -5,8 +5,8 @@ Bug #42859 import always conflicts with internal classes
|
|||||||
namespace Foo;
|
namespace Foo;
|
||||||
class Ex {}
|
class Ex {}
|
||||||
|
|
||||||
import Blah::Exception;
|
use Blah::Exception;
|
||||||
import Blah::Ex;
|
use Blah::Ex;
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Fatal error: Import name 'Ex' conflicts with defined class in %sbug42859.php on line 6
|
Fatal error: Import name 'Ex' conflicts with defined class in %sbug42859.php on line 6
|
@ -10,9 +10,9 @@ class Foo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
import test::ns1::Foo as Bar;
|
use test::ns1::Foo as Bar;
|
||||||
import test::ns1 as ns2;
|
use test::ns1 as ns2;
|
||||||
import test::ns1;
|
use test::ns1;
|
||||||
|
|
||||||
Foo::bar();
|
Foo::bar();
|
||||||
test::ns1::Foo::bar();
|
test::ns1::Foo::bar();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
namespace X;
|
namespace X;
|
||||||
import X as Y;
|
use X as Y;
|
||||||
class Foo {
|
class Foo {
|
||||||
const C = "const ok\n";
|
const C = "const ok\n";
|
||||||
static $var = "var ok\n";
|
static $var = "var ok\n";
|
||||||
|
@ -8,8 +8,8 @@ function foo() {
|
|||||||
echo __FUNCTION__,"\n";
|
echo __FUNCTION__,"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
import test::ns1 as ns2;
|
use test::ns1 as ns2;
|
||||||
import test as ns3;
|
use test as ns3;
|
||||||
|
|
||||||
foo();
|
foo();
|
||||||
bar();
|
bar();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
namespace X;
|
namespace X;
|
||||||
import X as Y;
|
use X as Y;
|
||||||
function foo() {
|
function foo() {
|
||||||
echo __FUNCTION__,"\n";
|
echo __FUNCTION__,"\n";
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace a::b::c;
|
namespace a::b::c;
|
||||||
|
|
||||||
import a::b::c as test;
|
use a::b::c as test;
|
||||||
|
|
||||||
require "ns_022.inc";
|
require "ns_022.inc";
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
029: Name ambiguity (class name & import name)
|
029: Name ambiguity (class name & import name)
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
import A::B as Foo;
|
use A::B as Foo;
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
class Foo {
|
class Foo {
|
||||||
}
|
}
|
||||||
|
|
||||||
import A::B as Foo;
|
use A::B as Foo;
|
||||||
|
|
||||||
new Foo();
|
new Foo();
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
033: Import statement with non-compound name
|
033: Import statement with non-compound name
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
import A;
|
use A;
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Warning: The import statement with non-compound name 'A' has no effect in %sns_033.php on line 2
|
Warning: The use statement with non-compound name 'A' has no effect in %sns_033.php on line 2
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
namespace A;
|
namespace A;
|
||||||
import A as B;
|
use A as B;
|
||||||
class Foo {
|
class Foo {
|
||||||
const C = "ok\n";
|
const C = "ok\n";
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
namespace A;
|
namespace A;
|
||||||
import A as B;
|
use A as B;
|
||||||
class ArrayObject {
|
class ArrayObject {
|
||||||
const STD_PROP_LIST = 2;
|
const STD_PROP_LIST = 2;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
namespace X;
|
namespace X;
|
||||||
import X as Y;
|
use X as Y;
|
||||||
class X {
|
class X {
|
||||||
const C = "const ok\n";
|
const C = "const ok\n";
|
||||||
static $var = "var ok\n";
|
static $var = "var ok\n";
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
namespace X;
|
namespace X;
|
||||||
import X as Y;
|
use X as Y;
|
||||||
const A = "ok\n";
|
const A = "ok\n";
|
||||||
const B = A;
|
const B = A;
|
||||||
const C = array(A);
|
const C = array(A);
|
||||||
|
@ -6,8 +6,8 @@ namespace test::ns1;
|
|||||||
|
|
||||||
const FOO = "ok\n";
|
const FOO = "ok\n";
|
||||||
|
|
||||||
import test::ns1 as ns2;
|
use test::ns1 as ns2;
|
||||||
import test as ns3;
|
use test as ns3;
|
||||||
|
|
||||||
echo FOO;
|
echo FOO;
|
||||||
echo test::ns1::FOO;
|
echo test::ns1::FOO;
|
||||||
|
@ -4600,7 +4600,7 @@ void zend_do_namespace(znode *name TSRMLS_DC) /* {{{ */
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
void zend_do_import(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */
|
void zend_do_use(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */
|
||||||
{
|
{
|
||||||
char *lcname;
|
char *lcname;
|
||||||
zval *name, *ns, tmp;
|
zval *name, *ns, tmp;
|
||||||
@ -4618,7 +4618,7 @@ void zend_do_import(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */
|
|||||||
} else {
|
} else {
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
/* The form "import A::B" is eqivalent to "import A::B as B".
|
/* The form "use A::B" is eqivalent to "use A::B as B".
|
||||||
So we extract the last part of compound name ti use as a new_name */
|
So we extract the last part of compound name ti use as a new_name */
|
||||||
name = &tmp;
|
name = &tmp;
|
||||||
p = zend_memrchr(Z_STRVAL_P(ns), ':', Z_STRLEN_P(ns));
|
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) /* {{{ */
|
|||||||
zend_error(E_COMPILE_ERROR, "Cannot reuse import name");
|
zend_error(E_COMPILE_ERROR, "Cannot reuse import name");
|
||||||
}
|
}
|
||||||
if (warn) {
|
if (warn) {
|
||||||
zend_error(E_WARNING, "The import statement with non-compound name '%s' has no effect", Z_STRVAL_P(name));
|
zend_error(E_WARNING, "The use statement with non-compound name '%s' has no effect", Z_STRVAL_P(name));
|
||||||
}
|
}
|
||||||
efree(lcname);
|
efree(lcname);
|
||||||
zval_dtor(name);
|
zval_dtor(name);
|
||||||
|
@ -506,7 +506,7 @@ void zend_do_abstract_method(znode *function_name, znode *modifiers, znode *body
|
|||||||
void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC);
|
void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC);
|
||||||
void zend_do_build_namespace_name(znode *result, znode *prefix, znode *name TSRMLS_DC);
|
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_namespace(znode *name TSRMLS_DC);
|
||||||
void zend_do_import(znode *name, znode *new_name TSRMLS_DC);
|
void zend_do_use(znode *name, znode *new_name TSRMLS_DC);
|
||||||
void zend_do_end_compilation(TSRMLS_D);
|
void zend_do_end_compilation(TSRMLS_D);
|
||||||
|
|
||||||
ZEND_API void function_add_ref(zend_function *function);
|
ZEND_API void function_add_ref(zend_function *function);
|
||||||
|
@ -144,7 +144,6 @@
|
|||||||
%token T_CURLY_OPEN
|
%token T_CURLY_OPEN
|
||||||
%token T_PAAMAYIM_NEKUDOTAYIM
|
%token T_PAAMAYIM_NEKUDOTAYIM
|
||||||
%token T_NAMESPACE
|
%token T_NAMESPACE
|
||||||
%token T_IMPORT
|
|
||||||
%token T_NS_C
|
%token T_NS_C
|
||||||
|
|
||||||
%% /* Rules */
|
%% /* Rules */
|
||||||
@ -169,8 +168,8 @@ top_statement:
|
|||||||
| class_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_HALT_COMPILER '(' ')' ';' { zend_do_halt_compiler_register(TSRMLS_C); YYACCEPT; }
|
||||||
| T_NAMESPACE namespace_name ';' { zend_do_namespace(&$2 TSRMLS_CC); }
|
| T_NAMESPACE namespace_name ';' { zend_do_namespace(&$2 TSRMLS_CC); }
|
||||||
| T_IMPORT namespace_name ';' { zend_do_import(&$2, NULL TSRMLS_CC); }
|
| T_USE namespace_name ';' { zend_do_use(&$2, NULL TSRMLS_CC); }
|
||||||
| T_IMPORT namespace_name T_AS T_STRING ';' { zend_do_import(&$2, &$4 TSRMLS_CC); }
|
| T_USE namespace_name T_AS T_STRING ';' { zend_do_use(&$2, &$4 TSRMLS_CC); }
|
||||||
| constant_declaration ';'
|
| constant_declaration ';'
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -225,7 +224,6 @@ unticked_statement:
|
|||||||
| T_ECHO echo_expr_list ';'
|
| T_ECHO echo_expr_list ';'
|
||||||
| T_INLINE_HTML { zend_do_echo(&$1 TSRMLS_CC); }
|
| T_INLINE_HTML { zend_do_echo(&$1 TSRMLS_CC); }
|
||||||
| expr ';' { zend_do_free(&$1 TSRMLS_CC); }
|
| expr ';' { zend_do_free(&$1 TSRMLS_CC); }
|
||||||
| 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); }
|
|
||||||
| T_UNSET '(' unset_variables ')' ';'
|
| T_UNSET '(' unset_variables ')' ';'
|
||||||
| T_FOREACH '(' variable T_AS
|
| T_FOREACH '(' variable T_AS
|
||||||
{ zend_do_foreach_begin(&$1, &$2, &$3, &$4, 1 TSRMLS_CC); }
|
{ zend_do_foreach_begin(&$1, &$2, &$3, &$4, 1 TSRMLS_CC); }
|
||||||
@ -272,12 +270,6 @@ unset_variable:
|
|||||||
variable { zend_do_end_variable_parse(BP_VAR_UNSET, 0 TSRMLS_CC); zend_do_unset(&$1 TSRMLS_CC); }
|
variable { zend_do_end_variable_parse(BP_VAR_UNSET, 0 TSRMLS_CC); zend_do_unset(&$1 TSRMLS_CC); }
|
||||||
;
|
;
|
||||||
|
|
||||||
use_filename:
|
|
||||||
T_CONSTANT_ENCAPSED_STRING { $$ = $1; }
|
|
||||||
| '(' T_CONSTANT_ENCAPSED_STRING ')' { $$ = $2; }
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
function_declaration_statement:
|
function_declaration_statement:
|
||||||
unticked_function_declaration_statement { zend_do_ticks(TSRMLS_C); }
|
unticked_function_declaration_statement { zend_do_ticks(TSRMLS_C); }
|
||||||
;
|
;
|
||||||
|
@ -1202,10 +1202,6 @@ HEREDOC_CHARS ("{"*([^$\n\r\\{]|("\\"[^\n\r]))|{HEREDOC_LITERAL_DOLLAR}|({
|
|||||||
return T_NAMESPACE;
|
return T_NAMESPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
<ST_IN_SCRIPTING>"import" {
|
|
||||||
return T_IMPORT;
|
|
||||||
}
|
|
||||||
|
|
||||||
<ST_IN_SCRIPTING>"use" {
|
<ST_IN_SCRIPTING>"use" {
|
||||||
return T_USE;
|
return T_USE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user