Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

非推奨となった関数の引数のnullable型について #154

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions language/functions.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 74976cdb263ef841c5fc2c3f91ca7e284adce552 Maintainer: takagi Status: ready -->
<!-- CREDITS: hirokawa,mumumu -->
<!-- EN-Revision: 489d46bc2598784bd3711454ccab8940107cde67 Maintainer: takagi Status: ready -->
<!-- CREDITS: hirokawa,mumumu,jdkfx -->
<chapter xml:id="language.functions" xmlns="http://docbook.org/ns/docbook">
<title>関数</title>

Expand Down Expand Up @@ -456,10 +456,9 @@ Making a bowl of raspberry natural yogurt.
<code>Type $param = null</code> と書かれた引数です。
&null; をデフォルトにすることは、
型が暗黙のうちに nullable であることを示しています。
この書き方はまだ許可されていますが、
以下のようにして 明示的に
この使い方はPHP 8.4.0で非推奨となり、代わりに明示的な
<link linkend="language.types.declarations.nullable">nullable 型</link>
を使うことを推奨します:
を使用する必要があります。
<example>
<title>デフォルト値を指定した引数は、必須の引数の後に宣言する</title>
<programlisting role="php">
Expand All @@ -468,7 +467,9 @@ Making a bowl of raspberry natural yogurt.
function foo($a = [], $b) {} // デフォルト値が使われないため、PHP 8.0.0 以降は推奨されません
function foo($a, $b) {} // 上のコードと機能的には同じですが、推奨されない警告は発生しません。

function bar(A $a = null, $b) {} // まだ許可されています。$a は必須ですが、nullable です。
// PHP 8.1.0以降、$a は暗黙的に必須(必須の引数の前にあるため)ですが、
// デフォルトのパラメータ値が null であるため、暗黙的に nullable とみなされます(PHP 8.4.0で非推奨)。
function bar(A $a = null, $b) {}
function bar(?A $a, $b) {} // 推奨される書き方です。
?>
]]>
Expand Down