parse_ini_file() 未与手册确认
parse_ini_file() does not confirm with manual
关于 PHP 的 parse_ini_file().
中的一些怪癖,我有两个问题
There are reserved words which must not be used as keys for ini
files. These include: null, yes, no, true, false, on, off, none.
Values null, off, no and false result in "", and values on, yes and
true result in "1", unless INI_SCANNER_TYPED mode is used (as of PHP
5.6.1).
根据上面的说法,如果设置INI_SCANNER_TYPED
,就可以使用no
作为key。那为什么会失败呢?
$ echo "no=1" > a.cfg | php -r 'print_r(parse_ini_file("a.cfg", TRUE, INI_SCANNER_TYPED));'
PHP Warning: syntax error, unexpected BOOL_FALSE in tmp.cfg on line 1
$ php --version
PHP 7.1.14 (cli) (built: Feb 2 2018 08:41:46) ( NTS )
另外,下面列出的字符的"special meaning"是什么?手册没有详细说明。
Characters ?{}|&~!()^" must not be used in the key and have a special meaning in the value.
您误解了您引用的文字。它说:
Values null
, off
, no
and false
result in ""
, and values on
, yes
and true
result in "1"
, unless INI_SCANNER_TYPED
mode is used (as of PHP 5.6.1).
它说的是价值观。在默认模式下,这些 值 被转换为字符串 ""
和 "1"
。在 INI_SCANNER_TYPED
模式下,这些 值 被转换为布尔值 false
和 true
.
它没有说明任何关于键的信息。这些词仍然不能用作键。
查看其工作原理:https://3v4l.org/5uZFN
关于 PHP 的 parse_ini_file().
中的一些怪癖,我有两个问题There are reserved words which must not be used as keys for ini files. These include: null, yes, no, true, false, on, off, none. Values null, off, no and false result in "", and values on, yes and true result in "1", unless INI_SCANNER_TYPED mode is used (as of PHP 5.6.1).
根据上面的说法,如果设置INI_SCANNER_TYPED
,就可以使用no
作为key。那为什么会失败呢?
$ echo "no=1" > a.cfg | php -r 'print_r(parse_ini_file("a.cfg", TRUE, INI_SCANNER_TYPED));'
PHP Warning: syntax error, unexpected BOOL_FALSE in tmp.cfg on line 1
$ php --version
PHP 7.1.14 (cli) (built: Feb 2 2018 08:41:46) ( NTS )
另外,下面列出的字符的"special meaning"是什么?手册没有详细说明。
Characters ?{}|&~!()^" must not be used in the key and have a special meaning in the value.
您误解了您引用的文字。它说:
Values
null
,off
,no
andfalse
result in""
, and valueson
,yes
andtrue
result in"1"
, unlessINI_SCANNER_TYPED
mode is used (as of PHP 5.6.1).
它说的是价值观。在默认模式下,这些 值 被转换为字符串 ""
和 "1"
。在 INI_SCANNER_TYPED
模式下,这些 值 被转换为布尔值 false
和 true
.
它没有说明任何关于键的信息。这些词仍然不能用作键。
查看其工作原理:https://3v4l.org/5uZFN