com doc/zh: Sync with EN.: language/operators.xml language/types.xml

From: Date: Sun, 17 Jan 2021 17:55:07 +0000
Subject: com doc/zh: Sync with EN.: language/operators.xml language/types.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-5927@lists.php.net to get a copy of this message
Commit: 70f0af9e29cd9ea16ad7cce865bc4df451abbb57 Author: 戴劼 <daijie@php.net> Mon, 18 Jan 2021 01:55:07 +0800 Parents: af4086ae5276d500045c4e6c6a579eb0358aed46 Branches: master Link: http://git.php.net/?p=doc/zh.git;a=commitdiff;h=70f0af9e29cd9ea16ad7cce865bc4df451abbb57 Log: Sync with EN. Changed paths: M language/operators.xml M language/types.xml

diff --git a/language/operators.xml b/language/operators.xml index b06871c9..e1148ed6 100755 --- a/language/operators.xml +++ b/language/operators.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> -<!-- EN-Revision: dec1f8445ab2af7fbafef012fb7907ab2cd349b5 Maintainer: jhdxr Status: ready --> +<!-- EN-Revision: 646e6eb3e3eaf0cb40127405a01ed5e3f479799f Maintainer: jhdxr Status: ready --> <chapter xml:id="language.operators" xmlns="http://docbook.org/ns/docbook"> <title>运算符</title> <simpara> @@ -401,7 +401,7 @@ x minus one equals 3, or so I hope <row> <entry>$a ** $b</entry> <entry>求幂</entry> - <entry> <varname>$a</varname> 的 <varname>$b</varname>次方的值. PHP 5.6版本中引入.</entry> + <entry> <varname>$a</varname> 的 <varname>$b</varname>次方的值。</entry> </row> </tbody> </tgroup> @@ -432,9 +432,14 @@ echo (-5 % -3)."\n"; // prints -2 </programlisting> </informalexample> </para> - <simpara> - 参见手册中的<link linkend="ref.math">数学函数</link>。 - </simpara> + <sect2 role="seealso"> + &reftitle.seealso; + <para> + <simplelist> + <member><link linkend="ref.math">数学函数</link></member> + </simplelist> + </para> + </sect2> </sect1> @@ -514,14 +519,10 @@ print "$b\n"; // 也输出 4,因为 $b 是 $a 的引用,因此也被改变 </para> <para> <link linkend="language.oop5.basic.new">new</link> - 运算符自动返回一个引用,因此在 PHP 7.0.0及之后的版本中禁止对 - <link linkend="language.oop5.basic.new">new</link> 的结果进行引用赋值; - PHP 5.3.0 及之后的版本则发出一条 - <constant>E_DEPRECATED</constant> 错误信息;在更早的版本中发出的是 - <constant>E_STRICT</constant>。 + 运算符自动返回一个引用,因此对 + <link linkend="language.oop5.basic.new">new</link> 的结果进行引用赋值是错误的。 </para> <para> - 例如以下代码将产生错误或警告: <informalexample> <programlisting role="php"> <![CDATA[ @@ -532,24 +533,12 @@ $o = &new C; ?> ]]> </programlisting> - &example.outputs.7; + &example.outputs; <screen> <![CDATA[ Parse error: syntax error, unexpected 'new' (T_NEW) in … ]]> </screen> - &example.outputs.53; - <screen> -<![CDATA[ -Deprecated: Assigning the return value of new by reference is deprecated in … -]]> - </screen> - &example.outputs.5; - <screen> -<![CDATA[ -Strict Standards: Assigning the return value of new by reference is deprecated in … -]]> - </screen> </informalexample> </para> <para> @@ -573,7 +562,7 @@ Strict Standards: Assigning the return value of new by reference is deprecated i <tbody> <row> <entry>$a += $b</entry> - <entry>$a = $a + b</entry> + <entry>$a = $a + $b</entry> <entry>加法</entry> </row> <row> @@ -669,12 +658,14 @@ Strict Standards: Assigning the return value of new by reference is deprecated i </tgroup> </informaltable> </sect2> - <sect2 xml:id="language.operators.assignment.see-also"> + <sect2 role="seealso" xml:id="language.operators.assignment.see-also"> + &reftitle.seealso; <para> - 可参见手册中<link linkend="language.operators.arithmetic"> - 算术运算符</link>、<link linkend="language.operators.bitwise">位运算符</link>、 - <link linkend="language.operators.string">字符串运算符</link>、 - <link linkend="language.operators.comparison.coalesce">NULL 合并运算符</link>章节。 + <simplelist> + <member><link linkend="language.operators.arithmetic">算术运算符</link></member> + <member><link linkend="language.operators.bitwise">位运算符</link></member> + <member><link linkend="language.operators.comparison.coalesce">NULL 合并运算符</link></member> + </simplelist> </para> </sect2> @@ -1303,26 +1294,25 @@ Expression: 0 = -4 << 62 </para> <warning> <para> - Prior to PHP 7.0, shifting integers by values greater than or equal to the - system long integer width, or by negative numbers, results in undefined - behavior. In other words, if you're using PHP 5.x, don't shift more than 31 - bits on a 32-bit system, and don't shift more than 63 bits on 64-bit - system. - </para> - <para> 使用 <link linkend="book.gmp">gmp</link> 扩展对超出 <literal>PHP_INT_MAX</literal> 的数值来进行位操作。 </para> </warning> - <para> - 参见 - <function>pack</function>, - <function>unpack</function>, - <function>gmp_and</function>, - <function>gmp_or</function>, - <function>gmp_xor</function>, - <function>gmp_testbit</function>, - <function>gmp_clrbit</function> - </para> + + <sect2 role="seealso"> + &reftitle.seealso; + <para> + <simplelist> + <!-- <link linkend="language.oop5.basic.class.class">::class</link> --> + <member><function>pack</function></member> + <member><function>unpack</function></member> + <member><function>gmp_and</function></member> + <member><function>gmp_or</function></member> + <member><function>gmp_xor</function></member> + <member><function>gmp_testbit</function></member> + <member><function>gmp_clrbit</function></member> + </simplelist> + </para> + </sect2> </sect1> <sect1 xml:id="language.operators.comparison"> @@ -1392,18 +1382,29 @@ Expression: 0 = -4 << 62 <entry>太空船运算符(组合比较符)</entry> <entry> 当<varname>$a</varname>小于、等于、大于 <varname>$b</varname>时 - 分别返回一个小于、等于、大于0的 <type>integer</type> 值。 - PHP7 起开始提供。 + 分别返回一个小于、等于、大于0的 <type>int</type> 值。 </entry> </row> </tbody> </tgroup> </table> <para> - 如果比较一个数字和字符串或者比较涉及到数字内容的字符串,则字符串会被<link - linkend="language.types.string.conversion">转换为数值</link>并且比较按照数值来进行。此规则也适用于 - <link linkend="control-structures.switch">switch</link> 语句。当用 === 或 !== - 进行比较时则不进行类型转换,因为此时类型和数值都要比对。 + 当两个操作对象都是 + <link linkend="language.types.numeric-strings">数字字符串</link>, + 或一个是数字另一个是 + <link linkend="language.types.numeric-strings">数字字符串</link>, + 就会自动按照数值进行比较。 + 此规则也适用于 + <link linkend="control-structures.switch">switch</link> 语句。 + 当比较时用的是 <literal>===</literal> 或 <literal>!==</literal>, + 则不会进行类型转换——因为不仅要对比数值,还要对比类型。 + </para> + <warning> + <para> + Prior to PHP 8.0.0, if a <type>string</type> is compared to a number + or a numeric string then the <type>string</type> was converted to a + number before performing the comparison. This can lead to surprising + results as can be seen with the following example: <informalexample> <programlisting role="php"> <![CDATA[ @@ -1424,6 +1425,12 @@ case "a": // never reached because "a" is already matched with 0 ?> ]]> </programlisting> + </informalexample> + </para> + </warning> + + <para> + <informalexample> <programlisting role="php"> <![CDATA[ <?php @@ -1511,8 +1518,8 @@ echo $a <=> $b; // 1 </entry> </row> <row> - <entry><type>string</type>,<type>resource</type> 或 <type>number</type></entry> - <entry><type>string</type>,<type>resource</type> 或 <type>number</type></entry> + <entry><type>string</type>、<type>resource</type>、<type>int</type>、<type>float</type></entry> + <entry><type>string</type>、<type>resource</type>、<type>int</type>、<type>float</type></entry> <entry>将字符串和资源转换成数字,按普通数学比较</entry> </row> <row> @@ -1585,11 +1592,6 @@ function standard_array_compare($op1, $op2) </programlisting> </example> </para> - - <para> - 参见 <function>strcasecmp</function>,<function>strcmp</function>,<link - linkend="language.operators.array">数组运算符</link>和<link linkend="language.types">类型</link>章节。 - </para> <warning> <title>比较浮点数</title> @@ -1603,6 +1605,18 @@ function standard_array_compare($op1, $op2) </para> </warning> + <sect2 role="seealso"> + &reftitle.seealso; + <para> + <simplelist> + <member><function>strcasecmp</function></member> + <member><function>strcmp</function></member> + <member><link linkend="language.operators.array">数组运算符</link></member> + <member><link linkend="language.types">类型</link></member> + </simplelist> + </para> + </sect2> + <sect2 xml:id="language.operators.comparison.ternary"> <title>三元运算符</title> <para> @@ -1633,7 +1647,7 @@ if (empty($_POST['action'])) { <replaceable>expr3</replaceable>。 </para> <para> - 自 PHP 5.3 起,可以省略三元运算符中间那部分。表达式 + 可以省略三元运算符中间那部分。表达式 <literal>expr1 ?: expr3</literal> 在 <replaceable>expr1</replaceable> 求值为 &true; 时返回 <replaceable>expr1</replaceable>,否则返回 @@ -1648,8 +1662,11 @@ if (empty($_POST['action'])) { </note> <note> <para> - 建议避免将三元运算符堆积在一起使用。当在一条语句中使用多个三元运算符时会造成 - PHP 运算结果不清晰: + 建议避免将三元运算符堆积在一起使用。和其他语言相比, + 当在一条语句中使用多个三元运算符时会造成 + PHP 运算结果不清晰。 + 甚至在 PHP 8.0.0 之前,三元运算符是从左到右执行的, + 而大多数其他编程语言是从右到左的。 <example> <title>不清晰的三元运算符行为</title> <programlisting role="php"> @@ -1658,12 +1675,12 @@ if (empty($_POST['action'])) { // 乍看起来下面的输出是 'true' echo (true?'true':false?'t':'f'); -// 然而,上面语句的实际输出是't',因为三元运算符是从左往右计算的 +// 然而,上面语句的实际输出是't',因为在 PHP 8.0.0 之前三元运算符是从左往右计算的 // 下面是与上面等价的语句,但更清晰 echo ((true ? 'true' : 'false') ? 't' : 'f'); -// here, you can see that the first expression is evaluated to 'true', which +// here, one can see that the first expression is evaluated to 'true', which // in turn evaluates to (bool)true, thus returning the true branch of the // second ternary expression. ?> @@ -1677,7 +1694,7 @@ echo ((true ? 'true' : 'false') ? 't' : 'f'); <sect2 xml:id="language.operators.comparison.coalesce"> <title>NULL 合并运算符</title> <para> - PHP 7 开始存在 "??" (NULL 合并)运算符。 + 而且存在 "??" (NULL 合并)运算符。 <example> <title>设置默认值</title> <programlisting role="php"> @@ -1748,7 +1765,7 @@ echo $foo ?? $bar ?? $baz ?? $qux; // 输出 1 <function>error_reporting</function>,而该函数在出错语句前有 @ 时将返回 0。 </simpara> <simpara> - <function>get_error_last</function> 返回数组中的 <literal>"message"</literal> 元素储存了表达式产生的任意错误信息。 + <function>error_get_last</function> 返回数组中的 <literal>"message"</literal> 元素储存了表达式产生的任意错误信息。 此函数的返回结果会随着每次错误的发生而相应变化,所以需要尽早检查。 </simpara> <para> @@ -1777,15 +1794,23 @@ $value = @$cache[$key]; <literal>if</literal> 和 &foreach; 等。 </simpara> </note> - <simpara> - 参见 <function>error_reporting</function> - 及手册中<link linkend="ref.errorfunc">错误处理及日志函数</link>的有关章节。 - </simpara> <warning> <para> - 目前的“@”错误控制运算符前缀甚至使导致脚本终止的严重错误的错误报告也失效。这意味着如果在某个不存在或者敲错了字母的函数调用前用了“@”来抑制错误信息,那脚本会没有任何迹象显示原因而死在那里。 + 目前的“@”错误控制运算符前缀甚至使导致脚本终止的严重错误的错误报告也失效。 + 这意味着如果在某个不存在或者敲错了字母的函数调用前用了“@”来抑制错误信息, + 那脚本会没有任何迹象显示原因而死在那里。 </para> </warning> + + <sect2 role="seealso"> + &reftitle.seealso; + <para> + <simplelist> + <member><function>error_reporting</function></member> + <member><link linkend="ref.errorfunc">错误处理与日志记录函数</link></member> + </simplelist> + </para> + </sect2> </sect1> <sect1 xml:id="language.operators.execution"> @@ -1815,10 +1840,18 @@ echo "<pre>$output</pre>"; 与其它某些语言不同,反引号不能在双引号字符串中使用。 </para> </note> - <para> - 参见手册中<link linkend="ref.exec">程序执行函数</link>,<function>popen</function>,<function>proc_open</function> - 以及 <link linkend="features.commandline">PHP 的命令行模式</link>。 - </para> + + <sect2 role="seealso"> + &reftitle.seealso; + <para> + <simplelist> + <member><link linkend="ref.exec">程序执行函数</link></member> + <member><function>popen</function></member> + <member><function>proc_open</function></member> + <member><link linkend="features.commandline">PHP 的命令行模式</link></member> + </simplelist> + </para> + </sect2> </sect1> <sect1 xml:id="language.operators.increment"> @@ -2085,9 +2118,16 @@ $a .= "World!"; // now $a contains "Hello World!" </programlisting> </informalexample> </para> - <para> - 参见<link linkend="language.types.string">字符串类型</link>和<link linkend="ref.strings">字符串函数</link>章节。 - </para> + + <sect2 role="seealso"> + &reftitle.seealso; + <para> + <simplelist> + <member><link linkend="language.types.string">字符串类型</link></member> + <member><link linkend="ref.strings">字符串函数</link></member> + </simplelist> + </para> + </sect2> </sect1> <sect1 xml:id="language.operators.array"> @@ -2214,10 +2254,16 @@ var_dump($a === $b); // bool(false) </programlisting> </example> </para> - <para> - 参见<link linkend="language.types.array">数组类型</link>和<link - linkend="ref.array">数组函数</link>章节。 - </para> + + <sect2 role="seealso"> + &reftitle.seealso; + <para> + <simplelist> + <member><link linkend="language.types.array">数组类型</link></member> + <member><link linkend="ref.array">数组函数</link></member> + </simplelist> + </para> + </sect2> </sect1> <sect1 xml:id="language.operators.type"> @@ -2425,38 +2471,20 @@ bool(false) </screen> </example> </para> - <para> - 然而 instanceof 的使用还有一些陷阱必须了解。在 - PHP 5.1.0 之前,如果要检查的类名称不存在,<literal>instanceof</literal> 会调用 - <function>__autoload</function>。另外,如果该类没有被装载则会产生一个致命错误。可以通过使用动态类引用或用一个包含类名的字符串变量来避开这种问题: - <example> - <title>避免 PHP 5.0 中 instanceof 引起的类名查找和致命错误问题</title> - <programlisting role="php"> -<![CDATA[ -<?php -$d = 'NotMyClass'; -var_dump($a instanceof $d); // no fatal error here -?> -]]> - </programlisting> - &example.outputs; - <screen> -<![CDATA[ -bool(false) -]]> - </screen> - </example> - </para> <simpara> - <literal>instanceof</literal> 运算符是 PHP 5 引进的。在此之前用 - <function>is_a</function>,但是后来 - <function>is_a</function> 被废弃而用 <literal>instanceof</literal> - 替代了。注意自 PHP 5.3.0 起,又恢复使用 <function>is_a</function> 了。 + <literal>instanceof</literal> 在功能上有个 + 类似的变体 <function>is_a</function>。 </simpara> - <para> - 参见 <function>get_class</function> 和 - <function>is_a</function>。 - </para> + + <sect2 role="seealso"> + &reftitle.seealso; + <para> + <simplelist> + <member><function>get_class</function></member> + <member><function>is_a</function></member> + </simplelist> + </para> + </sect2> </sect1> </chapter> diff --git a/language/types.xml b/language/types.xml index 44c1dfd5..45eb19c9 100755 --- a/language/types.xml +++ b/language/types.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> <!-- $Author$ --> -<!-- EN-Revision: a9a6224ca97531df0a4e4b9b16b59c3f2baf1b09 Maintainer: dallas Status: ready --> +<!-- EN-Revision: 1ffbadf2906a5c85d2f9437b87da3e204ea41b7a Maintainer: dallas Status: ready --> <!-- CREDITS: HonestQiao, Gregory, Haohappy --> <chapter xml:id="language.types" xmlns="http://docbook.org/ns/docbook"> <title>类型</title> @@ -96,27 +96,6 @@ </listitem> </itemizedlist> - - <para> - 为了确保代码的易读性,本手册还介绍了一些<link - linkend="language.pseudo-types">伪类型</link>: - </para> - - <itemizedlist> - - <listitem> - <simpara> - <type>mixed</type>(混合类型) - </simpara> - </listitem> - - <listitem> - <simpara> - <type>void</type>(无类型) - </simpara> - </listitem> - - </itemizedlist> <simpara> 可能还会读到一些关于“双精度(double)”类型的参考。实际上 @@ -184,6 +163,7 @@ if (is_string($a_bool)) { &language.types.integer; &language.types.float; &language.types.string; + &language.types.numeric-strings; &language.types.array; &language.types.iterable; &language.types.object; @@ -191,7 +171,6 @@ if (is_string($a_bool)) { &language.types.null; &language.types.callable; &language.types.declarations; - &language.types.pseudo-types; &language.types.type-juggling; </chapter>
« previous php.doc.zh (#5927) next »