Home  >  Article  >  Backend Development  >  二进制安全是什么意思?

二进制安全是什么意思?

WBOY
WBOYOriginal
2016-06-06 20:43:542164browse

在PHP的有些方法的说明中,有的说是“二进制安全”。这是什么意思?

回复内容:

在PHP的有些方法的说明中,有的说是“二进制安全”。这是什么意思?

就是指函数的参数包括二进制数据的时候,函数依然能正常操作。

例如strlen,在输入数据里有\0的时候,并不会在此停止。所以可以说是二进制安全的。

我也在 redis 数据库介绍上看到这样的说法.我认为的二进制安全应该是说:
只关心二进制化的字符串,不关心具体格式.只会严格的按照二进制的数据存取.不会妄图已某种格式解析数据.
有时候以错误的格式打开一个文件,会导致文件发生不可逆的损坏.而二进制安全就是说会避免这种损坏.

比如函数strcoll,它是非二进制安全。而strcmp则是二进制安全的。

它们的区别是:

<code>$string1 = "Hello";
$string2 = "Hello\x00Hello";
echo strcoll($string1, $string2); // 返回0, 由于是非二进制安全,误判为相等
echo strcmp($string1, $string2); // 返回负数
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn