Namespaces importing (thanks to Jan Tvrdik)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@309025 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Jakub Vrana 2011-03-08 17:07:49 +00:00
parent 4b7f1ad3b9
commit 4c514c4b89

View file

@ -592,7 +592,8 @@ $b = namespace\CONSTANT; // assigns value of constant CONSTANT to $b
</para>
<para>
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.
</para>
<para>
@ -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
?>
]]>
</programlisting>
@ -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 <literal>Foo\Bar</literal> as opposed to global names that
do not, such as <literal>FooBar</literal>), 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.
</para>
<para>