Skip to content

Commit

Permalink
Update language
Browse files Browse the repository at this point in the history
  • Loading branch information
mowangjuanzi committed Feb 4, 2025
1 parent 06399dd commit c6c70d0
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 45 deletions.
4 changes: 2 additions & 2 deletions language/control-structures/match.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 6507fc94c2d0a0e65ee9486a98e9135f34220ae7 Maintainer: mowangjuanzi Status: ready -->
<!-- EN-Revision: e50047b76fc0be5a2345a0b7c34979e3077e8580 Maintainer: mowangjuanzi Status: ready -->
<!-- CREDITS: Luffy, mowangjuanzi -->
<sect1 xml:id="control-structures.match" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>match</title>
Expand Down Expand Up @@ -87,7 +87,7 @@ string(8) "Teenager"
</note>
<note>
<simpara>
<literal>match</literal> 表达式<emphasis>必须</emphasis>使用分号 <literal>;</literal> 结尾
<literal>match</literal> 表达式用作独立表达式时,<emphasis>必须</emphasis>以分号 <literal>;</literal> 终止
</simpara>
</note>
</example>
Expand Down
9 changes: 4 additions & 5 deletions language/enumerations.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 3d5ec5f3634cc9abcbfea7200067861025e9b13e Maintainer: daijie Status: ready -->
<!-- EN-Revision: 06e4d8f936c5b102e60b59c02a048601e9beaf82 Maintainer: daijie Status: ready -->
<!-- CREDITS: Luffy, mowangjuanzi -->
<chapter xml:id="language.enumerations" xmlns="http://docbook.org/ns/docbook">
<title>枚举</title>
Expand Down Expand Up @@ -194,10 +194,9 @@ enum Suit: string
</para>

<para>
条目等同的值,必须是个字面量或它的表达式。
不能是常量和常量表达式。
换言之,允许 <literal>1 + 1</literal>,
不允许 <literal>1 + SOME_CONST</literal>。
等值可以是常量标量表达式。PHP 8.2.0
之前,必须是文字或文字表达式。这意味着不支持常量和常量表达式。也就是说,允许
<code>1 + 1</code>,但不允许 <code>1 + SOME_CONST</code>。
</para>

<para>
Expand Down
22 changes: 8 additions & 14 deletions language/oop5/lazy-objects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ $lazyObject = $reflector->newLazyProxy(function (Example $object) {
var_dump($lazyObject);
var_dump(get_class($lazyObject));
// Triggers initialization
// 触发器初始化
var_dump($lazyObject->prop);
?>
]]>
Expand Down Expand Up @@ -282,25 +282,19 @@ var_dump($post->id);
对象标记为非延迟。
</member>
<member>
Properties not initialized with
<methodname>ReflectionProperty::skipLazyInitialization</methodname> or
没有使用 <methodname>ReflectionProperty::skipLazyInitialization</methodname> 或
<methodname>ReflectionProperty::setRawValueWithoutLazyInitialization</methodname>
are set to their default values, if any. At this stage, the object
resembles one created with
<methodname>ReflectionClass::newInstanceWithoutConstructor</methodname>,
except for already initialized properties.
初始化的属性将设置为他们的默认值(如果有)。在此阶段,该对象类似于使用
<methodname>ReflectionClass::newInstanceWithoutConstructor</methodname>
创建的对象,但排除已初始化的属性。
</member>
<member>
The initializer function is then called with the object as its first
parameter. The function is expected, but not required, to initialize
the object state, and must return &null; or no value. The object is no
longer lazy at this point, so the function can access its properties
directly.
然后,将对象作为第一个参数调用其初始化函数。该函数需要(但不是必须)初始化对象状态,并且必须返回
&null; 或没有值。此时对象不再是延迟,因此该函数可以直接访问其属性。
</member>
</simplelist>
<simpara>
After initialization, the object is indistinguishable from an object that
was never lazy.
初始化后,该对象与从未延迟过的对象没有区别。
</simpara>
</sect3>

Expand Down
2 changes: 1 addition & 1 deletion language/oop5/static.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 3c831023489be0c64268882d5b656149140d6f8b Maintainer: jhdxr Status: ready -->
<!-- EN-Revision: 888507ca9ed7a8517edbf2d00a64fcaf5865aa23 Maintainer: jhdxr Status: ready -->
<!-- CREDITS: Luffy -->
<sect1 xml:id="language.oop5.static" xmlns="http://docbook.org/ns/docbook">
<title>静态(static)关键字</title>
Expand Down
4 changes: 2 additions & 2 deletions language/types.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 117340b0d72bc8884290450ae8b89643528e0f58 Maintainer: dallas Status: ready -->
<!-- EN-Revision: f908fff129bcd8ec1605658e06457cb04e5b2b51 Maintainer: dallas Status: ready -->
<!-- CREDITS: HonestQiao, Gregory, Haohappy, mowangjuanzi, Luffy -->
<chapter xml:id="language.types" xmlns="http://docbook.org/ns/docbook">
<title>类型</title>
Expand Down Expand Up @@ -110,7 +110,7 @@ int(16)
&language.types.void;
&language.types.never;
&language.types.relative-class-types;
&language.types.value;
&language.types.singleton;
&language.types.iterable;
&language.types.declarations;
&language.types.type-juggling;
Expand Down
4 changes: 2 additions & 2 deletions language/types/declarations.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 13273912b0f773c35f05297a47daa7f76dd52669 Maintainer: avenger Status: ready -->
<!-- EN-Revision: f908fff129bcd8ec1605658e06457cb04e5b2b51 Maintainer: avenger Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<sect1 xml:id="language.types.declarations">
<title>类型声明</title>
Expand Down Expand Up @@ -257,7 +257,7 @@ Stack trace:
<title>联合类型</title>
<warning>
<simpara>
在一个联合类型中不能同时用两个 Value 类型 <type>false</type> 和
在一个联合类型中不能同时用两个单例类型 <type>false</type> 和
<type>true</type>。而是使用 <type>bool</type> 替代。
</simpara>
</warning>
Expand Down
10 changes: 5 additions & 5 deletions language/types/value.xml → language/types/singleton.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 5fccbe5195820cd9ec0045674312ec567ef5f6ed Maintainer: mowangjuanzi Status: ready -->
<!-- EN-Revision: f908fff129bcd8ec1605658e06457cb04e5b2b51 Maintainer: mowangjuanzi Status: ready -->
<!-- CREDITS: Luffy -->
<sect1 xml:id="language.types.value">
<title>Value 类型</title>
<sect1 xml:id="language.types.singleton">
<title>单例类型</title>

<para>
Value 类型是那些不仅检查值,而且也检查值本身的类型。PHP 支持两种 Value 类型:<type>false</type>(自
单例类型(singleton type)是只允许单个值的类型。PHP 支持两种单例类型:<type>false</type>(自
PHP 8.0.0 起支持),<type>true</type>(自 PHP 8.2.0 起支持)。
</para>

Expand All @@ -18,7 +18,7 @@

<note>
<simpara>
无法定义自定义 Value 类型。建议改用<link linkend="language.types.enumerations">枚举</link>。
无法定义自定义单例类型。建议改用<link linkend="language.types.enumerations">枚举</link>。
</simpara>
</note>

Expand Down
33 changes: 20 additions & 13 deletions language/types/type-system.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 117340b0d72bc8884290450ae8b89643528e0f58 Maintainer: mowangjuanzi Status: ready -->
<!-- EN-Revision: f908fff129bcd8ec1605658e06457cb04e5b2b51 Maintainer: mowangjuanzi Status: ready -->
<!-- CREDITS: Luffy -->
<sect1 xml:id="language.types.type-system">
<title>类型系统</title>
Expand Down Expand Up @@ -27,9 +27,6 @@
<listitem>
<simpara>内置类型</simpara>
<itemizedlist>
<listitem>
<simpara><type>null</type> 类型</simpara>
</listitem>
<listitem>
<simpara>
标量类型:
Expand Down Expand Up @@ -70,18 +67,28 @@
和 <type>static</type>
</simpara>
</listitem>
</itemizedlist>
</listitem>
<listitem>
<simpara>
<link linkend="language.types.value">Value 类型</link>
</simpara>
<itemizedlist>
<listitem>
<simpara><type>false</type></simpara>
<simpara>
<link linkend="language.types.singleton">单例类型</link>
</simpara>
<itemizedlist>
<listitem>
<simpara><type>false</type></simpara>
</listitem>
<listitem>
<simpara><type>true</type></simpara>
</listitem>
</itemizedlist>
</listitem>
<listitem>
<simpara><type>true</type></simpara>
<simpara>
单值类型
</simpara>
<itemizedlist>
<listitem>
<simpara><type>null</type></simpara>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>
</listitem>
Expand Down
29 changes: 28 additions & 1 deletion language/variables.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: df1e7145848499f193d0e106a86c27a9b94d130e Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: 7d804723a85d3a8039ba3d0d2c8c414e85f5ede1 Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: dallas, Gregory, verdana, mowangjuanzi, Luffy -->
<chapter xml:id="language.variables" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>变量</title>
Expand Down Expand Up @@ -448,6 +448,33 @@ function foo(){
</example>
</para>

<simpara>
匿名函数内的静态变量仅在该特定函数实例中存在。如果每次调用时都重新创建匿名函数,则静态变量将重新初始化。
</simpara>
<example>
<title>匿名函数内的静态变量</title>
<programlisting role="php">
<![CDATA[
<?php
function exampleFunction($input) {
$result = (static function () use ($input) {
static $counter = 0;
$counter++;
return "Input: $input, Counter: $counter\n";
});
return $result();
}
// 调用 exampleFunction 将重新创建匿名函数,因此静态
// 变量不会保留其值。
echo exampleFunction('A'); // 输出:Input: A, Counter: 1
echo exampleFunction('B'); // 输出:Input: B, Counter: 1
?>
]]>
</programlisting>
</example>

<para>
从 PHP 8.1.0
开始,当继承(不是覆盖)使用有静态变量的方法时,继承的方法将会跟父级方法共享静态变量。这意味着方法中的静态变量现在跟静态属性有相同的行为。
Expand Down

0 comments on commit c6c70d0

Please sign in to comment.