Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper value type of the new value when using ini_set()?

Tags:

php

ini

I will use "display_errors" as an example:

ini_set('display_errors', 1);// int
ini_set('display_errors', '1');// string
ini_set('display_errors', 'on');// string
ini_set('display_errors', true);// boolean

I know that all the above will work the same. I'm just curious to know what's the most proper one to use, if anyone knows.

like image 734
evilReiko Avatar asked Nov 03 '15 07:11

evilReiko


1 Answers

On php.net the syntax looks like this:

string ini_set(string $varname, string $newvalue)

All parameters should be a string. On the php.ini file all booleans shown as On or Off. The following solution should be the most proper solution:

ini_set('display_errors', 'On');
ini_set('display_errors', 'Off');

On the documentation of the configuration file you can find the following part:

Boolean values can be set to either:
true, on, yes or false, off, no, none

http://php.net/manual/en/configuration.file.php

On ini_get the return value is a string. The documentation says:

A boolean ini value of off will be returned as an empty string or "0" while a boolean ini value of on will be returned as "1". The function can also return the literal string of INI value.

http://php.net/manual/en/function.ini-get.php

The return value of ini_get and the value for ini_set have to be a string!

like image 169
Sebastian Brosch Avatar answered Nov 16 '22 05:11

Sebastian Brosch