mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
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:
parent
18da52a535
commit
add41695ca
1 changed files with 23 additions and 0 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue