-
Notifications
You must be signed in to change notification settings - Fork 81
[PHP 8.5] Closure::getCurrent の翻訳を追加 #328
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- $Revision$ --> | ||
| <!-- EN-Revision: 31e56c25f90ebedf9aa4aa4877fbc859e1e0529c Maintainer: mumumu Status: ready --> | ||
| <refentry xml:id="closure.getcurrent" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
| <refnamediv> | ||
| <refname>Closure::getCurrent</refname> | ||
| <refpurpose>現在実行中のクロージャを返す</refpurpose> | ||
| </refnamediv> | ||
|
|
||
| <refsect1 role="description"> | ||
| &reftitle.description; | ||
| <methodsynopsis role="Closure"> | ||
| <modifier>public</modifier> <modifier>static</modifier> <type>Closure</type><methodname>Closure::getCurrent</methodname> | ||
| <void/> | ||
| </methodsynopsis> | ||
| <para> | ||
| 現在実行中のクロージャを返します。このメソッドは主に、 | ||
| <literal>use</literal> キーワードを使ってクロージャ変数への参照をキャプチャすることなく、 | ||
| 再帰的なクロージャを実装するのに役立ちます。 | ||
| </para> | ||
| <para> | ||
| このメソッドはクロージャの内部から呼び出す必要があります。 | ||
| クロージャのコンテキスト外から呼び出すと、 | ||
| <literal>Error: Current function is not a closure.</literal> が発生します。 | ||
| </para> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="parameters"> | ||
| &reftitle.parameters; | ||
| &no.function.parameters; | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="returnvalues"> | ||
| &reftitle.returnvalues; | ||
| <para> | ||
| 現在実行中の <classname>Closure</classname> インスタンスを返します。 | ||
| </para> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="errors"> | ||
| &reftitle.errors; | ||
| <para> | ||
| クロージャのコンテキスト外から呼び出された場合、 | ||
| <classname>Error</classname> をスローします。 | ||
| </para> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="examples"> | ||
| &reftitle.examples; | ||
| <example xml:id="closure.getcurrent.example.basic"> | ||
| <title><methodname>Closure::getCurrent</methodname> の例</title> | ||
| <para> | ||
| <methodname>Closure::getCurrent</methodname> を使って | ||
| 再帰的なフィボナッチ関数を実装する例: | ||
| </para> | ||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| $fibonacci = function (int $n) { | ||
| if ($n === 0 || $n === 1) { | ||
| return $n; | ||
| } | ||
|
|
||
| $fn = Closure::getCurrent(); | ||
| return $fn($n - 1) + $fn($n - 2); | ||
| }; | ||
|
|
||
| echo $fibonacci(10); // 出力: 55 | ||
| ?> | ||
| ]]> | ||
| </programlisting> | ||
| </example> | ||
| <example xml:id="closure.getcurrent.example.comparison"> | ||
| <title>従来のアプローチとの比較</title> | ||
| <para> | ||
| PHP 8.5 より前のバージョンでは、再帰的なクロージャを実装するには | ||
| <literal>use</literal> キーワードを使ってクロージャ変数への参照をキャプチャする必要がありました: | ||
| </para> | ||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| // 従来のアプローチ (PHP 8.5 でも引き続き使用可能) | ||
| $fibonacci = function (int $n) use (&$fibonacci) { | ||
| if ($n === 0) return 0; | ||
| if ($n === 1) return 1; | ||
| return $fibonacci($n - 1) + $fibonacci($n - 2); | ||
| }; | ||
|
|
||
| echo $fibonacci(10); // 出力: 55 | ||
| ?> | ||
| ]]> | ||
| </programlisting> | ||
| <para> | ||
| <methodname>Closure::getCurrent</methodname> を使うアプローチでは、 | ||
| <literal>use</literal> 句で変数を参照で宣言する必要がなくなり、 | ||
| コードがよりクリーンで間違いにくくなります。 | ||
| </para> | ||
| </example> | ||
| </refsect1> | ||
|
|
||
| </refentry> | ||
| <!-- Keep this comment at the end of the file | ||
| Local variables: | ||
| mode: sgml | ||
| sgml-omittag:t | ||
| sgml-shorttag:t | ||
| sgml-minimize-attributes:nil | ||
| sgml-always-quote-attributes:t | ||
| sgml-indent-step:1 | ||
| sgml-indent-data:t | ||
| indent-tabs-mode:nil | ||
| sgml-parent-document:nil | ||
| sgml-default-dtd-file:"~/.phpdoc/manual.ced" | ||
| sgml-exposed-tags:nil | ||
| sgml-local-catalogs:nil | ||
| sgml-local-ecat-files:nil | ||
| End: | ||
| vim600: syn=xml fen fdm=syntax fdl=2 si | ||
| vim: et tw=78 syn=sgml | ||
| vi: ts=1 sw=1 | ||
| --> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.