svn: /phpdoc/en/trunk/ language/constants.xml reference/misc/functions/define.xml
| From: | Maciej Sobaczewski | Date: | Wed, 20 May 2015 14:57:54 +0000 |
| Subject: | svn: /phpdoc/en/trunk/ language/constants.xml reference/misc/functions/define.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-13318@lists.php.net to get a copy of this message | ||
sobak Wed, 20 May 2015 14:57:54 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=336809
Log:
Document PHP 7 possibility to define array constants using define()
Changed paths:
U phpdoc/en/trunk/language/constants.xml
U phpdoc/en/trunk/reference/misc/functions/define.xml
Modified: phpdoc/en/trunk/language/constants.xml
===================================================================
--- phpdoc/en/trunk/language/constants.xml 2015-05-20 14:18:21 UTC (rev 336808)
+++ phpdoc/en/trunk/language/constants.xml 2015-05-20 14:57:54 UTC (rev 336809)
@@ -133,10 +133,12 @@
</listitem>
<listitem>
<simpara>
- Constants may only evaluate to scalar values, or scalar or array values
- in PHP 5.6 and later. You may use arrays in constant scalar expressions
+ Constants may only evaluate to scalar values. As of PHP 5.6 it is possible
+ to define array constant using <literal>const</literal> keywords and as of
+ PHP 7 array constants can also be defined using <function>define</function>
+ You may use arrays in constant scalar expressions
(for example, <literal>const FOO = array(1,2,3)[0];</literal>),
- but the end result must be a scalar value.
+ but the end result must be a value of allowed type.
</simpara>
</listitem>
</itemizedlist>
@@ -170,8 +172,18 @@
// Works as of PHP 5.6.0
const ANOTHER_CONST = CONSTANT.'; Goodbye World';
+echo ANOTHER_CONST;
-echo ANOTHER_CONST;
+const ANIMALS = array('dog', 'cat', 'bird');
+echo ANIMALS[1]; // outputs "cat"
+
+// Works as of PHP 7
+define('ANIMALS', array(
+ 'dog',
+ 'cat',
+ 'bird'
+));
+echo ANIMALS[1]; // outputs "cat"
?>
]]>
</programlisting>
Modified: phpdoc/en/trunk/reference/misc/functions/define.xml
===================================================================
--- phpdoc/en/trunk/reference/misc/functions/define.xml 2015-05-20 14:18:21 UTC (rev 336808)
+++ phpdoc/en/trunk/reference/misc/functions/define.xml 2015-05-20 14:57:54 UTC (rev 336809)
@@ -35,7 +35,8 @@
<term><parameter>value</parameter></term>
<listitem>
<para>
- The value of the constant; only scalar and <type>null</type> values are allowed.
+ The value of the constant; only scalar and <type>null</type> values are allowed.
+ As of PHP 7 it also possible to use <type>array</type> value.
Scalar values are <type>integer</type>,
<type>float</type>, <type>string</type> or
<type>boolean</type> values. It is
possible to define <type>resource</type> constants, however it is not
recommended
@@ -70,6 +71,30 @@
</para>
</refsect1>
+ <refsect1 role="changelog">
+ &reftitle.changelog;
+ <para>
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>7.0.0</entry>
+ <entry>
+ <type>array</type> values are allowed.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ </refsect1>
+
<refsect1 role="examples">
&reftitle.examples;
<para>
@@ -86,6 +111,14 @@
echo GREETING; // outputs "Hello you."
echo Greeting; // outputs "Hello you."
+// Works as of PHP 7
+define('ANIMALS', array(
+ 'dog',
+ 'cat',
+ 'bird'
+));
+echo ANIMALS[1]; // outputs "cat"
+
?>
]]>
</programlisting>