Reputation: 2777
I have two questions about some quirks in PHP's 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).
According to the above, you can use no
as key if you set INI_SCANNER_TYPED
. So why does it fail?
$ 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 )
Also, what is the "special meaning" of the characters listed below? The manual does not elaborate.
Characters ?{}|&~!()^" must not be used in the key and have a special meaning in the value.
Upvotes: 0
Views: 251
Reputation: 72256
You misinterpreted the text you quoted. It says:
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).
It says about the values. In the default mode, these values are converted to the strings ""
and "1"
. In the INI_SCANNER_TYPED
mode, these values are converted to the boolean false
and true
.
It doesn't say anything about the keys. These words still cannot be used as keys.
Check how it works: https://3v4l.org/5uZFN
Upvotes: 2