Skip to content

Commit efa4e7d

Browse files
committed
Update language
1 parent d48ef96 commit efa4e7d

File tree

11 files changed

+91
-74
lines changed

11 files changed

+91
-74
lines changed

appendices/migration84/new-functions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
<para>
158158
<!-- TODO: Link when feature is documented -->
159159
<!-- RFC: https://wiki.php.net/rfc/lazy-objects -->
160-
以下方法与新的惰性对象功能相关
160+
以下方法与新的延迟对象功能相关
161161
<simplelist>
162162
<member>
163163
<methodname>ReflectionClass::newLazyGhost</methodname>

language-snippets.ent

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: c75f19c74fa3b64abfafd7a35aaa652b07834a5a Maintainer: Gregory Status: ready -->
3+
<!-- EN-Revision: ddb05f8827151e25dd1c3e058f95f6c024bc881b Maintainer: Gregory Status: ready -->
44
<!-- CREDITS: dallas, mowangjuanzi, Luffy -->
55
<!-- 请保持此文件与英文文件中相应的每个 ENTITY 行号一一对应以便于对照,修改与更新! -->
66

@@ -2149,10 +2149,16 @@ while <constant>PGSQL_BOTH</constant> will return both numerical and associative
21492149
<!ENTITY sqlsafemode '<link xmlns="http://docbook.org/ns/docbook" linkend="ini.sql.safe-mode">SQL 安全模式</link>'>
21502150

21512151
<!-- BCMath Notes -->
2152-
<!ENTITY bc.scale.description '<varlistentry xmlns="http://docbook.org/ns/docbook"><term>
2153-
<parameter>scale</parameter></term><listitem><para>此可选参数用于设置结果中小数点后的小数位数。也可通过使用
2154-
<function>bcscale</function> 来设置全局默认的小数位数,用于所有函数。如果未设置,则默认为 <literal>0</literal>。
2155-
</para></listitem></varlistentry>'>
2152+
<!ENTITY bc.scale.description '<varlistentry xmlns="http://docbook.org/ns/docbook">
2153+
<term><parameter>scale</parameter></term>
2154+
<listitem>
2155+
<simpara>
2156+
此参数用于设置结果中的小数位数。如果为 &null;,则使用 <function>bcscale</function>
2157+
设置的默认小数位数,或者回退到 <link linkend="ini.bcmath.scale"><literal>bcmath.scale</literal></link>
2158+
INI 指令的值。
2159+
</simpara>
2160+
</listitem>
2161+
</varlistentry>'>
21562162

21572163

21582164
<!-- CTYPE Notes -->

language/functions.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: ee205135d091ffca38bebfb33b4ca7e51cf87625 Maintainer: avenger Status: ready -->
3+
<!-- EN-Revision: ae8e5c871b1a71ea77f5b97f7929d76d4ca724ab Maintainer: avenger Status: ready -->
44
<!-- CREDITS: Gregory, dallas, Luffy, mowangjuanzi -->
55
<chapter xml:id="language.functions" xmlns="http://docbook.org/ns/docbook">
66
<title>函数</title>
@@ -1293,6 +1293,12 @@ Warning: Cannot bind an instance to a static closure in %s on line %d
12931293
</row>
12941294
</thead>
12951295
<tbody>
1296+
<row>
1297+
<entry>8.3.0</entry>
1298+
<entry>
1299+
通过<link linkend="language.oop5.magic">魔术方法</link>创建的闭包可以接受命名参数。
1300+
</entry>
1301+
</row>
12961302
<row>
12971303
<entry>7.1.0</entry>
12981304
<entry>

language/oop5/lazy-objects.xml

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,8 @@
1111
</simpara>
1212

1313
<simpara>
14-
Two lazy object strategies are supported: Ghost Objects and Virtual
15-
Proxies, hereafter referred to as &quot;lazy ghosts&quot; and
16-
&quot;lazy proxies&quot;.
17-
In both strategies, the lazy object is attached to an initializer or factory
18-
that is called automatically when its state is observed or modified for
19-
the first time. From an abstraction point of view, lazy ghost objects are
20-
indistinguishable from non-lazy ones: they can be used without knowing they
21-
are lazy, allowing them to be passed to and used by code that is unaware of
22-
laziness. Lazy proxies are similarly transparent, but care must be taken when
23-
their identity is used, as the proxy and its real instance have different
24-
identities.
14+
支持两种延迟对象策略:幽灵对象(Ghost Object)和虚拟代理(Virtual Proxies),以下称为&quot;延迟幽灵&quot;&quot;延迟代理&quot;
15+
在这两种策略中,延迟对象都附加到初始化程序或工厂,当第一次观察或修改其状态时会自动调用。从抽象的角度来看,延迟幽灵对象与非延迟幽灵对象没有区别:都可以在不知道自己是延迟的情况下使用,从而允许将其传递给不知道延迟的代码并由其使用。延迟代理同样是透明的,但在使用它们的标识(identity)时必须小心,因为代理和其真实实例具有不同的标识。
2516
</simpara>
2617

2718
<sect2 xml:id="language.oop5.lazy-objects.creation">
@@ -37,7 +28,7 @@
3728
</simpara>
3829

3930
<example>
40-
<title>Creating a Lazy Ghost</title>
31+
<title>创建延迟幽灵</title>
4132
<programlisting role="php">
4233
<![CDATA[
4334
<?php
@@ -51,14 +42,14 @@ class Example
5142
5243
$reflector = new ReflectionClass(Example::class);
5344
$lazyObject = $reflector->newLazyGhost(function (Example $object) {
54-
// Initialize object in-place
45+
// 在这里初始化对象
5546
$object->__construct(1);
5647
});
5748
5849
var_dump($lazyObject);
5950
var_dump(get_class($lazyObject));
6051
61-
// Triggers initialization
52+
// 触发初始化
6253
var_dump($lazyObject->prop);
6354
?>
6455
]]>
@@ -78,7 +69,7 @@ int(1)
7869
</example>
7970

8071
<example>
81-
<title>Creating a Lazy Proxy</title>
72+
<title>创建延迟代理</title>
8273
<programlisting role="php">
8374
<![CDATA[
8475
<?php
@@ -92,7 +83,7 @@ class Example
9283
9384
$reflector = new ReflectionClass(Example::class);
9485
$lazyObject = $reflector->newLazyProxy(function (Example $object) {
95-
// Create and return the real instance
86+
// 创建并返回真实实例
9687
return new Example(1);
9788
});
9889
@@ -119,14 +110,12 @@ int(1)
119110
</example>
120111

121112
<simpara>
122-
Any access to properties of a lazy object triggers its initialization
123-
(including via <classname>ReflectionProperty</classname>).
124-
However, certain properties might be known in advance and should not trigger
125-
initialization when accessed:
113+
对延迟对象属性的任何访问都会触发其初始化(包括通过 <classname>ReflectionProperty</classname>
114+
访问)。但是,某些属性可能是预先知道的,并且在访问时不应触发初始化:
126115
</simpara>
127116

128117
<example>
129-
<title>Initializing Properties Eagerly</title>
118+
<title>立即初始化属性</title>
130119
<programlisting role="php">
131120
<![CDATA[
132121
<?php
@@ -162,9 +151,8 @@ var_dump($post->id);
162151
</example>
163152

164153
<simpara>
165-
The <methodname>ReflectionProperty::skipLazyInitialization</methodname> and
166-
<methodname>ReflectionProperty::setRawValueWithoutLazyInitialization</methodname>
167-
methods offer ways to bypass lazy-initialization when accessing a property.
154+
<methodname>ReflectionProperty::skipLazyInitialization</methodname> 和 <methodname>ReflectionProperty::setRawValueWithoutLazyInitialization</methodname>
155+
方法提供了在访问属性时绕过延迟初始化的方法。
168156
</simpara>
169157
</sect2>
170158

@@ -329,7 +317,7 @@ var_dump($post->id);
329317
</simpara>
330318

331319
<sect3>
332-
<title>Ghost Objects</title>
320+
<title>幽灵对象</title>
333321
<simplelist>
334322
<member>
335323
The object is marked as non-lazy.
@@ -358,7 +346,7 @@ var_dump($post->id);
358346
</sect3>
359347

360348
<sect3>
361-
<title>Proxy Objects</title>
349+
<title>代理对象</title>
362350
<simplelist>
363351
<member>
364352
The object is marked as non-lazy.
@@ -405,7 +393,7 @@ var_dump($post->id);
405393
</sect3>
406394

407395
<sect3>
408-
<title>Common Behavior</title>
396+
<title>通用行为</title>
409397

410398
<simpara>
411399
The scope and <varname>$this</varname> context of the initializer or factory

language/predefined/attributes.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- EN-Revision: fe11910e25e7eba44959bd347ba946ffc4d56934 Maintainer: mowangjuanzi Status: ready -->
2+
<!-- EN-Revision: e890e4a7f97a9ea85e60a38443e7c8eb7ae9383f Maintainer: mowangjuanzi Status: ready -->
33
<!-- CREDITS: Luffy -->
44
<part xml:id="reserved.attributes" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
55
<title>预定义注解</title>
@@ -12,6 +12,7 @@
1212

1313
&language.predefined.attributes.attribute;
1414
&language.predefined.attributes.allowdynamicproperties;
15+
&language.predefined.attributes.deprecated;
1516
&language.predefined.attributes.override;
1617
&language.predefined.attributes.returntypewillchange;
1718
&language.predefined.attributes.sensitiveparameter;

language/predefined/attributes/override.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- EN-Revision: 05b314c2ae84456def6a56777b05d0645fb3e11e Maintainer: mowangjuanzi Status: ready -->
2+
<!-- EN-Revision: 68265e11357d89a0c97986c89dcbf0e28b5977e1 Maintainer: mowangjuanzi Status: ready -->
33
<!-- CREDITS: Luffy -->
44
<reference xml:id="class.override" role="class" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
55
<title>Override 属性</title>
@@ -9,8 +9,12 @@
99

1010
<section xml:id="override.intro">
1111
&reftitle.intro;
12-
<para>
13-
</para>
12+
<simpara>
13+
此属性用于表明方法意图重写父类中的方法或实现接口中定义的方法。
14+
</simpara>
15+
<simpara>
16+
如果父类或实现的接口中不存在同名方法,则会引发编译时错误。
17+
</simpara>
1418
</section>
1519

1620
<section xml:id="override.synopsis">

language/predefined/errorexception.xml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: e6376e04ed2526138e5b71e16168cf6bb269fa8a Maintainer: mowangjuanzi Status: ready -->
3+
<!-- EN-Revision: 2f3c1237bc46a7e40dae35e9f3aec2c1b2fa23b8 Maintainer: mowangjuanzi Status: ready -->
44
<!-- CREDITS: Luffy -->
55
<reference xml:id="class.errorexception" role="exception" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
66
<title>ErrorException</title>
@@ -79,35 +79,42 @@
7979
&reftitle.examples;
8080
<para>
8181
<example xml:id="errorexception.example.error-handler"><!-- {{{ -->
82-
<title>使用 <function>set_error_handler</function> 函数将错误信息托管至 ErrorException</title>
82+
<title>使用 <function>set_error_handler</function> 函数将错误信息托管至 ErrorException</title>
8383
<programlisting role="php">
8484
<![CDATA[
8585
<?php
86-
function exception_error_handler(int $errno, string $errstr, string $errfile = null, int $errline) {
86+
87+
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
8788
if (!(error_reporting() & $errno)) {
88-
// 这个错误代码未包含在 error_reporting 中
89+
// 这个错误代码未包含在 error_reporting 中。
90+
return;
91+
}
92+
93+
if ($errno === E_DEPRECATED || $errno === E_USER_DEPRECATED) {
94+
// 因为新的或意外的弃用会破坏应用程序,
95+
// 不要因弃用 warning 而抛出 Exception。
8996
return;
9097
}
98+
9199
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
92-
}
93-
set_error_handler(exception_error_handler(...));
94-
// 在 PHP 8.1.0 引入 First-class 可调用语法之前,必须使用下面的调用来代替
95-
// set_error_handler(__NAMESPACE__ . "\\exception_error_handler");
100+
});
101+
102+
// 反序列化已损坏的数据会触发 warning,
103+
// 错误处理程序会将其转换为 ErrorException。
104+
unserialize('broken data');
96105
97-
/* 触发异常 */
98-
strpos();
99106
?>
100107
]]>
101108
</programlisting>
102109
&example.outputs.similar;
103110
<screen>
104111
<![CDATA[
105-
Fatal error: Uncaught exception 'ErrorException' with message 'strpos() expects at least 2 parameters, 0 given' in /home/bjori/tmp/ex.php:12
112+
Fatal error: Uncaught ErrorException: unserialize(): Error at offset 0 of 11 bytes in test.php:16
106113
Stack trace:
107-
#0 [internal function]: exception_error_handler(2, 'strpos() expect...', '/home/bjori/php...', 12, Array)
108-
#1 /home/bjori/php/cleandocs/test.php(12): strpos()
114+
#0 [internal function]: {closure}(2, 'unserialize(): ...', 'test.php', 16)
115+
#1 test.php(16): unserialize('broken data')
109116
#2 {main}
110-
thrown in /home/bjori/tmp/ex.php on line 12
117+
thrown in test.php on line 16
111118
]]>
112119
</screen>
113120
</example><!-- }}} -->
@@ -120,7 +127,6 @@ Stack trace:
120127
&language.predefined.errorexception.getseverity;
121128

122129
</reference>
123-
124130
<!-- Keep this comment at the end of the file
125131
Local variables:
126132
mode: sgml

language/predefined/exceptions.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: 49b7f738f43c1ea2113cc7931357a10224824539 Maintainer: mowangjuanzi Status: ready -->
3+
<!-- EN-Revision: 4bf789e981af0836c41daa16e57ef86c21497faa Maintainer: mowangjuanzi Status: ready -->
44
<part xml:id="reserved.exceptions" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
55
<title>预定义异常</title>
66

77
<partintro>
88
<para>
9-
参见 <link linkend="spl.exceptions">SPL 异常处理</link>
9+
参见 <link linkend="spl.exceptions">SPL 异常处理</link>
1010
</para>
1111
</partintro>
1212

@@ -27,6 +27,7 @@
2727
&language.predefined.valueerror;
2828
&language.predefined.unhandledmatcherror;
2929
&language.predefined.fibererror;
30+
&language.predefined.requestparsebodyexception;
3031
</part>
3132

3233
<!-- Keep this comment at the end of the file

language/predefined/stringable.xml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: 9eb4a46bba05da229be4c8f7a3cb64702e1a2f95 Maintainer: mowangjuanzi Status: ready -->
3+
<!-- EN-Revision: 85050f5f88cca909b14b7cccc1dcedbb784a4fd6 Maintainer: mowangjuanzi Status: ready -->
44
<reference xml:id="class.stringable" role="class" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
55

66
<title>Stringable 接口</title>
@@ -47,29 +47,25 @@
4747
<para>
4848
<example xml:id="stringable.basic-example">
4949
<title>基础 Stringable 用法</title>
50+
<simpara>这里使用了<link linkend="language.oop5.decon.constructor.promotion">构造器属性提升</link>。</simpara>
5051
<programlisting role="php">
5152
<![CDATA[
5253
<?php
5354
class IPv4Address implements Stringable {
54-
private string $oct1;
55-
private string $oct2;
56-
private string $oct3;
57-
private string $oct4;
58-
59-
public function __construct(string $oct1, string $oct2, string $oct3, string $oct4) {
60-
$this->oct1 = $oct1;
61-
$this->oct2 = $oct2;
62-
$this->oct3 = $oct3;
63-
$this->oct4 = $oct4;
64-
}
55+
public function __construct(
56+
private string $oct1,
57+
private string $oct2,
58+
private string $oct3,
59+
private string $oct4,
60+
) {}
6561
6662
public function __toString(): string {
6763
return "$this->oct1.$this->oct2.$this->oct3.$this->oct4";
6864
}
6965
}
7066
7167
function showStuff(string|Stringable $value) {
72-
// 通过在此处调用 __toString,Stringable 将会获得转化后的字符串
68+
// 存在 Stringable,这将默认调用 __toString()。
7369
print $value;
7470
}
7571

language/predefined/variables.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: a71742330defbc0edfbc6822b4f947bf437b2f70 Maintainer: avenger Status: ready -->
4-
3+
<!-- EN-Revision: d6baeae3fa6e100b6b4b4ecd59fda030aa32f694 Maintainer: avenger Status: ready -->
4+
<!-- CREDITS: mowangjuanzi -->
55
<reference xml:id="reserved.variables" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
66
<title>预定义变量</title>
77

88
<partintro>
99

1010
<para>
11-
对于全部脚本而言,PHP 提供了大量的预定义变量。这些变量将所有的<link linkend="language.variables.external">外部变量</link>表示成内建环境变量,并且将错误信息表示成返回头。
11+
PHP 提供了预定义变量,这些变量表述为<link linkend="language.variables.external">外部变量</link>、内置环境变量以及有关执行环境的其他信息,例如在
12+
CLI 环境中传递给脚本的参数的数量和值。
1213
</para>
1314

1415
</partintro>

0 commit comments

Comments
 (0)