gpt4 book ai didi

php - 据说不是 "binary safe"的 PHP 函数是什么?这些 "non-binary safe"函数将字符串传递给哪些库?为什么?

转载 作者:可可西里 更新时间:2023-10-31 22:43:31 32 4
gpt4 key购买 nike

我在我的机器上使用 Windows 10 家庭单语言版,这是一个 64 位操作系统

我已经安装了最新版本的 XAMPP,它在我的机器上安装了 PHP 7.2.7

我是根据摘自 PHP Manual 的摘录来问这个问题的:

The string in PHP is implemented as an array of bytes and an integer indicating the length of the buffer. It has no information about how those bytes translate to characters, leaving that task to the programmer. There are no limitations on the values the string can be composed of; in particular, bytes with value 0 (“NUL bytes”) are allowed anywhere in the string (however, a few functions, said in this manual not to be “binary safe”, may hand off the strings to libraries that ignore data after a NUL byte.)

我非常理解 PHP 中二进制安全函数和非二进制安全函数之间的区别。我心中有疑惑。请以适当的解释和适当的例子一一回答。

  • PHP中出现“非二进制安全”和“二进制安全”函数的现象仅仅是因为整个PHP解析器是用C语言编写的吗?
  • C 和 PHP 在处理包含任何值(包括 NUL 字节)的字符串时有什么区别?
  • 我想要“非二进制安全”和“二进制安全”的 PHP 函数的完整列表。
  • “非二进制安全”和“二进制安全”的特性是否只适用于操作字符串的函数而不适用于处理 PHP 中其他类型的 PHP 函数?
  • 为什么非二进制安全函数将字符串交给库?
  • 非二进制安全函数是否仅在它们处理的字符串包含 NUL 字节时才将字符串传递给库?
  • 这些“非二进制安全”函数将字符串传递给哪些库?
  • 这些库如何处理从“非二进制安全”函数接收的字符串?
  • 将包含 NUL 字节的字符串交给某个库后,“非二进制安全”函数是否像“二进制安全”函数一样工作?

最佳答案

正如 arkascha 所解释的,“二进制安全”和“非二进制安全”的问题与语言无关。

使用空字节 (0x00) 来指示字符串的结尾更简单(这可能是 C 使用它的原因),但缺点是字符串中的任何地方都不能有空字节如果您必须能够处理各种数据,这是一个很大的限制。将长度存储为字符串的元数据部分更为复杂,如 Pete 所示,但它允许您处理任何类型的数据。

关于哪些函数是“二进制安全的”或“非二进制安全的”,只需在使用函数之前阅读 PHP 手册。我就是做这个的。无需构建列表,因为 PHP 手册已经解释了您需要了解的有关函数的内容,包括它们是否是二进制安全的。

我认为,您的大部分帖子是由于误解了您引用的 PHP 手册的解释,尤其是这一部分:

however, a few functions, said in this manual not to be “binary safe”, may hand off the strings to libraries that ignore data after a NUL byte.

让我尝试通过添加一些我自己的话来使它更清楚:

however, a few functions, said in this manual not to be “binary safe”, are the functions that may hand off the strings to libraries that ignore data after a NUL byte.

所以它真的没有说“非二进制安全函数将字符串交给库”,这是一种误解。它的意思是“可能将字符串传递给忽略 NUL 字节后的数据的库的函数,在本手册中被称为不是二进制安全的”。

“移交给库”只是“从其他库调用函数”的另一种说法。“忽略 NUL 字节后的数据”是一种称为非二进制安全的行为。

另一种表达方式是:

A few functions in this manual are said not to be "binary safe" because they may call other functions that are also not "binary safe" (functions that ignore data after a NUL byte).

我希望这能帮您解决问题。

关于php - 据说不是 "binary safe"的 PHP 函数是什么?这些 "non-binary safe"函数将字符串传递给哪些库?为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51000656/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com