Skip to content

Commit

Permalink
Update install/language/array
Browse files Browse the repository at this point in the history
  • Loading branch information
mowangjuanzi committed Dec 31, 2024
1 parent f9506ba commit b6b16bb
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 105 deletions.
10 changes: 5 additions & 5 deletions install/fpm/configuration.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: fe2ce5304bfe7eaadba78bebb877dcd197df4c41 Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: b01a6761f8e5a1dc58ec92b4bba9b7b5878047fe Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<sect1 xml:id="install.fpm.configuration" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>配置</title>
Expand Down Expand Up @@ -198,8 +198,8 @@
<listitem>
<para>
设置 FPM 使用的事件机制。
可用以下选项:select、pool、epoll、kqueue (*BSD)、port (Solaris)。
默认值:不设置(自动检测)
可用以下选项:epoll、kqueue (*BSD)、port (Solaris)、poll、select
默认值:不设置(自动检测,优先使用 epoll 和 kqueue
</para>
</listitem>
</varlistentry>
Expand Down Expand Up @@ -882,8 +882,8 @@
<entry>
写入日志的时间(请求完成时)。可以接受 <literal>strftime(3)</literal> 格式
<literal>%d/%b/%Y:%H:%M:%S %z</literal>(默认)。<literal>strftime(3)</literal> 格式必须封装在
<literal>%{&lt;strftime_format&gt;}t</literal> 标签中,例如,对于 ISO8601 格式的时间字符串,使用
<literal>%{%Y-%m-%dT%H:%M:%S%z}t</literal>
<literal>%{&lt;strftime_format&gt;}T</literal> 标签中,例如,对于 ISO8601 格式的时间字符串,使用
<literal>%{%Y-%m-%dT%H:%M:%S%z}T</literal>
</entry>
</row>
<row>
Expand Down
50 changes: 16 additions & 34 deletions language/oop5/lazy-objects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,14 @@ $post = $reflector->newLazyGhost(function ($post) {
$post->__construct($data['id'], $data['title'], $data['content']);
});
// Without this line, the following call to ReflectionProperty::setValue() would
// trigger initialization.
// 如果没有这行,下面调用 ReflectionProperty::setValue() 时将触发初始化
$reflector->getProperty('id')->skipLazyInitialization($post);
$reflector->getProperty('id')->setValue($post, 123);
// Alternatively, one can use this directly:
// 或者直接使用它:
$reflector->getProperty('id')->setRawValueWithoutLazyInitialization($post, 123);
// The id property can be accessed without triggering initialization
// 无需触发初始化即可访问 id 属性
var_dump($post->id);
?>
]]>
Expand All @@ -160,58 +159,41 @@ var_dump($post->id);
<title>关于延迟对象策略</title>

<simpara>
<emphasis>Lazy ghosts</emphasis> are objects that initialize in-place and,
once initialized, are indistinguishable from an object that was never lazy.
This strategy is suitable when we control both the instantiation and
initialization of the object, making it unsuitable if either of these is
managed by another party.
<emphasis>延迟幽灵</emphasis>,就地初始化的对象,并且一旦初始化,就跟从未延迟化的对象没有区别。当需要控制对象的实例化和初始化时,此策略是合适的,如果是其中任何一个由另一方管理,则不适合。
</simpara>

<simpara>
<emphasis>Lazy proxies</emphasis>, once initialized, act as proxies to
a real instance: any operation on an initialized lazy proxy is forwarded
to the real instance. The creation of the real instance can be delegated
to another party, making this strategy useful in cases where lazy ghosts
are unsuitable. Although lazy proxies are nearly as transparent as lazy
ghosts, caution is needed when their identity is used, as the proxy and
its real instance have distinct identities.
<emphasis>延迟代理</emphasis>一旦初始化,便充当真实实例的代理:对已初始化延迟代理的任何操作都将转发给真实实例。真实实例的创建可以委托给另一方,这使得此策略在延迟幽灵不适合的情况下非常有用。尽管延迟代理几乎与延迟幽灵一样透明,但在使用其身份时需要谨慎,因为代理和真实实例具有不同的身份。
</simpara>
</sect2>

<sect2 xml:id="language.oop5.lazy-objects.lifecycle">
<title>延迟对象的生命周期</title>

<simpara>
Objects can be made lazy at instantiation time using
<methodname>ReflectionClass::newLazyGhost</methodname> or
<methodname>ReflectionClass::newLazyProxy</methodname>, or after
instantiation by using
<methodname>ReflectionClass::resetAsLazyGhost</methodname> or
<methodname>ReflectionClass::resetAsLazyProxy</methodname>. Following this, a
lazy object can become initialized through one of the following operations:
对象可以使用 <methodname>ReflectionClass::newLazyGhost</methodname> 或
<methodname>ReflectionClass::newLazyProxy</methodname> 在实例化时设置为延迟,或者使用
<methodname>ReflectionClass::resetAsLazyGhost</methodname> 或
<methodname>ReflectionClass::resetAsLazyProxy</methodname> 在实例化后设置为延迟。之后可以通过下列操作之一初始化延迟对象:
</simpara>

<simplelist>
<member>
Interacting with the object in a way that triggers automatic initialization. See
<link linkend="language.oop5.lazy-objects.initialization-triggers">Initialization
triggers</link>.
以触发自动初始化的方式与对象进行交互。参阅<link linkend="language.oop5.lazy-objects.initialization-triggers">初始化触发器</link>。
</member>
<member>
Marking all its properties as non-lazy using
<methodname>ReflectionProperty::skipLazyInitialization</methodname> or
<methodname>ReflectionProperty::setRawValueWithoutLazyInitialization</methodname>.
使用 <methodname>ReflectionProperty::skipLazyInitialization</methodname> 或
<methodname>ReflectionProperty::setRawValueWithoutLazyInitialization</methodname>
将其所有属性标注为非延迟。
</member>
<member>
Calling explicitly <methodname>ReflectionClass::initializeLazyObject</methodname>
or <methodname>ReflectionClass::markLazyObjectAsInitialized</methodname>.
明确调用 <methodname>ReflectionClass::initializeLazyObject</methodname>
<methodname>ReflectionClass::markLazyObjectAsInitialized</methodname>
</member>
</simplelist>

<simpara>
As lazy objects become initialized when all their properties are marked
non-lazy, the above methods will not mark an object as lazy if no properties
could be marked as lazy.
由于延迟对象在所有属性均标记为非惰性时才会初始化,因此如果没有属性可以标记为延迟,则上述方法不会将对象标记为延迟。
</simpara>
</sect2>

Expand Down
12 changes: 9 additions & 3 deletions language/predefined/variables/argv.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: a6d209f4ff71ccba3f1255902827f5df3e092ff9 Maintainer: HonestQiao Status: ready -->

<!-- EN-Revision: 74ba8fee2972b6ba4f955392d760dea54e757a95 Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry role="variable" xml:id="reserved.variables.argv" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" annotations="verify_info:false">
<refnamediv>
<refname>$argv</refname>
Expand All @@ -23,13 +23,19 @@
这个变量仅在 <link linkend="ini.register-argc-argv">register_argc_argv</link> 打开时可用。
</simpara>
</note>
<warning>
<simpara>
要测试脚本是否从命令行运行,应使用 <function>php_sapi_name</function>,而不是检查是否设置了
<varname>$argv</varname> 或 <varname>$_SERVER['argv']</varname>。
</simpara>
</warning>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example xml:id="variable.argv.basic">
<title><varname>$argv</varname> 范例</title>
<title><varname>$argv</varname> 示例</title>
<programlisting role="php">
<![CDATA[
<?php
Expand Down
23 changes: 11 additions & 12 deletions language/types/string.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: 887c21f977369af0808290874dc2c279ad4d0af2 Maintainer: dallas Status: ready -->
<!-- EN-Revision: ef5a00895dbb9a3abbe3edc03d1f966b239a2eb2 Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<sect1 xml:id="language.types.string">
<title>String 字符串</title>
Expand Down Expand Up @@ -888,10 +888,10 @@ $arr = [
'foo' => ['foo1', 'foo2', 'foo3']
];
// Won't work, outputs: This is { fantastic}
// 无效,输出 This is { fantastic}
echo "This is { $great}";
// Works, outputs: This is fantastic
// 有效,输出 This is fantastic
echo "This is {$great}";
class Square {
Expand All @@ -902,32 +902,31 @@ class Square {
$square = new Square(5);
// Works
// 有效
echo "This square is {$square->width}00 centimeters wide.";
// Works, quoted keys only work using the curly brace syntax
// 有效,引用 key 仅使用花括号语法时有效
echo "This works: {$arr['key']}";
// Works
// 有效
echo "This works: {$arr[3][2]}";
echo "This works: {$arr[DATA_KEY]}";
// When using multidimensional arrays, always use braces around arrays
// when inside of strings
// 使用多维数组时,在字符串内部时,始终使用括号括住数组
echo "This works: {$arr['foo'][2]}";
echo "This works: {$obj->values[3]->name}";
echo "This works: {$obj->$staticProp}";
// Won't work, outputs: C:\folder\{fantastic}.txt
echo "C:\folder\{$great}.txt";
// 无效,输出 C:\directory\{fantastic}.txt
echo "C:\directory\{$great}.txt";
// Works, outputs: C:\folder\fantastic.txt
echo "C:\\folder\\{$great}.txt";
// 有效,输出 C:\directory\fantastic.txt
echo "C:\\directory\\{$great}.txt";
?>
]]>
</programlisting>
Expand Down
54 changes: 41 additions & 13 deletions reference/array/functions/array-column.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 8cdc6621f9826d04abc3e50438c010804d7e8683 Maintainer: 邹松 Status: ready -->

<!-- EN-Revision: 8bf3587d8f70239a65d9aa44d42ced8a696a3e86 Maintainer: 邹松 Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.array-column" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>array_column</refname>
Expand Down Expand Up @@ -99,32 +99,34 @@
<programlisting role="php">
<![CDATA[
<?php
// 表示从数据库返回的记录集的数组
$records = array(
array(
$records = [
[
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
],
[
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
],
[
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
],
[
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
]
];
$first_names = array_column($records, 'first_name');
print_r($first_names);
?>
]]>
</programlisting>
Expand All @@ -150,9 +152,34 @@ Array
<programlisting role="php">
<![CDATA[
<?php
// 使用示例 #1 中的 $records 数组
$records = [
[
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
],
[
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
],
[
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
],
[
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
]
];
$last_names = array_column($records, 'last_name', 'id');
print_r($last_names);
?>
]]>
</programlisting>
Expand Down Expand Up @@ -196,6 +223,7 @@ $users = [
];
print_r(array_column($users, 'username'));
?>
]]>
</programlisting>
Expand All @@ -215,7 +243,7 @@ Array
<para>
<example>
<title>
通过 <function>__get</function> 魔术方法从对象中获取 private 属性的 "name" 列。
通过 <function>__isset</function> 和 <function>__get</function> 魔术方法从对象中获取 private 属性的 "name" 列。
</title>
<programlisting role="php">
<![CDATA[
Expand Down
Loading

0 comments on commit b6b16bb

Please sign in to comment.