From 4c514c4b8947e94d4fc6ae5d7c79ca4ea14e65c3 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Tue, 8 Mar 2011 17:07:49 +0000 Subject: [PATCH] Namespaces importing (thanks to Jan Tvrdik) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@309025 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/namespaces.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/language/namespaces.xml b/language/namespaces.xml index 17009d022a..611e480229 100644 --- a/language/namespaces.xml +++ b/language/namespaces.xml @@ -592,7 +592,8 @@ $b = namespace\CONSTANT; // assigns value of constant CONSTANT to $b PHP namespaces support - two kinds of aliasing or importing: aliasing a class name, and aliasing a namespace name. + three kinds of aliasing or importing: aliasing a class name, aliasing an interface name, + and aliasing a namespace name. Note that importing a function or constant is not supported. @@ -610,13 +611,13 @@ use My\Full\Classname as Another; use My\Full\NSname; // importing a global class -use \ArrayObject; +use ArrayObject; $obj = new namespace\Another; // instantiates object of class foo\Another $obj = new Another; // instantiates object of class My\Full\Classname NSname\subns\func(); // calls function My\Full\NSname\subns\func $a = new ArrayObject(array(1)); // instantiates object of class ArrayObject -// without the "use \ArrayObject" we would instantiate an object of class foo\ArrayObject +// without the "use ArrayObject" we would instantiate an object of class foo\ArrayObject ?> ]]> @@ -624,7 +625,7 @@ $a = new ArrayObject(array(1)); // instantiates object of class ArrayObject Note that for namespaced names (fully qualified namespace names containing namespace separator, such as Foo\Bar as opposed to global names that do not, such as FooBar), the leading backslash is unnecessary and not - allowed, as import names + recommended, as import names must be fully qualified, and are not processed relative to the current namespace.