Skip to content

Commit 160259f

Browse files
committed
Update var
1 parent 8ee1e17 commit 160259f

File tree

5 files changed

+121
-51
lines changed

5 files changed

+121
-51
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"workbench.sash.size": 1
3+
}

reference/var/functions/empty.xml

+1-1
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: 9b68bf2b63200534e022bc65e800cae6c75abf26 Maintainer: HonestQiao Status: ready -->
3+
<!-- EN-Revision: 4a07033f7ac5ab121357051cc94ec48b9f6f58fc Maintainer: HonestQiao Status: ready -->
44
<!-- CREDITS: mowangjuanzi, Luffy -->
55
<refentry xml:id="function.empty" xmlns="http://docbook.org/ns/docbook">
66
<refnamediv>

reference/var/functions/is-callable.xml

+59-37
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: 83a17a7324c2597bd6385148abf19f76127229f5 Maintainer: HonestQiao Status: ready -->
3+
<!-- EN-Revision: 32c55286c8739fd20de9c8624473b2f3268de68e Maintainer: HonestQiao Status: ready -->
44
<!-- CREDITS: mowangjuanzi -->
55
<refentry xml:id="function.is-callable" xmlns="http://docbook.org/ns/docbook">
66
<refnamediv>
77
<refname>is_callable</refname>
88
<refpurpose>
9-
验证值是否可以在当前范围内作为函数调用
9+
验证值是否可以在当前范围内作为函数调用
1010
</refpurpose>
1111
</refnamediv>
1212

@@ -19,7 +19,8 @@
1919
<methodparam choice="opt"><type>string</type><parameter role="reference">callable_name</parameter><initializer>&null;</initializer></methodparam>
2020
</methodsynopsis>
2121
<para>
22-
验证值是 <type>callable</type>。
22+
验证 <parameter>value</parameter> 是 <type>callable</type>,或者其可以使用
23+
<function>call_user_func</function> 函数调用。
2324
</para>
2425
</refsect1>
2526

@@ -31,7 +32,7 @@
3132
<term><parameter>value</parameter></term>
3233
<listitem>
3334
<para>
34-
要验证的值
35+
要验证的值
3536
</para>
3637
</listitem>
3738
</varlistentry>
@@ -40,17 +41,18 @@
4041
<listitem>
4142
<para>
4243
如果设置为 &true;,则函数仅验证 <parameter>value</parameter>
43-
可能是函数或方法。它仅拒绝不是字符串的简单变量,或者不能用作回调的有效结构的数组。只有
44-
2 个条目有效,一个是对象或者字符串,其次是字符串。
44+
是函数还是方法。它将拒绝任何不是<link linkend="object.invoke">可调用</link>对象、<classname>Closure</classname>、&string;
45+
或者不能用作回调的无效结构的数组的值。有效的可调用数组只有
46+
2 个条目,第一个是对象或者字符串,第二个是字符串。
4547
</para>
4648
</listitem>
4749
</varlistentry>
4850
<varlistentry>
4951
<term><parameter>callable_name</parameter></term>
5052
<listitem>
5153
<para>
52-
接受“可调用的名称”。下面的例子是“someClass::someMethod。注意,尽管
53-
someClass::SomeMethod() 暗示是可调用的静态方法,但事实并非如此。
54+
接受 “callable 名称”,例如 <literal>"SomeClass::someMethod"</literal>。注意,尽管
55+
<literal>SomeClass::someMethod()</literal> 暗示是可调用静态方法,但事实并非如此。
5456
</para>
5557
</listitem>
5658
</varlistentry>
@@ -69,54 +71,66 @@
6971
&reftitle.examples;
7072
<para>
7173
<example>
72-
<title><function>is_callable</function> 例子</title>
74+
<title>检查字符串是否可以作为函数调用</title>
7375
<programlisting role="php">
7476
<![CDATA[
7577
<?php
76-
// 如何检测变量以查看是否可以作为函数调用。
7778
78-
//
79-
// 包含函数的简单变量
80-
//
81-
82-
function someFunction()
83-
{
84-
}
79+
function someFunction() {}
8580
8681
$functionVariable = 'someFunction';
8782
88-
var_dump(is_callable($functionVariable, false, $callable_name)); // bool(true)
89-
90-
echo $callable_name, "\n"; // someFunction
83+
var_dump(is_callable($functionVariable, false, $callable_name));
9184
92-
//
93-
// 包含方法的数组
94-
//
85+
var_dump($callable_name);
9586
96-
class someClass {
97-
98-
function someMethod()
99-
{
100-
}
87+
?>
88+
]]>
89+
</programlisting>
90+
&example.outputs;
91+
<screen>
92+
<![CDATA[
93+
bool(true)
94+
string(12) "someFunction"
95+
]]>
96+
</screen>
97+
</example>
98+
<example>
99+
<title>检查数组是否可以作为函数调用</title>
100+
<programlisting role="php">
101+
<![CDATA[
102+
<?php
101103
104+
class SomeClass
105+
{
106+
public function someMethod() {}
102107
}
103108
104-
$anObject = new someClass();
109+
$anObject = new SomeClass();
105110
106-
$methodVariable = array($anObject, 'someMethod');
111+
$methodVariable = [$anObject, 'someMethod'];
107112
108-
var_dump(is_callable($methodVariable, true, $callable_name)); // bool(true)
113+
var_dump(is_callable($methodVariable, true, $callable_name));
109114
110-
echo $callable_name, "\n"; // someClass::someMethod
115+
var_dump($callable_name);
111116
112117
?>
113118
]]>
114119
</programlisting>
115-
</example>
120+
&example.outputs;
121+
<screen>
122+
<![CDATA[
123+
bool(true)
124+
string(21) "SomeClass::someMethod"
125+
]]>
126+
</screen>
127+
</example>
116128
<example>
117-
<title><function>is_callable</function> 和构造函数</title>
129+
<title><function>is_callable</function> 和构造方法</title>
118130
<simpara>
119-
<function>is_callable</function> 报告构造函数不可调用。
131+
尽管构造方法是创建对象时调用的方法,但它们不是静态方法,<function>is_callable</function>
132+
将对它们返回 &false;。无法使用 <function>is_callable</function> 检查类是否可以从当前作用域实例化。
133+
120134
</simpara>
121135
<programlisting role="php">
122136
<![CDATA[
@@ -125,20 +139,27 @@ echo $callable_name, "\n"; // someClass::someMethod
125139
class Foo
126140
{
127141
public function __construct() {}
142+
128143
public function foo() {}
129144
}
130145
131146
var_dump(
132-
is_callable(array('Foo', '__construct')),
133-
is_callable(array('Foo', 'foo'))
147+
is_callable(['Foo', '__construct']),
148+
is_callable(['Foo', 'foo'])
134149
);
150+
151+
$foo = new Foo();
152+
var_dump(is_callable([$foo, '__construct']));
153+
154+
?>
135155
]]>
136156
</programlisting>
137157
&example.outputs;
138158
<screen>
139159
<![CDATA[
140160
bool(false)
141161
bool(false)
162+
bool(true)
142163
]]>
143164
</screen>
144165
</example>
@@ -168,6 +189,7 @@ bool(false)
168189
&reftitle.seealso;
169190
<para>
170191
<simplelist>
192+
<member><function>call_user_func</function></member>
171193
<member><function>function_exists</function></member>
172194
<member><function>method_exists</function></member>
173195
</simplelist>

reference/var/functions/print-r.xml

+27-3
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: ccc438a27bae31d71fe2ca7dc095360db5bc1af6 Maintainer: nio Status: ready -->
3+
<!-- EN-Revision: 649598d5e2965b2565f7724cdb4fd4f094d4c81e Maintainer: nio Status: ready -->
44
<!-- CREDITS: mowangjuanzi -->
55
<refentry xml:id="function.print-r" xmlns="http://docbook.org/ns/docbook">
66
<refnamediv>
@@ -13,7 +13,7 @@
1313
<refsect1 role="description">
1414
&reftitle.description;
1515
<methodsynopsis>
16-
<type class="union"><type>string</type><type>bool</type></type><methodname>print_r</methodname>
16+
<type class="union"><type>string</type><type>true</type></type><methodname>print_r</methodname>
1717
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
1818
<methodparam choice="opt"><type>bool</type><parameter>return</parameter><initializer>&false;</initializer></methodparam>
1919
</methodsynopsis>
@@ -62,11 +62,35 @@
6262
</para>
6363
</refsect1>
6464

65+
<refsect1 role="changelog">
66+
&reftitle.changelog;
67+
<para>
68+
<informaltable>
69+
<tgroup cols="2">
70+
<thead>
71+
<row>
72+
<entry>&Version;</entry>
73+
<entry>&Description;</entry>
74+
</row>
75+
</thead>
76+
<tbody>
77+
<row>
78+
<entry>8.4.0</entry>
79+
<entry>
80+
返回类型从 <type class="union"><type>string</type><type>bool</type></type> 变为 <type class="union"><type>string</type><type>true</type></type>。
81+
</entry>
82+
</row>
83+
</tbody>
84+
</tgroup>
85+
</informaltable>
86+
</para>
87+
</refsect1>
88+
6589
<refsect1 role="examples">
6690
&reftitle.examples;
6791
<para>
6892
<example>
69-
<title><function>print_r</function> 例子</title>
93+
<title><function>print_r</function> 示例</title>
7094
<programlisting role="php">
7195
<![CDATA[
7296
<pre>

reference/var/functions/unserialize.xml

+31-10
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: f80105b4fc1196bd8d5fecb98d686b580b1ff65d Maintainer: HonestQiao Status: ready -->
3+
<!-- EN-Revision: 42bb18bcfef4f715008d00bbdc7ea5203f8ec30a Maintainer: HonestQiao Status: ready -->
44
<!-- CREDITS: mowangjuanzi, Luffy -->
55
<refentry xml:id="function.unserialize" xmlns="http://docbook.org/ns/docbook">
66
<refnamediv>
@@ -51,11 +51,13 @@
5151
</para>
5252
<para>
5353
<note>
54-
<title><link linkend="ini.unserialize-callback-func">unserialize_callback_func</link> 指令</title>
55-
<para>
54+
<title>
5655
<link linkend="ini.unserialize-callback-func">unserialize_callback_func</link>
57-
指令中指定的回调函数在反序列化未定义的类时会调用。如果没有指定回调函数,对象将被实例化为
58-
<classname>__PHP_Incomplete_Class</classname>。
56+
指令
57+
</title>
58+
<para>
59+
在反序列化未定义类时会调用 <link linkend="ini.unserialize-callback-func">unserialize_callback_func</link>
60+
指令中指定的回调。如果没有指定回调,将对象实例化为 <classname>__PHP_Incomplete_Class</classname>。
5961
</para>
6062
</note>
6163
</para>
@@ -80,7 +82,7 @@
8082
<tbody>
8183
<row>
8284
<entry><literal>allowed_classes</literal></entry>
83-
<entry><type>mixed</type></entry>
85+
<entry><type>array|bool</type></entry>
8486
<entry>
8587
<simpara>
8688
应该接受的类名数组,&false; 表示不接受任何类,或者 &true; 表示接受所有类。如果定义此选项且
@@ -124,9 +126,14 @@
124126

125127
<refsect1 role="errors">
126128
&reftitle.errors;
127-
<para>
129+
<simpara>
128130
对象可能会在反序列化处理程序中抛出 <classname>Throwable</classname>。
129-
</para>
131+
</simpara>
132+
<simpara>
133+
自 PHP 8.4.0 起,如果 <parameter>options</parameter> 的 <literal>allowed_classes</literal>
134+
元素不是类名 <type>array</type>,则 <function>unserialize</function> 会抛出 <exceptionname>TypeError</exceptionname>
135+
和 <exceptionname>ValueError</exceptionname>。
136+
</simpara>
130137
</refsect1>
131138

132139
<refsect1 role="changelog">
@@ -141,6 +148,20 @@
141148
</row>
142149
</thead>
143150
<tbody>
151+
<row>
152+
<entry>8.4.0</entry>
153+
<entry>
154+
如果 <parameter>options</parameter> 的 <literal>allowed_classes</literal>
155+
元素不是类名 <type>array</type>,现在会抛出 <exceptionname>TypeError</exceptionname>
156+
和 <exceptionname>ValueError</exceptionname>。
157+
</entry>
158+
</row>
159+
<row>
160+
<entry>8.3.0</entry>
161+
<entry>
162+
当输入字符串有未使用的数据时,现在会发出 <constant>E_WARNING</constant>。
163+
</entry>
164+
</row>
144165
<row>
145166
<entry>8.3.0</entry>
146167
<entry>
@@ -178,7 +199,7 @@
178199
&reftitle.examples;
179200
<para>
180201
<example>
181-
<title><function>unserialize</function> 例子</title>
202+
<title><function>unserialize</function> 示例</title>
182203
<programlisting role="php">
183204
<![CDATA[
184205
<?php
@@ -206,7 +227,7 @@ if (!odbc_execute($stmt, $sqldata) || !odbc_fetch_into($stmt, $tmp)) {
206227
</para>
207228
<para>
208229
<example>
209-
<title>unserialize_callback_func 例子</title>
230+
<title>unserialize_callback_func 示例</title>
210231
<programlisting role="php">
211232
<![CDATA[
212233
<?php

0 commit comments

Comments
 (0)