From 647ed75ca57df7f0b42096bf0bc520f860bf88bd Mon Sep 17 00:00:00 2001 From: Luffy Date: Tue, 15 Oct 2024 07:54:00 +0800 Subject: [PATCH] Sync outdated files (#921) --- appendices/tokens.xml | 19 +- language/types/string.xml | 333 ++++++++++-------- reference/filesystem/functions/glob.xml | 4 +- reference/memcache/memcache/delete.xml | 15 +- reference/outcontrol/constants.xml | 7 +- .../outcontrol/user-level-output-buffers.xml | 15 +- 6 files changed, 216 insertions(+), 177 deletions(-) diff --git a/appendices/tokens.xml b/appendices/tokens.xml index b267d27c8..05044f934 100755 --- a/appendices/tokens.xml +++ b/appendices/tokens.xml @@ -1,6 +1,6 @@ - + 解析器记号(token)列表 @@ -196,7 +196,10 @@ defined('T_FN') || define('T_FN', 10001); T_CURLY_OPEN {$ - 复杂变量解析语法 + + 高级 + 变量字符串插值 + T_DEC @@ -244,7 +247,10 @@ defined('T_FN') || define('T_FN', 10001); T_DOLLAR_OPEN_CURLY_BRACES ${ - 复杂变量解析语法 + + 基本 + 变量字符串插值 + T_DOUBLE_ARROW @@ -648,7 +654,7 @@ defined('T_FN') || define('T_FN', 10001); T_PAAMAYIM_NEKUDOTAYIM :: - ::。也定义为 + 范围解析。也定义为 T_DOUBLE_COLON @@ -773,7 +779,10 @@ defined('T_FN') || define('T_FN', 10001); T_STRING_VARNAME "${a - 复杂变量解析语法 + + 可变变量 + 在字符串中插值 + T_SWITCH diff --git a/language/types/string.xml b/language/types/string.xml index cbb15cb48..4a3808064 100644 --- a/language/types/string.xml +++ b/language/types/string.xml @@ -1,6 +1,6 @@ - + String 字符串 @@ -104,7 +104,7 @@ echo 'Variables do not $expand $either'; 双引号 - 如果字符串是包围在双引号(")中, PHP 将对以下特殊的字符进行解析: + 如果字符串是包围在双引号("))中, PHP 将对以下特殊的字符进行解析: @@ -186,7 +186,7 @@ echo 'Variables do not $expand $either'; 用双引号定义的字符串最重要的特征是变量会被解析,详见变量解析。 + linkend="language.types.string.parsing">变量插值。 @@ -550,7 +550,7 @@ FOOBAR; 就象 heredoc 结构类似于双引号字符串,Nowdoc 结构是类似于单引号字符串的。Nowdoc 结构很象 heredoc 结构,但是 nowdoc - 中不进行解析操作。这种结构很适合用于嵌入 PHP + 中不进行字符串插值。这种结构很适合用于嵌入 PHP 代码或其它大段文本而无需对其中的特殊字符进行转义。与 SGML 的 <![CDATA[ ]]> 结构是用来声明大段的不用解析的文本类似,nowdoc 结构也有相同的特征。 @@ -647,31 +647,25 @@ EOT; - 变量解析 + 字符串插值 字符串用双引号或 heredoc 结构定义时,其中的变量将会被解析。 + linkend="language.variables">变量可以进行替换。 这里共有两种语法规则:一种简单规则,一种复杂规则。简单的语法规则是最常用和最方便的,它可以用最少的代码在一个 + linkend="language.types.string.parsing.basic">基本规则,一种高级规则。基本的语法规则是最常用和最方便的,它可以用最少的代码在一个 string 中嵌入一个变量,一个 array 的值,或一个 object 的属性。 - - 复杂规则语法的显著标记是用花括号包围的表达式。 - - - - 简单语法 - + + 基本语法 - 当 PHP 解析器遇到一个美元符号($)时,它会和其它很多解析器一样,去组合尽量多的标识以形成一个合法的变量名。可以用花括号来明确变量名的界线。 + 如果遇到一个美元符号($),后面的字符会被解释为变量名,然后替换为变量的值。 - ]]> @@ -693,42 +681,127 @@ echo "He drank some juice made of {$juice}s."; - 类似的,一个 array 索引或一个 object - 属性也可被解析。数组索引要用方括号(])来表示索引结束的边际,对象属性则是和上述的变量规则相同。 + 从形式上讲,基本变量替换语法的结构如下: + + + - 简单语法示例 - +offset-or-property:: + offset-in-string + | property-in-string + +offset-in-string:: + [ name ] + | [ variable-name ] + | [ integer-literal ] + +property-in-string:: + -> name + +variable-name:: + $ name + +name:: + [a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]* + +]]> + + + + + + ${ expression } 语法从 PHP 8.2.0 开始被弃用,因为它可能被解释为 + 可变变量: + + "purple"); +const foo = 'bar'; +$foo = 'foo'; +$bar = 'bar'; +var_dump("${foo}"); +var_dump("${(foo)}"); +?> +]]> + + &example.outputs.82; + + + + &example.outputs; + + + + + 高级 字符串插值语法应该被使用。 + + -class people { - public $john = "John Smith"; - public $jane = "Jane Smith"; - public $robert = "Robert Paulsen"; + + + 如果无法形成有效的变量名,美元符号会保持原样。 + + + + +]]> + + &example.outputs; + + + + + + + + 插值数组或属性的第一个维度值 + + "purple"); - public $smith = "Smith"; +echo "He drank some $juices[0] juice."; +echo PHP_EOL; +echo "He drank some $juices[1] juice."; +echo PHP_EOL; +echo "He drank some $juices[string_key] juice."; +echo PHP_EOL; + +class A { + public $s = "string"; } -$people = new people(); +$o = new A(); -echo "$people->john drank some $juices[0] juice.".PHP_EOL; -echo "$people->john then said hello to $people->jane.".PHP_EOL; -echo "$people->john's wife greeted $people->robert.".PHP_EOL; -echo "$people->robert greeted the two $people->smiths."; // Won't work +echo "Object value: $o->s."; ?> ]]> @@ -738,21 +811,26 @@ echo "$people->robert greeted the two $people->smiths."; // Won't work He drank some apple juice. He drank some orange juice. He drank some purple juice. -John Smith drank some apple juice. -John Smith then said hello to Jane Smith. -John Smith's wife greeted Robert Paulsen. -Robert Paulsen greeted the two . +Object value: string. ]]> + + + 数组键必须是无引号的,因此不能用基本语法将常量作为键来引用。使用 + 高级 + 语法代替。 + + + 从 PHP 7.1.0 起,还支持数字索引。 负数索引 - &example.outputs; - @@ -771,149 +849,96 @@ Changing the character at index -3 to o gives strong. - 如果想要表达更复杂的结构,请用复杂语法。 + 对于更复杂的情况,可以使用 高级 + 语法。 - - 复杂(花括号)语法 + + + 高级(大括号)语法 - 复杂语法不是因为其语法复杂而得名,而是因为它可以使用复杂的表达式。 + 高级语法允许使用任意访问器对变量进行插值。 - 任何具有 string - 表达的标量变量,数组单元或对象属性都可使用此语法。 - 表达式的书写方式与在 string 以外的方式相同, - 然后用花括号 {} 把它括起来即可。由于 - { 无法被转义,只有 $ - 紧挨着 { 时才会被识别。可以用 - {\$ 来表达 {$。下面的示例可以更好的解释: + 任何标量变量、数组元素或对象属性(static 或非 + static)都可以通过这种语法进行插值。表达式的写法和 + 在string之外的写法一样,然后用大括号{和 + }包围。由于{不能被转义,所以这种语法只有在 + 紧跟在{后面的$才会被识别。要得到一个字面的 + {$,需要用{\$。以下是一些例子: 'Indexed value', + 'const-key' => 'Key with minus sign', + 'foo' => ['foo1', 'foo2', 'foo3'] +]; + +// Won't work, outputs: This is { fantastic} echo "This is { $great}"; -// 有效,输出: This is fantastic +// Works, outputs: This is fantastic echo "This is {$great}"; -// 有效 -echo "This square is {$square->width}00 centimeters broad."; +class Square { + public $width; -// 有效,只有通过花括号语法才能正确解析带引号的键名 -echo "This works: {$arr['key']}"; + public function __construct(int $width) { $this->width = $width; } +} + +$square = new Square(5); -// 有效 -echo "This works: {$arr[4][3]}"; +// Works +echo "This square is {$square->width}00 centimeters wide."; -// 这是错误的表达式,因为就象 $foo[bar] 的格式在字符串以外也是错的一样。 -// PHP 首先会查找名为 foo 的常量,如果没有找到,就会出错。 -// 如果常量被找到,其值(而不是 "foo" 本身)将用于数组索引。 -echo "This is wrong: {$arr[foo][3]}"; +// Works, quoted keys only work using the curly brace syntax +echo "This works: {$arr['key']}"; -// 有效,当在字符串中使用多重数组时,一定要用括号将它括起来 -echo "This works: {$arr['foo'][3]}"; -// 有效 -echo "This works: " . $arr['foo'][3]; +// Works +echo "This works: {$arr[3][2]}"; -echo "This works too: {$obj->values[3]->name}"; +echo "This works: {$arr[DATA_KEY]}"; -echo "This is the value of the var named $name: {${$name}}"; +// When using multidimensional arrays, always use braces around arrays +// when inside of strings +echo "This works: {$arr['foo'][2]}"; -echo "This is the value of the var named by the return value of getName(): {${getName()}}"; +echo "This works: {$obj->values[3]->name}"; -echo "This is the value of the var named by the return value of \$object->getName(): {${$object->getName()}}"; +echo "This works: {$obj->$staticProp}"; -// 无效,输出: This is the return value of getName(): {getName()} -echo "This is the return value of getName(): {getName()}"; +// Won't work, outputs: C:\folder\{fantastic}.txt +echo "C:\folder\{$great}.txt"; -// 无效, 输出: C:\folder\{fantastic}.txt -echo "C:\folder\{$great}.txt" -// 有效, 输出: C:\folder\fantastic.txt -echo "C:\\folder\\{$great}.txt" +// Works, outputs: C:\folder\fantastic.txt +echo "C:\\folder\\{$great}.txt"; ?> ]]> - - - 也可以在字符串中用此语法通过变量来调用类的属性。 - - - - -$bar}\n"; -echo "{$foo->{$baz[1]}}\n"; -?> -]]> - - &example.outputs; - -I am bar. -I am bar. - - - - - 函数、方法、静态类变量和类常量可使用 {$} - ,在该字符串被定义的命名空间中将其值作为变量名来访问。只单一使用花括号 - ({}) 无法处理从函数或方法的返回值或者类常量以及类静态变量的值。 - + + 由于该语法允许任意表达式,因此可以在高级语法中使用 + 可变变量。 + - - - - -]]> - - - diff --git a/reference/filesystem/functions/glob.xml b/reference/filesystem/functions/glob.xml index 3c93c4e73..63e9eba79 100644 --- a/reference/filesystem/functions/glob.xml +++ b/reference/filesystem/functions/glob.xml @@ -1,6 +1,6 @@ - + @@ -68,7 +68,7 @@ 有效标记有: - + diff --git a/reference/memcache/memcache/delete.xml b/reference/memcache/memcache/delete.xml index 8bb547d1c..ce739047e 100644 --- a/reference/memcache/memcache/delete.xml +++ b/reference/memcache/memcache/delete.xml @@ -1,7 +1,7 @@ - - + + Memcache::delete @@ -13,7 +13,7 @@ boolMemcache::delete stringkey - inttimeout0 + intexptime0 @@ -35,7 +35,7 @@ - timeout + exptime 不支持此弃用参数,并且默认为 0 秒。不要使用此参数。 @@ -59,11 +59,10 @@ - Unknown + PECL memcache 3.0.5 - - 不建议使用 timeout 参数。此行为在多个 memcached 版本之间的行为不同,但设置为 0 - 是安全的。此弃用功能的其他值可能会导致内存缓存删除失败。 + exptime 已经被弃用,不应该再提供。 + 除了 0 之外的值可能会导致意外错误。 diff --git a/reference/outcontrol/constants.xml b/reference/outcontrol/constants.xml index f8d1d8470..129be7493 100644 --- a/reference/outcontrol/constants.xml +++ b/reference/outcontrol/constants.xml @@ -1,6 +1,6 @@ - + &reftitle.constants; @@ -173,8 +173,9 @@ - 表示输出处理程序已禁用。当输出处理程序返回 &false; 或者处理缓冲区失败时设置此 - flag,也有一个情况就是在调用输出处理程序之前设置了此 flag。 + 表示输出处理程序已禁用。当输出处理程序返回 &false; + 或者处理缓冲区失败时设置此 flag。 + 在 PHP 8.4.0 之前,此 flag 可以在启动输出缓冲区时设置。 diff --git a/reference/outcontrol/user-level-output-buffers.xml b/reference/outcontrol/user-level-output-buffers.xml index 890fc695c..a3fac39af 100644 --- a/reference/outcontrol/user-level-output-buffers.xml +++ b/reference/outcontrol/user-level-output-buffers.xml @@ -1,5 +1,6 @@ - + + 用户级别输出缓冲区 @@ -368,9 +369,11 @@ If the PHP_OUTPUT_HANDLER_DISABLED of a handler is set, the handler will not be invoked by calling ob_end_clean, ob_end_flush, - ob_get_clean, ob_get_flush + ob_get_clean, ob_get_flush, + ob_clean, + ob_flush or during PHP's shutdown process. - This flag has no effect on when calling ob_clean + Prior to PHP 8.4.0, this flag had no effect when calling ob_clean or ob_flush. @@ -575,9 +578,11 @@ If the PHP_OUTPUT_HANDLER_DISABLED of a handler is set, the handler will not be invoked by calling ob_end_clean, ob_end_flush, - ob_get_clean, ob_get_flush + ob_get_clean, ob_get_flush, + ob_clean, + ob_flush or during PHP's shutdown process. - This flag has no effect on when calling ob_clean + Prior to PHP 8.4.0, this flag had no effect when calling ob_clean or ob_flush.