Req #79074 [Com]: Add null colleasing and ternary operator for php.ini directive

From: Date: Mon, 10 Feb 2020 01:45:33 +0000
Subject: Req #79074 [Com]: Add null colleasing and ternary operator for php.ini directive
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225471@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79074&edit=1 ID: 79074 Comment by: michael dot vorisek at email dot cz Reported by: michael dot vorisek at email dot cz Summary: Add null colleasing and ternary operator for php.ini directive Status: Feedback Type: Feature/Change Request Package: *General Issues Operating System: Any PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: > The sentence actually means that if you typo the *name* of the directive, PHP will not complain > and a default value will be used instead. Yes, but it does not actually use default value it uses empty string - it should be documented this way also. My specific use case is to set some PHP config value thru env. vars for **recursive** PHP execution, i.e. to be able to pass some configuration values to php subprocess started by exec('php ...') of which I do not have any control and this seems to me like the only way without extra shell script. I propose adding ternary "a ? b ? c" and null colleasing operators "a ?? b". Both operators should evaluate if the "a" expression is empty (i.e. zero length or "0") Then fallback will be easy to implement like: memory_limit = ${PHP_MEMORY_LIMIT} ?? "32MB" Previous Comments: ------------------------------------------------------------------------ [2020-02-10 01:04:18] requinix@php.net > If PHP can't find an expected directive because it is not set or is mistyped, a default > value will be used. If you pull this sentence out of context it's easy to misinterpret what it means. > ; Directives are specified using the following syntax: > ; directive = value > ; Directive names are *case sensitive* - foo=bar is different from FOO=bar. > ; Directives are variables used to configure PHP or PHP extensions. > ; There is no name validation. If PHP can't find an expected > ; directive because it is not set or is mistyped, a default value will be used. The sentence actually means that if you typo the *name* of the directive, PHP will not complain and a default value will be used instead. So it's irrelevant as far as this request goes. What is the real-world use case for a null coalesce or ternary? Why does *branching logic* need to be performed in a configuration file? ------------------------------------------------------------------------ [2020-02-10 00:54:56] video dot ice dot power at seznam dot cz memory_limit = 32M memory_limit = "${PHP_MEMORY_LIMIT}" I have tested this and currently this config does not ignore the 2nd line if the variable is not set, i.e. it does not use "last default/correct value" but instead it uses "PHP default value" Ternary operator is definitely needed for these cases or is there currently any solution without using shell before PHP is launched? ------------------------------------------------------------------------ [2020-01-11 22:36:17] michael dot vorisek at email dot cz > > https://github.com/php/php-src/blob/master/php.ini-production#L40#L41 @geekcom@php.net Thanks, so I could write: memory_limit = 32M memory_limit = "${PHP_MEMORY_LIMIT}" Is there any test for this behaviour in the PHP source? > ternary operator What do you think about native ternary operator for php.ini? ------------------------------------------------------------------------ [2020-01-10 19:11:46] geekcom@php.net https://github.com/php/php-src/blob/master/php.ini-production#L40#L41 ------------------------------------------------------------------------ [2020-01-10 19:06:14] geekcom@php.net Hi michael, bellow text is a snippet of php.ini packaged with PHP. "If PHP can't find an expected directive because it is not set or is mistyped, a default value will be used." Please see at: https://github.com/php/php-src/blob/master/php.ini-production ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=79074 -- Edit this bug report at https://bugs.php.net/bug.php?id=79074&edit=1

« previous php.bugs (#225471) next »