Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-79900

PHP 8.3: Fallback value support for PHP INI Environment Variable syntax

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor Minor
    • None
    • 4.3.1, 4.4
    • General

      https://php.watch/versions/8.3/php-ini-envar-fallback-value-syntax

      PHP Supports substituting PHP INI values with Environment variables with PHP's string interpolation syntax. If the specified Environment variable is not available, the INI parser uses an empty string. In PHP 8.3, this syntax is extended to support declaring a fallback value if the Environment variable is not set.

      session.name = ${SESSION_NAME}
      sendmail_from = "${MAIL_FROM_USER}@${MAIL_FROM_DOMAIN}"
      

      ini_get('session.name');
      ini_get('sendmail_from');
      

      All of the PHP versions support the syntax above to use Environment variables in PHP INI files. In this instance, the session.name INI value will be set to the SESSION_NAME Environment variable if set, or an empty string otherwise. The sendmail_from value uses string interpolation, and PHP substitutes the available Environment variables along with the @ character in the middle.

      PHP does not emit any warnings at startup or parse time when the Environment variables are not present, and always substitutes it with an empty string.

      PHP 8.3 extends the support for INI Environment variable substitution with support for declaring a fallback value.

      In PHP 8.3 and later, it is possible to optionally declare a fallback value with the :- symbol, followed by the fallback value. The same INI values declared in the snippet above can now be set with fallback values:

      session.name = ${SESSION_NAME:-Foo}
      sendmail_from = "${MAIL_FROM_USER:-info}@${MAIL_FROM_DOMAIN:-example.com}"
      

      ini_get('session.name');
      ini_get('sendmail_from');
      

      PHP 8.3 parses these values with support for fallback values specified after the :- symbol.

      For example, the session.name value will be the value of the SESSION_NAME Environment variable if it is set, but it now uses Foo value otherwise.

      sendmail_from value will also fall back to info@example.com if both MAIL_FROM_USER and MAIL_FROM_DOMAIN Environment variables are not set. If either of them are available, the Environment variable will be used.

      Required

      1. Confirm my assessment that no change is required

            dobedobedoh Andrew Lyons
            dobedobedoh Andrew Lyons
            Raquel Ortega Raquel Ortega
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 30 minutes
                30m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.