mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Added Intial Return TypeError Doc & fix typo
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@337189 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
0ac74a54b9
commit
635e2ad129
1 changed files with 25 additions and 1 deletions
|
@ -937,7 +937,7 @@ var_dump($dis->two());
|
|||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Return a class;</title>
|
||||
<title>Return a class</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
@ -955,6 +955,30 @@ class B implements A {
|
|||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>TypeError</title>
|
||||
<para>Incorrect return type will result in a TypeError</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
function show(): int{
|
||||
return "1";
|
||||
}
|
||||
|
||||
try {
|
||||
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"
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
</sect2>
|
||||
</sect1>
|
||||
|
||||
|
|
Loading…
Reference in a new issue