com doc/ja: Fix ternary precedence: language/operators.xml
| From: | Yoshinari Takaoka | Date: | Tue, 09 Mar 2021 11:05:10 +0000 |
| Subject: | com doc/ja: Fix ternary precedence: language/operators.xml | ||
| Groups: | php.doc.ja | ||
| Request: | Send a blank email to doc-ja+get-6244@lists.php.net to get a copy of this message | ||
Commit: 7b46aee984e8ddd3e27b5e7fa8fc99876e61ab21
Author: Yoshinari Takaoka <mumumu@mumumu.org> Tue, 9 Mar 2021 20:05:10 +0900
Parents: ca3236dd86b86f91cec8a9256d6683c3722295e9
Branches: master
Link: http://git.php.net/?p=doc/ja.git;a=commitdiff;h=7b46aee984e8ddd3e27b5e7fa8fc99876e61ab21
Log:
Fix ternary precedence
We also fix the misleading note about the ternary operator's
associativity.
Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
Closes GH-470.
Changed paths:
M language/operators.xml
Diff:
diff --git a/language/operators.xml b/language/operators.xml
index 9a484dc388...570d6c11cf 100644
--- a/language/operators.xml
+++ b/language/operators.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 12b1d4704ea448b55ec155619be1e50c0e67e9f9 Maintainer: takagi Status: ready
-->
+<!-- EN-Revision: bcd666c7d0027d2ea13b5051d39e8cf48e338d27 Maintainer: takagi Status: ready
-->
<!-- CREDITS: hirokawa,mumumu -->
<chapter xml:id="language.operators" xmlns="http://docbook.org/ns/docbook">
<title>演算子</title>
@@ -222,7 +222,7 @@
</entry>
</row>
<row>
- <entry>left</entry>
+ <entry>(n/a)</entry>
<entry><literal>? :</literal></entry>
<entry>
<link
linkend="language.operators.comparison.ternary">三項演算子</link>
@@ -363,6 +363,36 @@ x minus one equals 3, or so I hope
<varname>$a</varname> に代入されます。
</para>
</note>
+ <sect2 role="changelog">
+ &reftitle.changelog;
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>8.0.0</entry>
+ <entry>
+ 三項演算子 (<literal>? :</literal>) は、
+ どの演算とも結合しなくなりました。
+ これより前のバージョンでは、左結合でした。
+ </entry>
+ </row>
+ <row>
+ <entry>7.4.0</entry>
+ <entry>
+ 三項演算子(<literal>? :</literal>)
が左結合であること依存すること、
+
つまり、括弧で囲わずに三項演算子をネストすることは推奨されなくなりました。
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </sect2>
</sect1>
<sect1 xml:id="language.operators.arithmetic">
@@ -1730,18 +1760,20 @@ if (empty($_POST['action'])) {
<note>
<para>
三項演算子を "積み重ねて" 使用することは避けましょう。
- ひとつの文の中で複数の三項演算子を使用した際の PHP
の振る舞いは、
+ ひとつの文の中で括弧で囲わずに複数の三項演算子を使用した際の
PHP の振る舞いは、
他のプログラミング言語のそれと比べて、少々わかりにくいものです。
PHP 8.0.0
より前のバージョンでは、三項演算子は左から右に評価されていました。
他の殆どのプログラミング言語では、右から左に評価されます。
+ 左から右に評価される振る舞いに依存することは、PHP 7.4.0
以降は推奨されません。
+ PHP 8.0.0
以降は、三項演算子はどの演算とも結合しなくなっています。
<example>
<title>三項演算子のわかりにくい挙動</title>
<programlisting role="php">
<![CDATA[
<?php
// ぱっと見た感じでは、これは 'true'
と表示されると思うでしょう。
-echo (true?'true':false?'t':'f');
+echo (true ? 'true' : false ? 't' : 'f')
// しかし、PHP 8.0.0 より前のバージョンでは、実際には上の出力結果は
't' です。
// なぜなら、三項演算子は左から右へ順に評価されるからです。