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

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 of the above will work the same way. I'm just curious to know what to use the most suitable , if anyone knows.

+5
source share
3 answers

Referring: http://php.net/manual/en/function.ini-set.php

 string ini_set ( string $varname , string $newvalue ) 

So you need to use the string for newValue

eg:

 <?php echo ini_get('display_errors'); if (!ini_get('display_errors')) { ini_set('display_errors', '1'); } echo ini_get('display_errors'); ?> 
+2
source

In php.net, the syntax is as follows:

string ini_set (string $ varname, string $ newvalue)

All parameters must be string . In the php.ini file, all logical values ​​are shown as On or Off . The following solution should be the most correct solution:

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

In the documentation for the configuration file, you can find the following part:

Boolean values ​​can be set as follows: true, on, yes or false, off, no, none

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

In ini_get return value is a string. The documentation states:

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

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

+3
source

It should be the same as you installed it in the php.ini file. From the documentation:

string ini_set ( string $varname , string $newvalue )

Thus, this means that you can use any string for $newvalue , and that would be the most correct way. But usually I set it to (int) 1

0
source

Source: https://habr.com/ru/post/1235084/


All Articles