[prev in list] [next in list] [prev in thread] [next in thread]
List: phpdoc
Subject: [PHP-DOC] Contributions are ready for review
From: phpdoc () lists ! php ! net
Date: 2015-07-27 12:00:03
Message-ID: 201507271200.t6RC03gn005192 () pb11 ! pair ! com
[Download RAW message or body]
Hello PHP EN Documentation team,
There are contributions within the online editor queue for this language.
Please review, then commit or delete these patches.
Patches for review :
-----------------------
Modified: en/internals2/opcodes/add-interface.xml
By: Gennady Kovshenin on 2015-03-15 18:27:32
===================================================================
--- en/internals2/opcodes/add-interface.xml
+++ en/internals2/opcodes/add-interface.xml
@@ -8,11 +8,64 @@
<![CDATA[
<?php
/*
- *
+ * adds an implemented interface to a class declaration
* opcode number: 144
- * No sample PHP yet */
+ */
+interface iA {
+}
+
+class A implements iA {
+}
?>
]]>
</programlisting>
</section>
+ <section xml:id="internals2.opcodes.add-interface.listing">
+ <title>PHP opcodes</title>
+ <simpara>Function name: (null)</simpara>
+ <simpara>Compiled variables: none</simpara>
+ <informaltable>
+ <tgroup cols="7">
+ <thead>
+ <row>
+ <entry>line</entry><entry>#</entry><entry>op</entry>
+ <entry>fetch</entry><entry>ext</entry><entry>return</entry>
+ <entry>operands</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>6</entry><entry>0</entry>
+ <entry>NOP</entry><entry></entry>
+ <entry></entry><entry></entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry></entry><entry>1</entry>
+ <entry>DECLARE_CLASS</entry><entry></entry>
+ <entry></entry><entry></entry>
+ <entry>'a'</entry>
+ </row>
+ <row>
+ <entry></entry><entry>2</entry>
+ <entry>ADD_INTERFACE</entry><entry></entry>
+ <entry></entry><entry></entry>
+ <entry>'iA'</entry>
+ </row>
+ <row>
+ <entry></entry><entry>3</entry>
+ <entry>VERIFY_ABSTRACT_CLASS</entry><entry></entry>
+ <entry></entry><entry></entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry></entry><entry>3</entry>
+ <entry>RETURN</entry><entry></entry>
+ <entry></entry><entry></entry>
+ <entry>1</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </section>
</section>
No newline at end of file
=> Put this change into your patches : \
https://edit.php.net/?project=php&action=putIntoMyPatches&idDB=60576
=> Delete this change: \
https://edit.php.net/?project=php&action=deleteThisChange&idDB=60576
\
------------------------------------------------------------------
Modified: en/internals2/opcodes/add-char.xml
By: Gennady Kovshenin on 2015-03-15 18:29:44
===================================================================
--- en/internals2/opcodes/add-char.xml
+++ en/internals2/opcodes/add-char.xml
@@ -8,10 +8,10 @@
<![CDATA[
<?php
/*
- * add character value2 to string value1 and store in result
+ * add regular characters in encapsed string
* opcode number: 54
*/
-echo "hello world";
+echo "$a ";
?>
]]>
</programlisting>
@@ -19,7 +19,7 @@
<section xml:id="internals2.opcodes.add-char.listing">
<title>PHP opcodes</title>
<simpara>Function name: (null)</simpara>
- <simpara>Compiled variables: none </simpara>
+ <simpara>Compiled variables: !0=$a</simpara>
<informaltable>
<tgroup cols="7">
<thead>
@@ -32,12 +32,24 @@
<tbody>
<row>
<entry>6</entry><entry>0</entry>
+ <entry>ADD_VAR</entry><entry></entry>
+ <entry></entry><entry></entry>
+ <entry>!0</entry>
+ </row>
+ <row>
+ <entry></entry><entry>1</entry>
+ <entry>ADD_CHAR</entry><entry></entry>
+ <entry></entry><entry></entry>
+ <entry>32</entry>
+ </row>
+ <row>
+ <entry></entry><entry>2</entry>
<entry>ECHO</entry><entry></entry>
<entry></entry><entry></entry>
- <entry>'hello%5C+world'</entry>
+ <entry> </entry>
</row>
<row>
- <entry>7</entry><entry>1</entry>
+ <entry></entry><entry>3</entry>
<entry>RETURN</entry><entry></entry>
<entry></entry><entry></entry>
<entry>1</entry>
=> Put this change into your patches : \
https://edit.php.net/?project=php&action=putIntoMyPatches&idDB=60575
=> Delete this change: \
https://edit.php.net/?project=php&action=deleteThisChange&idDB=60575
\
------------------------------------------------------------------
Modified: en/internals2/opcodes/cast.xml
By: Gennady Kovshenin on 2015-03-15 18:46:59
===================================================================
--- en/internals2/opcodes/cast.xml
+++ en/internals2/opcodes/cast.xml
@@ -8,7 +8,7 @@
<![CDATA[
<?php
/*
- * casts value1 as type value2 (?? Not certain about arguments ??)
+ * casts value1 as type value2 (type in extended_value)
* opcode number: 21
*/
echo (int)1;
@@ -39,7 +39,7 @@
<row>
<entry></entry><entry>1</entry>
<entry>ECHO</entry><entry></entry>
- <entry></entry><entry></entry>
+ <entry></entry><entry>1</entry>
<entry>~0</entry>
</row>
<row>
=> Put this change into your patches : \
https://edit.php.net/?project=php&action=putIntoMyPatches&idDB=60577
=> Delete this change: \
https://edit.php.net/?project=php&action=deleteThisChange&idDB=60577
\
------------------------------------------------------------------
Modified: en/language/predefined/closure/call.xml
By: mail@akirakoyasu.net on 2015-06-23 07:03:03
===================================================================
--- en/language/predefined/closure/call.xml
+++ en/language/predefined/closure/call.xml
@@ -11,7 +11,8 @@
<methodsynopsis>
<modifier>public</modifier> \
<type>Closure</type><methodname>Closure::call</methodname> \
<methodparam><type>object</type><parameter>to</parameter></methodparam>
- <methodparam choice="opt"><type>mixed</type><parameter>parameters</parameter></methodparam>
+ <methodparam choice="opt"><type>mixed</type><parameter>parameter</parameter></methodparam>
+ <methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
</methodsynopsis>
<para>
Calls the closure with the given parameters and returns the result, with $this \
bound to the given object @@ -29,7 +30,7 @@
</listitem>
</varlistentry>
<varlistentry>
- <term><parameter>parameters</parameter></term>
+ <term><parameter>args</parameter></term>
<listitem>
<para>
</para>
=> Put this change into your patches : \
https://edit.php.net/?project=php&action=putIntoMyPatches&idDB=63267
=> Delete this change: \
https://edit.php.net/?project=php&action=deleteThisChange&idDB=63267
\
------------------------------------------------------------------
Modified: en/reference/imap/functions/imap-fetchstructure.xml
By: Krzysiek Ĺukasiak on 2015-06-24 05:21:58
===================================================================
--- en/reference/imap/functions/imap-fetchstructure.xml
+++ en/reference/imap/functions/imap-fetchstructure.xml
@@ -140,32 +140,38 @@
</para>
<para>
<table>
- <title>Primary body type (may vary with used library)</title>
- <tgroup cols="2">
- <tbody>
- <row><entry>0</entry><entry>text</entry></row>
- <row><entry>1</entry><entry>multipart</entry></row>
- <row><entry>2</entry><entry>message</entry></row>
- <row><entry>3</entry><entry>application</entry></row>
- <row><entry>4</entry><entry>audio</entry></row>
- <row><entry>5</entry><entry>image</entry></row>
- <row><entry>6</entry><entry>video</entry></row>
- <row><entry>7</entry><entry>other</entry></row>
- </tbody>
- </tgroup>
+ <title>Primary body type (value may vary with used library, use of constants is \
recommended)</title> + <tgroup cols="3">
+ <thead>
+ <row><entry>Value</entry><entry>Type</entry><entry>Constant</entry></row>
+ </thead>
+ <tbody>
+ <row><entry>0</entry><entry>text</entry><entry>TYPETEXT</entry></row>
+ <row><entry>1</entry><entry>multipart</entry><entry>TYPEMULTIPART</entry></row>
+ <row><entry>2</entry><entry>message</entry><entry>TYPEMESSAGE</entry></row>
+ <row><entry>3</entry><entry>application</entry><entry>TYPEAPPLICATION</entry></row>
+ <row><entry>4</entry><entry>audio</entry><entry>TYPEAUDIO</entry></row>
+ <row><entry>5</entry><entry>image</entry><entry>TYPEIMAGE</entry></row>
+ <row><entry>6</entry><entry>video</entry><entry>TYPEVIDEO</entry></row>
+ <row><entry>7</entry><entry>other</entry><entry>TYPEOTHER</entry></row>
+ </tbody>
+ </tgroup>
</table>
</para>
<para>
<table>
- <title>Transfer encodings (may vary with used library)</title>
- <tgroup cols="2">
- <tbody>
- <row><entry>0</entry><entry>7BIT</entry></row>
- <row><entry>1</entry><entry>8BIT</entry></row>
- <row><entry>2</entry><entry>BINARY</entry></row>
- <row><entry>3</entry><entry>BASE64</entry></row>
- <row><entry>4</entry><entry>QUOTED-PRINTABLE</entry></row>
- <row><entry>5</entry><entry>OTHER</entry></row>
+ <title>Transfer encodings (value may vary with used library, use of constants is \
recommended)</title> + <tgroup cols="3">
+ <thead>
+ <row><entry>Value</entry><entry>Type</entry><entry>Constant</entry></row>
+ </thead>
+ <tbody>
+ <row><entry>0</entry><entry>7bit</entry><entry>ENC7BIT</entry></row>
+ <row><entry>1</entry><entry>8bit</entry><entry>ENC8BIT</entry></row>
+ <row><entry>2</entry><entry>Binary</entry><entry>ENCBINARY</entry></row>
+ <row><entry>3</entry><entry>Base64</entry><entry>ENCBASE64</entry></row>
+ <row><entry>4</entry><entry>Quoted-Printable</entry><entry>ENCQUOTEDPRINTABLE</entry></row>
+ <row><entry>5</entry><entry>other</entry><entry>ENCOTHER</entry></row>
</tbody>
</tgroup>
</table>
=> Put this change into your patches : \
https://edit.php.net/?project=php&action=putIntoMyPatches&idDB=63305
=> Delete this change: \
https://edit.php.net/?project=php&action=deleteThisChange&idDB=63305
\
------------------------------------------------------------------
Modified: en/reference/soap/functions/use-soap-error-handler.xml
By: Tomasz Sawicki on 2015-06-25 02:46:41
===================================================================
--- en/reference/soap/functions/use-soap-error-handler.xml
+++ en/reference/soap/functions/use-soap-error-handler.xml
@@ -19,7 +19,7 @@
in a <classname>SoapServer</classname> application will be sent to the client
as a SOAP fault message.
If &false;, the standard PHP error handler is used.
- The default is to use the standard PHP error handler.
+ The default is to send error to the client as SOAP fault message.
</para>
</refsect1>
=> Put this change into your patches : \
https://edit.php.net/?project=php&action=putIntoMyPatches&idDB=63350
=> Delete this change: \
https://edit.php.net/?project=php&action=deleteThisChange&idDB=63350
\
------------------------------------------------------------------
Modified: en/reference/reflection/reflectionproperty/isdefault.xml
By: James Titcumb on 2015-07-10 04:24:50
===================================================================
--- en/reference/reflection/reflectionproperty/isdefault.xml
+++ en/reference/reflection/reflectionproperty/isdefault.xml
@@ -14,7 +14,8 @@
<void />
</methodsynopsis>
<para>
- Checks whether the property is the default.
+ Checks whether the property was declared at compile-time, or whether the
+ property was dynamically declared at run-time.
</para>
</refsect1>
=> Put this change into your patches : \
https://edit.php.net/?project=php&action=putIntoMyPatches&idDB=63571
=> Delete this change: \
https://edit.php.net/?project=php&action=deleteThisChange&idDB=63571
\
------------------------------------------------------------------
Modified: en/reference/strings/functions/strspn.xml
By: francois on 2015-07-22 05:00:11
===================================================================
--- en/reference/strings/functions/strspn.xml
+++ en/reference/strings/functions/strspn.xml
@@ -125,6 +125,13 @@
Returns the length of the initial segment of <parameter>subject</parameter>
which consists entirely of characters in <parameter>mask</parameter>.
</para>
+ <note>
+ <para>
+ When a <parameter>start</parameter> parameter is set, the returned length
+ is counted starting from this position, not from the beginning of
+ <parameter>subject</parameter>.
+ </para>
+ </note>
</refsect1>
<refsect1 role="examples">
=> Put this change into your patches : \
https://edit.php.net/?project=php&action=putIntoMyPatches&idDB=63792
=> Delete this change: \
https://edit.php.net/?project=php&action=deleteThisChange&idDB=63792
\
------------------------------------------------------------------
Modified: en/reference/strings/functions/strcspn.xml
By: francois on 2015-07-22 05:02:24
===================================================================
--- en/reference/strings/functions/strcspn.xml
+++ en/reference/strings/functions/strcspn.xml
@@ -10,35 +10,43 @@
&reftitle.description;
<methodsynopsis>
<type>int</type><methodname>strcspn</methodname>
- <methodparam><type>string</type><parameter>str1</parameter></methodparam>
- <methodparam><type>string</type><parameter>str2</parameter></methodparam>
+ <methodparam><type>string</type><parameter>subject</parameter></methodparam>
+ <methodparam><type>string</type><parameter>mask</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>start</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam>
</methodsynopsis>
<para>
Returns the length of the initial segment of
- <parameter>str1</parameter> which does <emphasis>not</emphasis>
- contain any of the characters in <parameter>str2</parameter>.
+ <parameter>subject</parameter> which does <emphasis>not</emphasis>
+ contain any of the characters in <parameter>mask</parameter>.
+ </para>
+ <para>
+ If <parameter>start</parameter> and <parameter>length</parameter>
+ are omitted, then all of <parameter>subject</parameter> will be
+ examined. If they are included, then the effect will be the same as
+ calling <literal>strcspn(substr($subject, $start, $length),
+ $mask)</literal> (see <xref linkend="function.substr" />
+ for more information).
</para>
</refsect1>
-
+
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
- <term><parameter>str1</parameter></term>
+ <term><parameter>subject</parameter></term>
<listitem>
<para>
- The first string.
+ The string to examine.
</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><parameter>str2</parameter></term>
+ <term><parameter>mask</parameter></term>
<listitem>
<para>
- The second string.
+ The string containing every disallowed character.
</para>
</listitem>
</varlistentry>
@@ -46,7 +54,25 @@
<term><parameter>start</parameter></term>
<listitem>
<para>
- The start position of the string to examine.
+ The position in <parameter>subject</parameter> to
+ start searching.
+ </para>
+ <para>
+ If <parameter>start</parameter> is given and is non-negative,
+ then <function>strcspn</function> will begin
+ examining <parameter>subject</parameter> at
+ the <parameter>start</parameter>'th position. For instance, in
+ the string '<literal>abcdef</literal>', the character at
+ position <literal>0</literal> is '<literal>a</literal>', the
+ character at position <literal>2</literal> is
+ '<literal>c</literal>', and so forth.
+ </para>
+ <para>
+ If <parameter>start</parameter> is given and is negative,
+ then <function>strspn</function> will begin
+ examining <parameter>subject</parameter> at
+ the <parameter>start</parameter>'th position from the end
+ of <parameter>subject</parameter>.
</para>
</listitem>
</varlistentry>
@@ -54,21 +80,42 @@
<term><parameter>length</parameter></term>
<listitem>
<para>
- The length of the string to examine.
+ The length of the segment from <parameter>subject</parameter>
+ to examine.
+ </para>
+ <para>
+ If <parameter>length</parameter> is given and is non-negative,
+ then <parameter>subject</parameter> will be examined
+ for <parameter>length</parameter> characters after the starting
+ position.
+ </para>
+ <para>
+ If <parameter>length</parameter> is given and is negative,
+ then <parameter>subject</parameter> will be examined from the
+ starting position up to <parameter>length</parameter>
+ characters from the end of <parameter>subject</parameter>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
-
+
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
- Returns the length of the segment as an integer.
+ Returns the length of the initial segment of <parameter>subject</parameter>
+ which consists entirely of characters <emphasis>not</emphasis> in \
<parameter>mask</parameter>. </para>
+ <note>
+ <para>
+ When a <parameter>start</parameter> parameter is set, the returned length
+ is counted starting from this position, not from the beginning of
+ <parameter>subject</parameter>.
+ </para>
+ </note>
</refsect1>
-
+
<refsect1 role="examples">
&reftitle.examples;
<example xml:id="strcspn.example">
@@ -80,11 +127,15 @@
$b = strcspn('abcd', 'banana');
$c = strcspn('hello', 'l');
$d = strcspn('hello', 'world');
+$e = strcspn('abcdhelloabcd', 'abcd', -9);
+$f = strcspn('abcdhelloabcd', 'abcd', -9, -5);
var_dump($a);
var_dump($b);
var_dump($c);
var_dump($d);
+var_dump($e);
+var_dump($f);
?>
]]>
</programlisting>
@@ -95,16 +146,18 @@
int(0)
int(2)
int(2)
+int(5)
+int(4)
]]>
</screen>
</example>
</refsect1>
-
+
<refsect1 role="notes">
&reftitle.notes;
¬e.bin-safe;
</refsect1>
-
+
<refsect1 role="seealso">
&reftitle.seealso;
<para>
@@ -113,7 +166,7 @@
</simplelist>
</para>
</refsect1>
-
+
</refentry>
<!-- Keep this comment at the end of the file
=> Put this change into your patches : \
https://edit.php.net/?project=php&action=putIntoMyPatches&idDB=63793
=> Delete this change: \
https://edit.php.net/?project=php&action=deleteThisChange&idDB=63793
\
------------------------------------------------------------------
Modified: en/language/functions.xml
By: anonymous on 2015-07-24 17:30:58
===================================================================
--- en/language/functions.xml
+++ en/language/functions.xml
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 337189 $ -->
- <chapter xml:id="language.functions" xmlns="http://docbook.org/ns/docbook">
- <title>Functions</title>
-
- <sect1 xml:id="functions.user-defined">
- <title>User-defined functions</title>
+<chapter xml:id="language.functions" xmlns="http://docbook.org/ns/docbook">
+ <title>Functions</title>
- <para>
- A function may be defined using syntax such as the following:
- </para>
- <para>
- <example>
- <title>Pseudo code to demonstrate function uses</title>
- <programlisting role="php">
+ <sect1 xml:id="functions.user-defined">
+ <title>User-defined functions</title>
+
+ <para>
+ A function may be defined using syntax such as the following:
+ </para>
+ <para>
+ <example>
+ <title>Pseudo code to demonstrate function uses</title>
+ <programlisting role="php">
<![CDATA[
<?php
function foo($arg_1, $arg_2, /* ..., */ $arg_n)
@@ -22,37 +22,37 @@
}
?>
]]>
- </programlisting>
- </example>
- </para>
-
- <simpara>
- Any valid PHP code may appear inside a function, even other
- functions and <link linkend="keyword.class">class</link>
- definitions.
- </simpara>
- <para>
- Function names follow the same rules as other labels in PHP. A
- valid function name starts with a letter or underscore, followed
- by any number of letters, numbers, or underscores. As a regular
- expression, it would be expressed thus:
- <literal>[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*</literal>.
- </para>
- &tip.userlandnaming;
- <simpara>
- Functions need not be defined before they are referenced,
- <emphasis>except</emphasis> when a function is conditionally defined as
- shown in the two examples below.
- </simpara>
- <para>
- When a function is defined in a conditional manner such as the two
- examples shown. Its definition must be processed <emphasis>prior</emphasis>
- to being called.
- </para>
- <para>
- <example>
- <title>Conditional functions</title>
- <programlisting role="php">
+ </programlisting>
+ </example>
+ </para>
+
+ <simpara>
+ Any valid PHP code may appear inside a function, even other
+ functions and <link linkend="keyword.class">class</link>
+ definitions.
+ </simpara>
+ <para>
+ Function names follow the same rules as other labels in PHP. A
+ valid function name starts with a letter or underscore, followed
+ by any number of letters, numbers, or underscores. As a regular
+ expression, it would be expressed thus:
+ <literal>[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*</literal>.
+ </para>
+ &tip.userlandnaming;
+ <simpara>
+ Functions need not be defined before they are referenced,
+ <emphasis>except</emphasis> when a function is conditionally defined as
+ shown in the two examples below.
+ </simpara>
+ <para>
+ When a function is defined in a conditional manner such as the two
+ examples shown. Its definition must be processed <emphasis>prior</emphasis>
+ to being called.
+ </para>
+ <para>
+ <example>
+ <title>Conditional functions</title>
+ <programlisting role="php">
<![CDATA[
<?php
@@ -158,54 +158,54 @@
]]>
</programlisting>
</example>
- <note>
- <simpara>
- Recursive function/method calls with over 100-200 recursion levels can
- smash the stack and cause a termination of the current script. Especially,
- infinite recursion is considered a programming error.
- </simpara>
- </note>
+ <note>
+ <simpara>
+ Recursive function/method calls with over 100-200 recursion levels can
+ smash the stack and cause a termination of the current script. Especially,
+ infinite recursion is considered a programming error.
+ </simpara>
+ </note>
</para>
-
+
</sect1>
-
+
<sect1 xml:id="functions.arguments">
<title>Function arguments</title>
-
+
<simpara>
Information may be passed to functions via the argument list,
which is a comma-delimited list of expressions. The arguments are
evaluated from left to right.
</simpara>
<para>
- <informaltable>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>&Version;</entry>
- <entry>&Description;</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>5.1.0</entry>
- <entry>classes,interfaces and arrays type declaration</entry>
- </row>
- <row>
- <entry>5.4.0</entry>
- <entry><type>callable</type> type declaration</entry>
- </row>
- <row>
- <entry>7.0.0</entry>
- <entry>scalar (<type>int</type>,
- <type>float</type>,
- <type>string</type>,
- <type>bool</type>) type declaration</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
- </para>
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>5.1.0</entry>
+ <entry>classes,interfaces and arrays type declaration</entry>
+ </row>
+ <row>
+ <entry>5.4.0</entry>
+ <entry><type>callable</type> type declaration</entry>
+ </row>
+ <row>
+ <entry>7.0.0</entry>
+ <entry>scalar (<type>int</type>,
+ <type>float</type>,
+ <type>string</type>,
+ <type>bool</type>) type declaration</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
<para>
PHP supports passing arguments by value (the default), <link
linkend="functions.arguments.by-reference">passing by
@@ -231,7 +231,7 @@
</para>
<sect2 xml:id="functions.arguments.by-reference">
<title>Making arguments be passed by reference</title>
-
+
<simpara>
By default, function arguments are passed by value (so that if
the value of the argument within the function is changed, it does
@@ -263,7 +263,7 @@
</sect2>
<sect2 xml:id="functions.arguments.default">
<title>Default argument values</title>
-
+
<para>
A function may define C++-style default values for scalar
arguments as follows:
@@ -315,7 +315,7 @@
]]>
</programlisting>
</example>
-
+
</para>
<simpara>
The default value must be a constant expression, not (for
@@ -384,28 +384,30 @@
</note>
</sect2>
<sect2 xml:id="functions.scalar-type-declaration">
- <title>Scalar Type Declaration</title>
+ <title>Scalar Type Hints</title>
<para>
- <note>
- <para>
- Type declaration is also known as Type Hinting.
- </para>
- </note>
- PHP 7 introduces scalar type declaration. Functions are now able to force \
parameters
- to be <type>string</type>, <type>int</type>, <type>float</type> or \
<type>bool</type>.
- By default all PHP Files are in weakly typed mode.
- To enable strict type checking, <link \
linkend="control-structures.declare">declare(strict_types=1)</link>
- directive must be the first
- statement in the file. strict_types has two options, 1 for strict type
- checking and 0 for weak type checking. This only affects the file this is \
stated in and not
- files either included in this file or other files that include this file.
- Whether or not the function being called was declared in a file that uses \
strict or weak
- type checking is irrelevant. The type checking mode depends on the file where \
the function is called from. + Starting with PHP 7, a function can specify a \
scalar type name as a type hint + in addition to class names, interface names, \
<type>array</type>, and + <type>callable</type>. The supported scalar type hints \
are <type>string</type>, + <type>int</type>, <type>float</type> and \
<type>bool</type>. + </para>
+ <para>
+ The handling of function scalar type hints depends on the per-file
+ strict_types directive. If this directive is set to 0 or not specified,
+ PHP will attempt to convert the supplied argument value to the type specified
+ by the type hint if they do not match. If this directive is set to 1,
+ a type mismatch will cause a TypeError to be thrown.
+ </para>
+ <para>
+ A type hinted value will always be of the specified type within the function,
+ irrespective of the strict_types setting. An integer value will always be \
accepted + for an argument with a <type>float</type> type hint, though the \
reverse will not + happen.
</para>
<para>
<example>
- <title>Scalar Type Declaration examples</title>
- <programlisting role="php">
+ <title>Scalar Type Hint Examples</title>
+ <programlisting role="php">
<![CDATA[
<?php
declare(strict_types=1); // Fatal error if this is not the first statement
@@ -424,8 +426,8 @@
}
]]>
- </programlisting>
- <programlisting role="php">
+ </programlisting>
+ <programlisting role="php">
<![CDATA[
<?php
declare(strict_types=1); // file 1
@@ -457,8 +459,8 @@
?>
]]>
- </programlisting>
- <programlisting role="php">
+ </programlisting>
+ <programlisting role="php">
<![CDATA[
<?php // file 1
@@ -494,13 +496,13 @@
</programlisting>
</example>
</para>
-
-
+
+
<sect3>
- <para>
- <example>
- <title>Type Widening</title>
- <programlisting role="php">
+ <para>
+ <example>
+ <title>Type Widening</title>
+ <programlisting role="php">
<![CDATA[
<?php
declare(strict_types=1);
@@ -514,16 +516,16 @@
a($a);
]]>
- </programlisting>
- </example>
- </para>
+ </programlisting>
+ </example>
+ </para>
</sect3>
<sect3 xml:id="functions.scalar-type-declaration-error">
<title>Type Error</title>
<para>Absences of a &try; &catch; block will result in a \
<constant>E_ERROR</constant></para>
- <example>
- <title>Type Error with try catch</title>
- <programlisting role="php">
+ <example>
+ <title>Type Error with try catch</title>
+ <programlisting role="php">
<![CDATA[
<?php
declare(strict_types=1);
@@ -545,8 +547,8 @@
}
?>
]]>
- </programlisting>
- <programlisting role="php">
+ </programlisting>
+ <programlisting role="php">
<![CDATA[
<?php
declare(strict_types=1);
@@ -560,13 +562,13 @@
?>
]]>
- </programlisting>
- </example>
+ </programlisting>
+ </example>
</sect3>
</sect2>
<sect2 xml:id="functions.variable-arg-list">
<title>Variable-length argument lists</title>
-
+
<simpara>
PHP has support for variable-length argument lists in
user-defined functions. This is implemented using the
@@ -575,16 +577,16 @@
<function>func_get_arg</function>, and
<function>func_get_args</function> functions in PHP 5.5 and earlier.
</simpara>
-
+
<sect3 xml:id="functions.variable-arg-list.new">
<title><literal>...</literal> in PHP 5.6+</title>
-
+
<para>
In PHP 5.6 and later, argument lists may include the
<literal>...</literal> token to denote that the function accepts a
variable number of arguments. The arguments will be passed into the
given variable as an array; for example:
-
+
<example>
<title>Using <literal>...</literal> to access variable arguments</title>
<programlisting role="php">
@@ -610,12 +612,12 @@
</screen>
</example>
</para>
-
+
<para>
You can also use <literal>...</literal> when calling functions to unpack
an <type>array</type> or <classname>Traversable</classname> variable or
literal into the argument list:
-
+
<example>
<title>Using <literal>...</literal> to provide arguments</title>
<programlisting role="php">
@@ -641,20 +643,20 @@
</screen>
</example>
</para>
-
+
<para>
You may specify normal positional arguments before the
<literal>...</literal> token. In this case, only the trailing arguments
that don't match a positional argument will be added to the array
generated by <literal>...</literal>.
</para>
-
+
<para>
It is also possible to add a
<link linkend="language.oop5.typehinting">type hint</link> before the
<literal>...</literal> token. If this is present, then all arguments
captured by <literal>...</literal> must be objects of the hinted class.
-
+
<example>
<title>Type hinted variable arguments</title>
<programlisting role="php">
@@ -686,7 +688,7 @@
</screen>
</example>
</para>
-
+
<para>
Finally, you may also pass variable arguments
<link linkend="functions.arguments.by-reference">by reference</link> by
@@ -694,21 +696,21 @@
(<literal>&</literal>).
</para>
</sect3>
-
+
<sect3 xml:id="functions.variable-arg-list.old">
<title>Older versions of PHP</title>
-
+
<para>
No special syntax is required to note that a function is variadic;
however access to the function's arguments must use
<function>func_num_args</function>, <function>func_get_arg</function>
and <function>func_get_args</function>.
</para>
-
+
<para>
The first example above would be implemented as follows in PHP 5.5 and
earlier:
-
+
<example>
<title>Accessing variable arguments in PHP 5.5 and earlier</title>
<programlisting role="php">
@@ -735,14 +737,14 @@
</example>
</para>
</sect3>
-
+
</sect2>
-
+
</sect1>
-
+
<sect1 xml:id="functions.returning-values">
<title>Returning values</title>
-
+
<para>
Values are returned by using the optional return statement. Any
type may be returned, including arrays and objects. This causes the
@@ -762,7 +764,7 @@
<tbody>
<row>
<entry>7.0.0</entry>
- <entry>Added Return Type Declarations</entry>
+ <entry>Added return type hints</entry>
</row>
</tbody>
</tgroup>
@@ -776,10 +778,10 @@
</note>
<sect2>
<title>Use of return</title>
- <para>
- <example>
- <title>Use of <function>return</function></title>
- <programlisting role="php">
+ <para>
+ <example>
+ <title>Use of <function>return</function></title>
+ <programlisting role="php">
<![CDATA[
<?php
function square($num)
@@ -789,18 +791,18 @@
echo square(4); // outputs '16'.
?>
]]>
- </programlisting>
- </example>
- </para>
-
- <para>
- A function can not return multiple values, but similar results can be
- obtained by returning an array.
- </para>
- <para>
- <example>
- <title>Returning an array to get multiple values</title>
- <programlisting role="php">
+ </programlisting>
+ </example>
+ </para>
+
+ <para>
+ A function can not return multiple values, but similar results can be
+ obtained by returning an array.
+ </para>
+ <para>
+ <example>
+ <title>Returning an array to get multiple values</title>
+ <programlisting role="php">
<![CDATA[
<?php
function small_numbers()
@@ -810,18 +812,18 @@
list ($zero, $one, $two) = small_numbers();
?>
]]>
- </programlisting>
- </example>
- </para>
- <para>
- To return a reference from a function, use the reference operator & in
- both the function declaration and when assigning the returned value to a
- variable:
- </para>
- <para>
- <example>
- <title>Returning a reference from a function</title>
- <programlisting role="php">
+ </programlisting>
+ </example>
+ </para>
+ <para>
+ To return a reference from a function, use the reference operator & in
+ both the function declaration and when assigning the returned value to a
+ variable:
+ </para>
+ <para>
+ <example>
+ <title>Returning a reference from a function</title>
+ <programlisting role="php">
<![CDATA[
<?php
function &returns_reference()
@@ -832,29 +834,42 @@
$newref =& returns_reference();
?>
]]>
- </programlisting>
- </example>
- </para>
- <simpara>
- For more information on references, please check out <link
- linkend="language.references">References Explained</link>.
- </simpara>
- </sect2>
- <sect2>
- <title>Return Type Declarations</title>
- <para>
- PHP 7 Introduces Return type declaration where function can be forced to \
return
- type that is defined. This is done by setting
- <link linkend="control-structures.declare">declare(strict_types=1)</link>, if \
declare strict_type directive
- is set to 0 or not set functions are weakly type checked. The directive will \
have affect on all functions
- delcared in the file and not functions either included by this file or files \
that includes this file, are
- affected. The place where the function is called from is irrelavent.
- Declarable types are Classes, Interfaces, Array, Int, Float, String and Bool.
- </para>
- <para>
- <example>
- <title>Affect of strict_types directive </title>
- <programlisting role="php">
+ </programlisting>
+ </example>
+ </para>
+ <simpara>
+ For more information on references, please check out <link
+ linkend="language.references">References Explained</link>.
+ </simpara>
+ </sect2>
+ <sect2>
+ <title>Return Type Hints</title>
+ <para>
+ Starting with PHP 7, a function can specify the type of value that
+ it returns. This is achieved by adding a colon (:) followed by the
+ type name after the closing parenthesis of the function declaration.
+ </para>
+ <para>
+ Valid values for a return type hint are class names, interface names,
+ <type>array</type>, and the scalar types <type>string</type>,
+ <type>int</type>, <type>float</type> and <type>bool</type>.
+ </para>
+ <para>
+ The handling of function return types depends on the per-file
+ strict_types directive. If this directive is set to 0 or not specified,
+ PHP will attempt to convert the returned value to the type specified by
+ the return type hint if they do not match. If this directive is set to 1,
+ a type mismatch will cause a TypeError to be thrown.
+ </para>
+ <para>
+ Return types that are specified on an object's method must match those
+ specified on the parent method. However, if the parent class does not
+ specify a return type, a child class may introduce a return type hint.
+ </para>
+ <para>
+ <example>
+ <title>The strict_types directive</title>
+ <programlisting role="php">
<![CDATA[
<?php
declare(strict_types=1); // file1.php
@@ -882,17 +897,13 @@
?>
]]>
- </programlisting>
- </example>
- </para>
- <para>
- <example>
- <title>More Return types</title>
- <para>
- The function signature must match of the parent, if the parent has not been \
declared the
- return type the child can declare a type.
- </para>
- <programlisting role="php">
+ </programlisting>
+ </example>
+ </para>
+ <para>
+ <example>
+ <title>More Return Types</title>
+ <programlisting role="php">
<![CDATA[
<?php
declare(strict_types=1);
@@ -934,11 +945,11 @@
]]>
</programlisting>
</example>
- </para>
- <para>
- <example>
- <title>Return a class</title>
- <programlisting role="php">
+ </para>
+ <para>
+ <example>
+ <title>Return a class</title>
+ <programlisting role="php">
<![CDATA[
<?php
declare(strict_types=1);
@@ -954,10 +965,10 @@
]]>
</programlisting>
</example>
- </para>
+ </para>
<para>
<example>
- <title>TypeError</title>
+ <title>TypeError</title>
<para>Incorrect return type will result in a TypeError</para>
<programlisting role="php">
<![CDATA[
@@ -965,11 +976,11 @@
declare(strict_types=1);
function show(): int{
- return "1";
+ return "1";
}
try {
- show();
+ show();
} catch (TypeError $e) {
var_dump($e->getMessage()); // string(121) "Return value of show() must be of the \
type integer, // string returned in %s on line 5"
@@ -981,10 +992,10 @@
</para>
</sect2>
</sect1>
-
+
<sect1 xml:id="functions.variable-functions">
<title>Variable functions</title>
-
+
<para>
PHP supports the concept of variable functions. This means that if
a variable name has parentheses appended to it, PHP will look for
@@ -1089,11 +1100,11 @@
</programlisting>
</example>
</para>
-
+
<para>
See also <function>is_callable</function>, <function>call_user_func</function>,
<link linkend="language.variables.variable">
- variable variables</link> and <function>function_exists</function>.
+ variable variables</link> and <function>function_exists</function>.
</para>
</sect1>
@@ -1152,14 +1163,14 @@
<sect1 xml:id="functions.anonymous">
<title>Anonymous functions</title>
-
+
<simpara>
Anonymous functions, also known as <literal>closures</literal>, allow the
creation of functions which have no specified name. They are most useful as
the value of <link linkend="language.types.callback">callback</link>
parameters, but they have many other uses.
</simpara>
-
+
<example>
<title>Anonymous function example</title>
<programlisting role="php">
@@ -1173,7 +1184,7 @@
]]>
</programlisting>
</example>
-
+
<simpara>
Closures can also be used as the values of variables; PHP automatically
converts such expressions into instances of the
@@ -1181,7 +1192,7 @@
variable uses the same syntax as any other assignment, including the
trailing semicolon:
</simpara>
-
+
<example>
<title>Anonymous function variable assignment example</title>
<programlisting role="php">
@@ -1203,7 +1214,7 @@
Closures may also inherit variables from the parent scope.
Any such variables must be passed to the <literal>use</literal> language \
construct. </simpara>
-
+
<example>
<title>Inheriting variables from the parent scope</title>
<programlisting role="php">
@@ -1263,7 +1274,7 @@
]]>
</screen>
</example>
-
+
<simpara>
Inheriting variables from the parent scope is <emphasis>not</emphasis>
the same as using global variables.
@@ -1272,7 +1283,7 @@
function in which the closure was declared (not necessarily the function it
was called from). See the following example:
</simpara>
-
+
<example>
<title>Closures and scoping</title>
<programlisting role="php">
@@ -1367,7 +1378,7 @@
</informaltable>
</para>
</sect2>
-
+
<sect2 role="notes">
&reftitle.notes;
<note>
@@ -1378,11 +1389,11 @@
</simpara>
</note>
</sect2>
-
+
</sect1>
+
+</chapter>
- </chapter>
-
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
=> Put this change into your patches : \
https://edit.php.net/?project=php&action=putIntoMyPatches&idDB=63827
=> Delete this change: \
https://edit.php.net/?project=php&action=deleteThisChange&idDB=63827
\
------------------------------------------------------------------
--
https://edit.php.net/
This email is send automatically by the Php Docbook Online Editor.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic