svn: /phpdoc/en/trunk/language/ functions.xml
| From: | Thomas Punt | Date: | Sat, 19 Dec 2015 20:00:23 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/ functions.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-13922@lists.php.net to get a copy of this message | ||
tpunt Sat, 19 Dec 2015 20:00:23 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=338328
Log:
Resolve doc bug #71167
Bug: https://bugs.php.net/71167 (Assigned) Missing
documentation, that type declaration doesn't support aliases
Changed paths:
U phpdoc/en/trunk/language/functions.xml
Modified: phpdoc/en/trunk/language/functions.xml
===================================================================
--- phpdoc/en/trunk/language/functions.xml 2015-12-19 12:56:11 UTC (rev 338327)
+++ phpdoc/en/trunk/language/functions.xml 2015-12-19 20:00:23 UTC (rev 338328)
@@ -366,8 +366,8 @@
</note>
<para>
- Type declarations allow functions to require that parameters are of a
- certain type at call time. If the given value is of the incorrect type,
+ Type declarations allow functions to specify parameters as certain types.
+ If the given value is of the incorrect type,
then an error is generated: in PHP 5, this will be a recoverable fatal
error, while PHP 7 will throw a <classname>TypeError</classname>
exception.
@@ -453,6 +453,35 @@
</tbody>
</tgroup>
</informaltable>
+
+ <warning>
+ <para>
+ Aliases for the above scalar types are not supported. Instead, they are
+ treated as class or interface names. For example, using
+ <literal>boolean</literal> as a parameter or return type will require
+ an argument or return value that is an &instanceof; the class or
+ interface <literal>boolean</literal>, rather than of type
+ <type>bool</type>:
+ </para>
+ <para>
+ <example>
+ <programlisting role="php">
+ <![CDATA[
+ <?php
+ function test(boolean $param) {}
+ test(true);
+ ?>
+ ]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+ <![CDATA[
+ Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of boolean,
boolean given, called in - on line 1 and defined in -:1
+ ]]>
+ </screen>
+ </example>
+ </para>
+ </warning>
</sect3>
<sect3 xml:id="functions.arguments.type-declaration.examples">