Reputation: 5574
i'm start to use ini_get_all function to retrieve all configuration option on a shared host server. in the end i got this chunk of array :
[allow_call_time_pass_reference] => Array
(
[global_value] => 1
[local_value] => 1
[access] => 6
)
[allow_url_fopen] => Array
(
[global_value] => 1
[local_value] => 1
[access] => 4
)
The PHP manual just give descripstion :
It's possible for a directive to have multiple access levels, which is why access shows the appropriate bitmask values.
so, can anybody explain about 'access' ? ans how to understand its bitmask values ?
Upvotes: 3
Views: 823
Reputation: 2157
Correct values
I looked it up in the PHP source code and found what you could define as your constants:
define('PHP_INI_USER', 1)
define('PHP_INI_PERDIR', 2)
define('PHP_INI_SYSTEM', 4)
define('PHP_INI_ALL', PHP_INI_USER | PHP_INI_PERDIR | PHP_INI_SYSTEM); // = 7
To check an access level from ini_get_all()
you can do (using allow_url_fopen
as an example):
$all = ini_get_all();
$config = $all['allow_url_fopen'];
$isUserLevel = $config['access'] & PHP_INI_USER; // PHP_INI_USER = 1
For reference
In the PHP's source code in main/php_ini.h these constants are defined as aliases of the Zend equivalents:
#define PHP_INI_USER ZEND_INI_USER
#define PHP_INI_PERDIR ZEND_INI_PERDIR
#define PHP_INI_SYSTEM ZEND_INI_SYSTEM
#define PHP_INI_ALL ZEND_INI_ALL
https://github.com/php/php-src/blob/c8aa6f3a9a3d2c114d0c5e0c9fdd0a465dbb54a5/main/php_ini.h#L45 (lines 45 to 49)
The Zend equivalents are defined in Zend/zend_ini.h as follows:
#define ZEND_INI_USER (1<<0)
#define ZEND_INI_PERDIR (1<<1)
#define ZEND_INI_SYSTEM (1<<2)
#define ZEND_INI_ALL (ZEND_INI_USER|ZEND_INI_PERDIR|ZEND_INI_SYSTEM)
https://github.com/php/php-src/blob/c8aa6f3a9a3d2c114d0c5e0c9fdd0a465dbb54a5/Zend/zend_ini.h#L24 (lines 24 to 28)
<<
is the bitwise shift operator in C++ so 1<<0
= 1, 1<<1
= 2, 1<<2
= 4. ZEND_INI_ALL
is the addition of 1+2+4 = 7.
Upvotes: 2
Reputation: 138171
Would you have read a little further in the "Return Value" section, you'd have found the link to the change modes and what they mean:
1
: PHP_INI_USER
: Entry can be set in user scripts (like with ini_set()) or in the Windows registry2
: PHP_INI_PERDIR
: Entry can be set in php.ini, .htaccess or httpd.conf4
: PHP_INI_SYSTEM
: Entry can be set in php.ini or httpd.conf7
: PHP_INI_ALL
: Entry can be set anywhereUpvotes: 9