Document nullable return types

Based on a patch provided by Massimo Naccari.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@346044 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Christoph Michael Becker 2018-11-26 12:32:50 +00:00
parent 18da52a535
commit add41695ca

View file

@ -1014,6 +1014,12 @@ $newref =& returns_reference();
correct type, otherwise a <classname>TypeError</classname> will be thrown.
</para>
<para>
As of PHP 7.1.0, return values can be marked as nullable by prefixing the
type name with a question mark (<literal>?</literal>). This signifies that
the function returns either the specified type or &null;.
</para>
<note>
<para>
When overriding a parent method, the child's method must match any return
@ -1100,6 +1106,23 @@ object(C)#1 (0) {
]]>
</screen>
</example>
<example>
<title>Nullable return type declaration (as of PHP 7.1.0)</title>
<programlisting role="php">
<![CDATA[
<?php
function get_item(): ?string {
if (isset($_GET['item'])) {
return $_GET['item'];
} else {
return null;
}
}
?>
]]>
</programlisting>
</example>
</sect3>
</sect2>
</sect1>