svn: /phpdoc/en/trunk/language/ namespaces.xml
| From: | Adam Harvey | Date: | Sun, 01 Jun 2014 22:48:50 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/ namespaces.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-12515@lists.php.net to get a copy of this message | ||
aharvey Sun, 01 Jun 2014 22:48:50 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=333680
Log:
Document use function/const.
Changed paths:
U phpdoc/en/trunk/language/namespaces.xml
Modified: phpdoc/en/trunk/language/namespaces.xml
===================================================================
--- phpdoc/en/trunk/language/namespaces.xml 2014-06-01 22:43:11 UTC (rev 333679)
+++ phpdoc/en/trunk/language/namespaces.xml 2014-06-01 22:48:50 UTC (rev 333680)
@@ -603,14 +603,14 @@
ability of unix-based filesystems to create symbolic links to a file or to a directory.
</para>
<para>
- PHP namespaces support
- 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.
+ All versions of PHP that support namespaces support three kinds of aliasing
+ or importing: aliasing a class name, aliasing an interface name, and
+ aliasing a namespace name. PHP 5.6+ also allows aliasing or importing
+ function and constant names.
</para>
<para>
In PHP, aliasing is accomplished with the <literal>use</literal> operator. Here
- is an example showing all 3 kinds of importing:
+ is an example showing all 5 kinds of importing:
<example>
<title>importing/aliasing with the use operator</title>
<programlisting role="php">
@@ -625,11 +625,22 @@
// importing a global class
use ArrayObject;
+// importing a function (PHP 5.6+)
+use function My\Full\functionName;
+
+// aliasing a function (PHP 5.6+)
+use function My\Full\functionName as func;
+
+// importing a constant (PHP 5.6+)
+use const My\Full\CONSTANT;
+
$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
+func(); // calls function My\Full\functionName
+echo CONSTANT; // echoes the value of My\Full\CONSTANT
?>
]]>
</programlisting>