Re: Is there a mapping between "access level" from output ini_get_all() and constants HP_INI_USER, PHP_INI_PERDIR, PHP_INI_SYSTEM, PHP_INI_ALL in
official docs?

From: Date: Wed, 08 Oct 2014 15:11:34 +0000
Subject: Re: Is there a mapping between "access level" from output ini_get_all() and constants HP_INI_USER, PHP_INI_PERDIR, PHP_INI_SYSTEM, PHP_INI_ALL in
official docs?
References: 1 2 3  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969385213@lists.php.net to get a copy of this message
Hi Костя On 8 October 2014 15:59, Костя Третяк <ktretyak.in.ua@gmail.com> wrote: > When I see it the output function ini_get_all(), for example > print_r(ini_get_all("pcre")). > I get a value of "pcre.backtrack_limit['access'] => 7", and understand > that > it means the level of access, > but does not have a mapping to determine that this applies to constants > PHP_INI_ALL > (maybe this is only on Windows 7 and other OS this constant is defined). Is > there a way > to make sure that the "access level" with a value of 7 corresponds to > constant PHP_INI_ALL? The way to determine this in code is simply: if ($ini['pcre.backtrack_limit']['access'] == PHP_INI_ALL) { // stuff } There's no way to get the constant *name* in code without creating a lookup table - and for good reason: PHP_INI_ALL is actually a convenience constant comprising all the other constants, i.e. PHP_INI_ALL === PHP_INI_USER | PHP_INI_PERDIR | PHP_INI_SYSTEM It's also possible for settings to have a scope that does not exactly match one of these constants, for example you'll notice in the example on the ini_get_all() manual page that allow_call_time_pass_reference returns a value of 6, which is actually PHP_INI_PERDIR | PHP_INI_SYSTEM It can be changed in php.ini or in a .htaccess file but it cannot be changed using ini_set(). There is no named constant that maps directly to this configuration, so there is no specific name to give it. In reality, what's likely to be more useful in code is something like this: if ($ini[$name]['access'] & PHP_INI_USER) { ini_set($name, $newValue); } else if ($ini[$name]['access'] & PHP_INI_PERDIR) { echo "Setting must be set in .htaccess or php.ini\n"; } else { // Checking for PHP_INI_SYSTEM is redundant because everything has this echo "Setting must be set in php.ini\n"; } As such, it's not a good idea to rely on specific values but instead use the constant names (especially PHP_INI_ALL) because if another access level were to be added in the future, these values might change. HTH Chris

« previous php.doc (#969385213) next »