Problem/Motivation

This is a follow-up to #2843328: Enforce minimum PHP version in composer dependencies

In that issue, we learned that it's hard to unit-test against the minimum PHP requirement for Drupal.

That's because the DRUPAL_MINIMUM_PHP constant lives in core/includes/bootstrap.inc, which is not autoloadable in unit tests.

This is also true of DRUPAL_MINIMUM_PHP_MEMORY_LIMIT.

This kind of awkward constant definition leads to the solution in #2843328: Enforce minimum PHP version in composer dependencies which is to define a similar constant on the test class, and also to re-definitions of constants as in ThemeHandlerTest.

Also this true of DRUPAL_MINIMUM_SUPPORTED_PHP and DRUPAL_RECOMMENDED_PHP that introduced in #3039287: Implement changes required to remove support for PHP 5.5 and 5.6

Proposed resolution

Deprecate these constants in bootstrap.inc.

Move the constants to an appropriate autoloadable class. This could be in the installer system or \Drupal, or a constants-only class designed for this purpose.
Update: The chosen solution is to add 4 constants to the class \Drupal.

Remaining tasks

Follow-up to remove usages of deprecated constants.

User interface changes

None

API changes

Deprecates DRUPAL_MINIMUM_PHP, DRUPAL_MINIMUM_SUPPORTED_PHP, DRUPAL_RECOMMENDED_PHP and DRUPAL_MINIMUM_PHP_MEMORY_LIMIT

Adds to the class Drupal the following 4 constants: \Drupal::MINIMUM_PHP, \Drupal::MINIMUM_SUPPORTED_PHP, \Drupal::RECOMMENDED_PHP and \Drupal::PHP_MEMORY_LIMIT

Data model changes

None.

CommentFileSizeAuthor
#172 2908079-172.patch20.64 KBjungle
#172 interdiff-170-172.txt790 bytesjungle
#170 raw-interdiff-164-170.txt749 bytesjungle
#170 2908079-170.patch20.63 KBjungle
#164 interdiff-164.txt2.48 KBxjm
#164 php-2908079-164.patch20.63 KBxjm
#161 interdiff-158-161.txt2.03 KBjungle
#161 2908079-161.patch20.35 KBjungle
#158 interdiff-156-158.txt1.95 KBjungle
#158 2908079-158.patch20.27 KBjungle
#156 interdiff-152-155.txt1.66 KBjungle
#156 2908079-155.patch20.31 KBjungle
#152 interdiff-148-152.txt1.27 KBjungle
#152 2908079-152.patch20.23 KBjungle
#151 interdiff-148-151-copied-from-147.txt1.18 KBjungle
#151 2908079-151-copied-from-147.patch20.14 KBjungle
#150 2908079-150-copied-from-147.patch20.14 KBjungle
#150 2908079-150-copied-from-147.patch20.14 KBjungle
#150 2908079-150.patch20.23 KBjungle
#148 interdiff-146-148.txt1.19 KBjungle
#148 2908079-148.patch19.92 KBjungle
#146 interdiff-145-146.txt651 bytesjungle
#146 2908079-146.patch20.18 KBjungle
#145 interdiff-139-145.txt1.06 KBjungle
#145 2908079-145.patch20.02 KBjungle
#139 interdiff-138-139.txt931 bytesjungle
#139 2908079-139.patch20.18 KBjungle
#138 interdiff-134-138.txt3.24 KBjungle
#138 2908079-138.patch20.15 KBjungle
#134 interdiff-132-134.txt1.05 KBjungle
#134 2908079-134.patch19.5 KBjungle
#132 interdiff-130-132.txt719 bytesjungle
#132 2908079-132.patch19.01 KBjungle
#130 interdiff-129-130.txt580 bytesjungle
#130 2908079-130.patch18.79 KBjungle
#129 interdiff-122-129.txt752 bytesjungle
#129 2908079-129.patch18.72 KBjungle
#122 interdiff-119-122.txt2.92 KBjungle
#122 2908079-122.patch18.61 KBjungle
#119 interdiff-115-119.txt1.71 KBjungle
#119 2908079-119.patch16.78 KBjungle
#115 2908079-115.patch16.75 KBSuresh Prabhu Parkala
#108 Screenshot 2019-10-09 at 10.47.51.png137.3 KBalexpott
#105 2908079-105.patch16.45 KBalexpott
#105 103-105-interdiff.txt18.1 KBalexpott
#103 interdiff-2908079-100-103.txt1.71 KBvoleger
#103 2908079-103.patch18.69 KBvoleger
#100 2908079-100.patch20.66 KBandypost
#95 interdiff-2908079-91-95.txt1.27 KBvoleger
#95 2908079-95.patch20.66 KBvoleger
#91 2908079-91.patch20.31 KBvoleger
#85 interdiff-2908079-82-85.txt1.76 KBvoleger
#85 2908079-85.patch20.29 KBvoleger
#85 2908079-85-JUST-REROLL.patch20.31 KBvoleger
#82 2908079-82.patch20.21 KBvoleger
#81 interdiff-2908079-79-81.txt4.62 KBnaveenvalecha
#81 2908079-81.patch20.23 KBnaveenvalecha
#79 interdiff-2908079-75-79.txt4.99 KBvoleger
#79 2908079-79.patch17.4 KBvoleger
#79 2908079-79-just-reroll.patch15.39 KBvoleger
#75 2908079-75.patch16.17 KBKrzysztof Domański
#75 interdiff-73-75.txt898 bytesKrzysztof Domański
#73 2908079-73.patch16.92 KBclaudiu.cristea
#71 2908079-70.interdiff.txt4.04 KBclaudiu.cristea
#71 2908079-70.patch16.88 KBclaudiu.cristea
#68 drupal-2908079-68.patch16.76 KBvoleger
#57 drupal-2908079-57.patch16.71 KBRoSk0
#53 interdiff-47-53.txt1.55 KBmpdonadio
#53 2908079-53.patch16.66 KBmpdonadio
#47 2908079-47.patch16.76 KBandypost
#47 interdiff-2908079-46.txt873 bytesandypost
#46 interdiff-45-46.txt5.74 KBmpdonadio
#46 2908079-46.patch16.58 KBmpdonadio
#45 2908079-45.patch11.65 KBmpdonadio
#42 2908079-boot-const-41.patch11.52 KBvoleger
#42 interdiff-2908079-40-41.txt405 bytesvoleger
#40 2908079-boot-const-40.patch12.02 KBandypost
#40 2908079-interdiff-38.txt395 bytesandypost
#38 2908079-php-36.txt12.02 KBandypost
#38 2908079-interdiff-33.txt1.39 KBandypost
#36 interdiff-2908079-33-36.txt2.53 KBvoleger
#36 deprecate_some_bootstrap-2908079-36-8.6.x.patch11.52 KBvoleger
#33 interdiff-29-33.txt1.51 KBpiggito
#33 2908079-33.patch10.83 KBpiggito
#29 interdiff-2908079-17-29.txt8.82 KBzahord
#29 2908079-29.patch10.85 KBzahord
#24 2908079-24.patch9.17 KBzahord
#23 2908079-22.patch9.17 KBzahord
#20 2908079-20.patch10.07 KBzahord
#17 2908079-17.patch3.67 KBRoSk0
#15 2908079-15.patch2.92 KBRoSk0
#10 interdiff-07-10.txt2.68 KBmpdonadio
#10 2908079-10.patch3.59 KBmpdonadio
#7 interdiff-05-07.txt1.04 KBmpdonadio
#7 2908079-07.patch4.37 KBmpdonadio
#5 interdiff.txt3.09 KBMile23
#5 2908079_5.patch4.25 KBMile23
#3 2908079_3.patch4.13 KBMile23
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mile23 created an issue. See original summary.

xjm’s picture

ThemeHandlerTest is already wrong, unfortunately:

if (!defined('DRUPAL_MINIMUM_PHP')) {
  define('DRUPAL_MINIMUM_PHP', '5.3.10');
}

So yeah, we need a solution for this.

Should we just add it to \Drupal where VERSION lives for now?

Mile23’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +@deprecated, +Kill includes
FileSize
4.13 KB

The actual value of DRUPAL_MINIMUM_PHP doesn't really matter that much for ThemeHandlerTest, because the constant is only defined so the dependencies can be resolved without adding an include. Nevertheless we'd like to test against the actual constant, wouldn't we? :-)

Figuring out where to put these constants is awkward. I don't like \Drupal in general, and it's supposed to be about discovering services and not having constants for stuff. So really \Drupal::VERSION is misplaced. (There should be a Drupal\Core\Release class or something.)

I added a class called Drupal\Core\Php with the various constants, plus deprecation notices. When we decide this part we can add a follow-up to remove deprecated usages.

xjm’s picture

Could we call it Requirements or something? Not Php. :P

Mile23’s picture

One of the two hardest things in computer science. :-)

mpdonadio’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record

I like this, and I like not having this in the `\Drupal` class. I also like the name Requirements, as it may provide a nice home for future needs.

+++ b/core/lib/Drupal/Core/Requirements.php
@@ -0,0 +1,31 @@
+  const DRUPAL_MINIMUM_PHP = '5.5.9';

Since this is already in the `Drupal\Core`, do we need the 'DRUPAL_' prefix on these constants? Or do we want to keep this as they are one-to-one mappings? I think the former would be better.

We are deprecating something, so we need a CR. I stubbed out https://www.drupal.org/node/2909361 so we have something to reference and will write it up later.

NW, for needing to write the CR and needing to reference the CR in the deprecations.

mpdonadio’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
FileSize
4.37 KB
1.04 KB

First pass at CR. Added @see CR to the docblocks.

xjm’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Requirements.php
    @@ -0,0 +1,31 @@
    +  const DRUPAL_MINIMUM_PHP = '5.5.9';
    ...
    +  const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '64M';
    

    Since we now have a namespaced class, I think we can remove DRUPAL_ from the beginning.

  2. +++ b/core/lib/Drupal/Core/Requirements.php
    @@ -0,0 +1,31 @@
    +  /**
    +   * Regular expression to match PHP function names.
    +   *
    +   * @see http://php.net/manual/language.functions.php
    +   */
    +  const DRUPAL_PHP_FUNCTION_PATTERN = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*';
    

    I'm not sure this one belongs here; actually I'm not sure it belongs anywhere. It's only used in two places: by update.module, to look for .info.yml files, and install.inc, to detect... a database driver, of all things.

    So I'd suggest removing this one from the patch and filing a separate issue to deprecate and get rid of it entirely. It has two usages that are not even really conceptually related. Seems like a legacy thing.

Thanks @Mile23 and @mpdonadio!

Mile23’s picture

mpdonadio’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
3.59 KB
2.68 KB

#8 done, updating CR shortly.

xjm’s picture

This looks good to me. One question occurred to me:

+++ b/core/includes/bootstrap.inc
@@ -19,8 +20,13 @@
-const DRUPAL_MINIMUM_PHP = '5.5.9';
+const DRUPAL_MINIMUM_PHP = Requirements::MINIMUM_PHP;

I wondered, is there any risk of these constants being needed at a point when the autoloader isn't available? That prompted me to look at things in the early installer before the autoloader is initialized, and there's a spot in install.php that hardcodes the version to avoid fatal errors. So we're okay on that front (at least in terms of the very early installer). We can discuss what to do about that separately I think.

The constant isn't used anywhere else that seemed like a risk.

xjm’s picture

Issue tags: +Needs followup
mpdonadio’s picture

andypost’s picture

+++ b/core/lib/Drupal/Core/Requirements.php
@@ -0,0 +1,24 @@
+class Requirements {

Most of time constants are defined in interfaces.. is there a reason to make in in class?

+++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php
@@ -361,13 +361,3 @@ protected function systemListReset() {
-if (!defined('DRUPAL_EXTENSION_NAME_MAX_LENGTH')) {
...
-if (!defined('DRUPAL_PHP_FUNCTION_PATTERN')) {

This removal looks unrelated

RoSk0’s picture

FileSize
2.92 KB

Re-roll.

Status: Needs review » Needs work

The last submitted patch, 15: 2908079-15.patch, failed testing. View results

RoSk0’s picture

Missed Requirements class.

In respect to #14:
1) For me it feels strange to have that constants in the interface that not meant to be implemented.
2) Yes and no. Such a clean up is always a good thing for me, so I will leave a decision to someone else.

dawehner’s picture

+++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php
@@ -361,13 +361,3 @@ protected function systemListReset() {
-
-if (!defined('DRUPAL_EXTENSION_NAME_MAX_LENGTH')) {
-  define('DRUPAL_EXTENSION_NAME_MAX_LENGTH', 50);
-}
-if (!defined('DRUPAL_PHP_FUNCTION_PATTERN')) {
-  define('DRUPAL_PHP_FUNCTION_PATTERN', '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*');
-}
-if (!defined('DRUPAL_MINIMUM_PHP')) {

I am a bit confused why one can remove those here as well, but we don't deprecate them

martin107’s picture

Version: 8.5.x-dev » 8.6.x-dev
Status: Needs review » Needs work

The development branch is now 8.6.x

so we need to upgrade our comments of the form.

@deprecated in Drupal 8.5.0

zahord’s picture

Hi All,

I was checking the issue reported and moving all the expected const to Requirements:: to prevent duplicate const declarations. Hope it works!

zahord’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 20: 2908079-20.patch, failed testing. View results

zahord’s picture

Patch udated to prevent remove variables and adding @deprecated

zahord’s picture

Fix patch name

zahord’s picture

Status: Needs work » Needs review
mpdonadio’s picture

Can we get an interdiff? Not sure why this patch jumped from 3k to 10k.

The last submitted patch, 23: 2908079-22.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 24: 2908079-24.patch, failed testing. View results

zahord’s picture

Updated patch to allow install.php file access to the Requirements class + interdiff

zahord’s picture

Status: Needs work » Needs review
gumanist’s picture

Status: Needs review » Needs work

1. Typo, as renamed without DRUPAL_

+ *   \Drupal\Core\Requirements::DRUPAL_MINIMUM_PHP_MEMORY_LIMIT instead.

+ *   \Drupal\Core\Requirements::DRUPAL_MINIMUM_PHP instead.

2. +// The minimum version is specified in the Drupal\Core\Requirements interface
we have class, not an interface

3. PHP_VERSION vs phpversion()
probably it is out of the scope of the issue, but is there any sense of using different ways of getting actual PHP version?

4. Not sure, but wouldn't it be better to add PHP version validation function to the Requirements class to be more DRY?

5. As we introduced Requirements.php, don't be better to move code from core/lib/Drupal/Component/Utility/Environment.php to it and deprecate Environment.php or extend Environment.php with version validation?

6. Probably it is out of the scope as well, but it looks like constants REQUIREMENT_ERROR, etc should be moved to Requirements class

mpdonadio’s picture

Re #31-3-6, I think we can explore those ideas in the future but the scope of this issue is really just to move those constants onto a class (or interface, but IMHO an interface w/o a class is a bad idea) to solve the problem of needing them when unit testing, which will help some of the composer related issues and will pop up once we drop 5.5 and 5.6.

As a side note, PHP_VERSION vs phpversion(), the function is better as it can be mocked or shadowed for testing purposes.

piggito’s picture

anavarre’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
dawehner’s picture

Title: Deprecate bootstrap.inc PHP-related constants » Deprecate some of the bootstrap.inc PHP-related constants
voleger’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
11.52 KB
2.53 KB
dawehner’s picture

+++ b/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -1081,7 +1081,7 @@

@@ -1081,7 +1081,7 @@
       'description' => '',
       'version' => NULL,
       'hidden' => FALSE,
-      'php' => Requirements::MINIMUM_PHP,
+      'php' => DRUPAL_MINIMUM_PHP,
     ];
     $profile_file = drupal_get_path('profile', $profile) . "/$profile.info.yml";
     $info = \Drupal::service('info_parser')->parse($profile_file);
@@ -1090,7 +1090,7 @@

@@ -1090,7 +1090,7 @@
       'description' => '',
       'version' => NULL,
       'hidden' => FALSE,
-      'php' => DRUPAL_MINIMUM_PHP,
+      'php' => Requirements::MINIMUM_PHP,
     ];
     $profile_file = drupal_get_path('profile', $profile) . "/$profile.info.yml";
...
--- b/core/modules/system/system.module

--- b/core/modules/system/system.module
+++ a/core/modules/system/system.module

+++ a/core/modules/system/system.module
+++ a/core/modules/system/system.module
@@ -10,7 +10,6 @@

@@ -10,7 +10,6 @@
 use Drupal\Core\Asset\AttachedAssetsInterface;
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Queue\QueueGarbageCollectionInterface;
-use Drupal\Core\Requirements;
 use Drupal\Core\Database\Query\AlterableInterface;
 use Drupal\Core\Extension\Extension;
 use Drupal\Core\Extension\ExtensionDiscovery;
@@ -1034,7 +1033,7 @@

@@ -1034,7 +1033,7 @@
     'description' => '',
     'package' => 'Other',
     'version' => NULL,
+    'php' => DRUPAL_MINIMUM_PHP,
-    'php' => Requirements::MINIMUM_PHP,
   ];

Is there a reason to revert some of these changes ... ?

andypost’s picture

dawehner’s picture

Status: Needs review » Needs work

Needs work based upon #37

andypost’s picture

Status: Needs work » Needs review
FileSize
395 bytes
12.02 KB

Google reports consts in interfaces is a bad practice for php & java

So I think this class should be final at least

andypost’s picture

Issue tags: +KharkivGSW18
voleger’s picture

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

#42 looks solid.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 42: 2908079-boot-const-41.patch, failed testing. View results

mpdonadio’s picture

Assigned: Unassigned » mpdonadio
Status: Needs work » Needs review
FileSize
11.65 KB

Reroll. Fixing one little thing shortly.

mpdonadio’s picture

This moves the recommended version to the new class, and also removes a hardcoded value in a test.

Did a search for the issue number, and I think we caught all of the @todos, and did some usage reports in PhpStorm, and think we have caught all of the uses in core.

andypost’s picture

both places use files from current "core" dir

dawehner’s picture

+++ b/core/install.php
@@ -21,11 +22,10 @@
 
-// Exit early if running an incompatible PHP version to avoid fatal errors.
-// The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not
-// yet available. It is defined in bootstrap.inc, but it is not possible to
-// load that file yet as it would cause a fatal error on older versions of PHP.
-if (version_compare(PHP_VERSION, '5.5.9') < 0) {
+// Checking minimum PHP version to avoid fatal errors.
+// The minimum version is specified in the Drupal\Core\Requirements class.
+require_once __DIR__ . '/lib/Drupal/Core/Requirements.php';
+if (version_compare(PHP_VERSION, Requirements::MINIMUM_PHP) < 0) {

Isn't this a problem because this now probably at least requires php 5.4 to even start executing this code?

mpdonadio’s picture

#48, https://3v4l.org/5mS1U

Or were you thinking about `__DIR__`? That was introduced in 5.3.0, per http://php.net/manual/en/language.constants.predefined.php

andypost’s picture

Yes __DIR__ will fail early

+++ b/core/install.php
@@ -21,11 +22,10 @@
+// The minimum version is specified in the Drupal\Core\Requirements class.
+require_once __DIR__ . '/lib/Drupal/Core/Requirements.php';

@@ -40,5 +40,5 @@
-require_once $root_path . '/core/includes/install.core.inc';
+require_once __DIR__ . '/includes/install.core.inc';

The first one looks better to revert cos it will fail in PHP < 5.3 but in second one we are safe

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

@mpdonadio Nice research. Thank you!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/install.php
    @@ -21,11 +22,10 @@
    +require_once __DIR__ . '/lib/Drupal/Core/Requirements.php';
    +if (version_compare(PHP_VERSION, Requirements::MINIMUM_PHP) < 0) {
       print 'Your PHP installation is too old. Drupal requires at least PHP 5.5.9. See the <a href="https://www.drupal.org/requirements">system requirements</a> page for more information.';
    

    If we're making this configurable we should change the message to use the constant too.

  2. +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php
    @@ -368,6 +368,15 @@ protected function systemListReset() {
    +/**
    + * Minimum supported version of PHP.
    + *
    + * @deprecated in Drupal 8.6.0, will be removed before Drupal 9.0.0. Use
    + *   \Drupal\Core\Requirements::MINIMUM_PHP instead.
    + *
    + * @see https://www.drupal.org/node/2909361
    + */
    + if (!defined('DRUPAL_MINIMUM_PHP')) {
    +   define('DRUPAL_MINIMUM_PHP', '5.3.10');
    + }
    

    can this be removed? If we've replaced all the usages then the test doesn't need to fake it.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Status: Needs review » Needs work

The last submitted patch, 53: 2908079-53.patch, failed testing. View results

voleger’s picture

Issue tags: +Needs reroll

Needs reroll

RoSk0’s picture

Status: Needs work » Needs review
FileSize
16.71 KB

Reroll

RoSk0’s picture

Issue tags: -Needs reroll

Status: Needs review » Needs work

The last submitted patch, 57: drupal-2908079-57.patch, failed testing. View results

voleger’s picture

Status: Needs work » Needs review

Needs review of the patch as all of the tests passed.

claudiu.cristea’s picture

Status: Needs review » Needs work

Nice. Only nits:

  1. +++ b/core/includes/bootstrap.inc
    @@ -22,10 +23,12 @@
    + * @deprecated in Drupal 8.6.0, will be removed before Drupal 9.0.0. Use
    
    @@ -34,10 +37,12 @@
    + * @deprecated in Drupal 8.6.0, will be removed before Drupal 9.0.0. Use
    
    @@ -46,10 +51,12 @@
    + * @deprecated in Drupal 8.6.0, will be removed before Drupal 9.0.0. Use
    

    8.6.0 => 8.7.0. The CR "Introduced in branch" field should be adapted too.

  2. +++ b/core/install.php
    @@ -21,12 +22,11 @@
    +// Checking minimum PHP version to avoid fatal errors.
    +// The minimum version is specified in the Drupal\Core\Requirements class.
    

    According to Drupal API documentation standards (general):

    Lines containing comments (including docblocks) must wrap as close to 80 characters as possible without going over

    So, the beginning 2nd line ("The minimum..") should start on the 1st line.

claudiu.cristea’s picture

Also... in other issue I'm trying to deprecate drupal_set_time_limit() and I'm looking for a place for a new static method that is suppose to replace the procedural function. Could we rename the new class Drupal\Core\Requirements as Drupal\Core\Php, so that we can add there such methods, that are actually setting the PHP environment?

andypost’s picture

I think better to create separate helper class like \Drupal\Component\Utility\Php for wrappers like other utility methods here

claudiu.cristea’s picture

@andypost, usually, components are something that are self contained and make sens outside Drupal. Here's the other issue #3000057: Deprecate drupal_set_time_limit() and file_upload_max_size() and move to Environment component.

Mile23’s picture

@claudiu.cristea: Re: #62, see #4. :-)

claudiu.cristea’s picture

@Mile23, missed that :)

But now, anticipating #3000057: Deprecate drupal_set_time_limit() and file_upload_max_size() and move to Environment component, I think we can reconsider #4?

andypost’s picture

But class Requirements still needed for constants #2909480-5: Move REQUIREMENT_* constants out of install.inc file

voleger’s picture

Status: Needs work » Needs review
FileSize
16.76 KB

rerolled
addressed #61

Status: Needs review » Needs work

The last submitted patch, 68: drupal-2908079-68.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review

Reolled, removed other occurrence from a new tests. Interdiff is against #61.

claudiu.cristea’s picture

Status: Needs review » Needs work

The last submitted patch, 71: 2908079-70.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
16.92 KB

Oops! Forgot to rebase on top of 8.7.x so it needed a new reroll.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Krzysztof Domański’s picture

1. I have removed unnecessary or unrelated changes to this issue (interdiff).
2. I changed recommended PHP version (7.1 -> 7.2) after #3034202: Recommended php version is 7.2 was fixed (re-roll).
3. All occurrences of deprecated constants (DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, DRUPAL_RECOMMENDED_PHP, DRUPAL_MINIMUM_PHP) have been changed/removed.

+1 RTBC

voleger’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

larowlan’s picture

+++ b/core/install.php
@@ -21,12 +22,11 @@
+require_once __DIR__ . '/lib/Drupal/Core/Requirements.php';

why do we need the require_once here? is this for 'stuff is so bad the autoloader is broken'?

voleger’s picture

Looks like that. Autoloader included in a few lines below.

voleger’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
15.39 KB
17.4 KB
4.99 KB

Rerolled.
Added deprecation for DRUPAL_MINIMUM_SUPPORTED_PHP constant.
Fixed deprecation message for DRUPAL_RECOMMENDED_PHP constant.
Moved minimal version check to autoload file.

The last submitted patch, 79: 2908079-79-just-reroll.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

naveenvalecha’s picture

+++ b/core/includes/bootstrap.inc
@@ -27,12 +28,13 @@
+ * @deprecated in Drupal 8.7.x, will be removed before Drupal 9.0.0. Use

Update the deprecated message.
Also, updated the CR to 8.8.0
Also, changed the usage of the DRUPAL_MINIMUM_SUPPORTED_PHP

voleger’s picture

Reroll. No interdiff "Error applying patch1 to reconstructed file"
Current minimum php version is bumped to the 7.0.8 .
Updated Requirements.php minimal version constant value and deprecation messages in bootstrap.inc to meet CS requirements.

Mile23’s picture

Here's a fix for ThemeHandlerTest and ThemeExtensionListTest in a narrower scope: #3054674: ThemeHandlerTest and friends break isolation for constants

Krzysztof Domański’s picture

Status: Needs review » Needs work
Issue tags: +Needs re-roll
voleger’s picture

Status: Needs work » Needs review
FileSize
20.31 KB
20.29 KB
1.76 KB

Conflicts are just in the "use"'s sections that ware changed recently. So just reroll and fix the CS issues with deprecation messages.

There were no new usages of the constants since May...

voleger’s picture

Issue tags: -Needs re-roll
Krzysztof Domański’s picture

+  /**
+   * Minimum supported version of PHP.
+   */
+  const MINIMUM_PHP = '7.0.8';
+  /**
+   * Minimum supported version of PHP.
+   *
+   * Below this version:
+   * - New sites cannot be installed, except from within tests.
+   * - Updates from previous Drupal versions can be run, but users are warned
+   *   that Drupal no longer supports that PHP version.
+   * - An error is shown in the status report that the PHP version is too old.
+   */
+  const MINIMUM_SUPPORTED_PHP = '7.0.8';

1. There are two constants with the same description "Minimum supported version of PHP." IMO MINIMUM_PHP also needs an additional description.

2. Maybe there should be one constant MINIMUM_SUPPORTED_PHP? Is there any difference?

voleger’s picture

+++ b/core/lib/autoloader.php
@@ -0,0 +1,14 @@
+// Checking minimum PHP version to avoid fatal errors.
+if (version_compare(PHP_VERSION, Requirements::MINIMUM_PHP) < 0) {
+ print 'Your PHP installation is too old. Drupal requires at least PHP ' . Requirements::MINIMUM_PHP . '. See the system requirements page for more information.';
+ exit;
+}

+++ b/core/modules/system/system.install
@@ -186,11 +187,11 @@ function system_requirements($phase) {
// Check if the PHP version is below what Drupal supports.
- if (version_compare($phpversion, DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
+ if (version_compare($phpversion, Requirements::MINIMUM_SUPPORTED_PHP) < 0) {
$requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version. It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See PHP\'s version support documentation and the Drupal 8 PHP requirements handbook page for more information.',

Here the difference:
MINIMUM_PHP checked before Drupal bootstrap and do not allow use the Drupal core with not compatible version of PHP

MINIMUM_SUPPORTED_PHP warn the administrator of the usage of outdated and not recommended version of the PHP

voleger’s picture

I think that documentation update we can do at the followup issue at any time, but remove deprecated constant only from the next major release.
Let's move forward and try to replace as much as possible API that left in the legacy includes files.

Krzysztof Domański’s picture

Status: Needs review » Needs work
Issue tags: +Needs re-roll, +Needs followup

1. Needs re-roll.

2. I agree with #89. It's near RTBC! Needs followup due to #87 and #88.

voleger’s picture

Status: Needs work » Needs review
Issue tags: -Needs re-roll
FileSize
20.31 KB

Just reroll

Krzysztof Domański’s picture

voleger’s picture

Added mentions that we also deprecate DRUPAL_MINIMUM_SUPPORTED_PHP constant. Added related issue where this constant was introduced.

Krzysztof Domański’s picture

Status: Needs review » Needs work
voleger’s picture

Noticed that docblock for Requirements::MINIMUM_PHP was outdated in comparison with DRUPAL_MINIMUM_PHP.
So I synchronized the documentation and also keep the same behavior for the request to install.php.

Krzysztof Domański’s picture

voleger’s picture

Issue summary: View changes
Krzysztof Domański’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Test failure at PHP 7 is unrelated. See #96.

Krzysztof Domański’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs re-roll
Krzysztof Domański’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/composer.json
    @@ -180,7 +180,8 @@
    +        "files": ["lib/autoloader.php"]
    

    I think we should reconsider the location and name. The name because it has nothing to do autoloading. I think there is a good case for a file to exist like this. It'd be useful for doing other things like setting up class aliases. The location is also a bit odd because it's going against the README.txt in the same directory. This file is not "autoloadable" per se.

    Also if we do this we need to run $ composer update drupal/core in order to add the changes to composer.lock

    But see next comment. Imo this change should be delegate to a follow-up.

  2. +++ b/core/install.php
    @@ -21,15 +21,6 @@
    -// Exit early if running an incompatible PHP version to avoid fatal errors.
    -// The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not
    -// yet available. It is defined in bootstrap.inc, but it is not possible to
    -// load that file yet as it would cause a fatal error on older versions of PHP.
    -if (version_compare(PHP_VERSION, '7.0.8') < 0) {
    -  print 'Your PHP installation is too old. Drupal requires at least PHP 7.0.8. See the <a href="https://www.drupal.org/requirements">system requirements</a> page for more information.';
    -  exit;
    -}
    

    I think this should be a follow-up and done in this issue. This isn't using a deprecated constant - yes it'd be great if it was but it's out-of-scope for deprecating the constants in boostrap.inc.

  3. +++ b/core/lib/Drupal/Core/Requirements.php
    @@ -0,0 +1,51 @@
    +/**
    + * Defines PHP-related constants for use with Drupal.
    + */
    +final class Requirements {
    

    Great use of final!

voleger’s picture

Status: Needs work » Needs review
FileSize
18.69 KB
1.71 KB

#102.1 and #102.2: Oh, right, we have already an issue regarding the install.php file. So let's introduce that solution in #2910070: Figure out better solution for PHP version check in install.php.
So I'll revert those changes in the current patch as we have no deprecation replacements there. And I will introduce the patch with those changes in #2910070: Figure out better solution for PHP version check in install.php and postpone it on this issue.

Krzysztof Domański’s picture

Status: Needs review » Reviewed & tested by the community

1. #102 was addresed.

2. Needs change record update Global PHP-related constants for minimum values are deprecated.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
18.1 KB
16.45 KB

I've been doing some thinking about this change. Whilst giving this a final review I started wondering why these constants weren't going on \Drupal. In #3 @mile23 wrote

Figuring out where to put these constants is awkward. I don’t like \Drupal in general, and it’s supposed to be about discovering services and not having constants for stuff. So really \Drupal::VERSION is misplaced. (There should be a Drupal\Core\Release class or something.)

I'm not sure that I agree with this. Firstly, \Drupal feels more like an application class that should have these application wide constants on. Secondly, it’s the service location parts of that class that are problematic not the constants.

The solution the current patch comes up with is to add a \Drupal\Core\Requirements class. I think that adding things to core/lib/Drupal/Core needs careful thought or that’s going to become a dumping ground and I'm not sure this belongs there.

I feel that there are 2 solutions:

  • Move these to \Drupal
  • Add a constants.php to our autoloader.

The first has problem that it doesn't solve things like #2909480: Move REQUIREMENT_* constants out of install.inc file (which is also creating a requirements class). The more I think about it the more I like the second because:

  • there's no deprecation
  • the constants become available to autoloaded code
  • as constants.php grows it becomes a place to learn about all the core provided constants

The one downside is this approach is only available to core and not core modules/themes, or contrib or custom because they don't using composer to set up their autoloading. But I'm not sure that outweighs the advantages listed.

I have a patch to move these to \Drupal (attached) but I'm interested in other opinions on the core/constants.php idea.

voleger’s picture

From DX perspective I don't like the idea just to move constants into core/constants.php file as-is. Wrapping constants into a class made them more discoverable during coding in the IDE. So comparing the namespace naming \Drupal::MINIMUM_PHP vs \Drupal\Core\Requirements::MINIMUM_PHP , \Drupal looks more short.

So my proposals are to move constants to the namespaced class, but which one of the namespaces to choose - also interested in other opinions.

alexpott’s picture

From DX perspective I don't like the idea just to move constants into core/constants.php file as-is. Wrapping constants into a class made them more discoverable during coding in the IDE.

IDEs discover global constants just fine in my experience.

alexpott’s picture

Issue summary: View changes
FileSize
137.3 KB

Screenshot evidence for #107
SCreenshot of IDE support for global constants

voleger’s picture

Yes, exactly. That suggests all constant prefixed for different purposes.
Classes create the scope of the constants which can be defined for the specific purpose.

But if we want just to get rid of the include files, it's fine to just move the constant to autoloadable file as is, and then deprecate with removal in Drupal 10.

mpdonadio’s picture

Re #105, what about putting the new constants on core/lib/DrupalInterface or similar? I recall an issue about preferring interfaces for constants because of some weirdness that can happen during autoloading? There are some early comments that allude to this, but memory foggy here.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

daffie’s picture

Version: 8.9.x-dev » 9.1.x-dev
Issue tags: +Needs reroll
daffie’s picture

Status: Needs review » Needs work
Suresh Prabhu Parkala’s picture

Assigned: Unassigned » Suresh Prabhu Parkala
Suresh Prabhu Parkala’s picture

Status: Needs work » Needs review
FileSize
16.75 KB

Done re-roll for 9.1.x. Please review.

voleger’s picture

Status: Needs review » Needs work
+++ b/core/includes/bootstrap.inc
@@ -22,12 +22,13 @@
+ * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use

Versions in the deprecation messages needs to be updated.

jungle’s picture

Re #115 and #116, the patch is for 9.1.x, should not deprecation messages suppose to be removed in 9.x?

andypost’s picture

@jungle current dev is 9.1, it's where we can deprecate for 10.0

jungle’s picture

Status: Needs work » Needs review
FileSize
16.78 KB
1.71 KB

Thanks, @andypost! Versions updated.

Suresh Prabhu Parkala’s picture

Assigned: Suresh Prabhu Parkala » Unassigned
daffie’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll
  1. When I do a code base search for "DRUPAL_MINIMUM_PHP", I still find it in the wrong places like: "core/install.php"
  2. The change as described in the CR is not the same as the one from the patch.
jungle’s picture

Addressing #121.1 and updated min version to 7.3.0/7.3 according to the official documentation here

jungle’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record updates +Needs issue summary update

In order to minimize the need to include files containing constants in the global namespace, four global constants have been deprecated. and moved into core/lib/Drupal.php

Instead of DRUPAL_MINIMUM_PHP, use \Drupal::MINIMUM_PHP instead.
Instead of DRUPAL_MINIMUM_SUPPORTED_PHP, use \Drupal::MINIMUM_SUPPORTED_PHP instead.
Instead of DRUPAL_RECOMMENDED_PHP, use \Drupal::RECOMMENDED_PHP instead.
Instead of DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, use \Drupal::MINIMUM_PHP_MEMORY_LIMIT instead.

CR updated

daffie’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update
daffie’s picture

Issue summary: View changes
jungle’s picture

Issue summary: View changes

Updated API changes section of IS again according to the patch in #122

+++ b/core/includes/bootstrap.inc
@@ -22,12 +22,13 @@
+ *   \Drupal::MINIMUM_PHP instead.

@@ -38,10 +39,12 @@
+ *   \Drupal::MINIMUM_SUPPORTED_PHP instead.

@@ -50,10 +53,12 @@
+ *   \Drupal::RECOMMENDED_PHP instead.

@@ -62,10 +67,12 @@
+ *   \Drupal::MINIMUM_PHP_MEMORY_LIMIT instead.

The namespace/class is \Drupal or Drupal, not Requirements

daffie’s picture

@jungle: Thanks I missed that.

jungle’s picture

Status: Needs review » Needs work
+++ b/core/install.php
@@ -22,7 +22,7 @@
 // Exit early if running an incompatible PHP version to avoid fatal errors.
-// The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not
+// The minimum version is specified explicitly, as \Drupal::MINIMUM_PHP is not
 // yet available. It is defined in bootstrap.inc, but it is not possible to
 // load that file yet as it would cause a fatal error on older versions of PHP.

Self-review, needs updating the inline comment further.

jungle’s picture

Status: Needs work » Needs review
FileSize
18.72 KB
752 bytes

Addressing #128

jungle’s picture

 // Exit early if running an incompatible PHP version to avoid fatal errors.
-if (version_compare(PHP_VERSION, '7.3.0') < 0) {
+if (version_compare(PHP_VERSION, \Drupal::MINIMUM_PHP) < 0) {

Using the new constant.

jungle’s picture

  print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0. See the <a href="https://www.drupal.org/requirements">system requirements</a> page for more information.';
  1. Should use the new constant in the message and update the link

Sorry for so many noises ...

jungle’s picture

Used the URL of Environment requirements of Drupal 9 page's canonical URL, -- node/nid, instead of the alias. In case updating of the alias in the future.

Status: Needs review » Needs work

The last submitted patch, 132: 2908079-132.patch, failed testing. View results

jungle’s picture

Status: Needs work » Needs review
FileSize
19.5 KB
1.05 KB

Move up the autoloader and init it right before using the new constant.

voleger’s picture

Status: Needs review » Needs work
jungle’s picture

Status: Needs work » Needs review

@voleger, thanks for pointing it out. But I do not think it's out of the scope as no remarkable progress on #2910070, and no consent has been reached yet, Meanwhile, the change here does not conflict with finding a better solution for PHP version check -- the scope of #2910070.

I'd set this back to Needs review to get feedback from others, or if you persist on NW, I'm ok to reroll a new patch without touching that part.

daffie’s picture

Status: Needs review » Needs work

Patch looks good. Some remarks:

  1. +++ b/core/install.php
    @@ -21,18 +21,15 @@
    +  print 'Your PHP installation is too old. Drupal requires at least PHP ' . \Drupal::MINIMUM_PHP . '. See the <a href="https://www.drupal.org/node/3053125">Environment requirements of Drupal 9</a> page for more information.';
    

    Can we use the link "https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/..." instead of "https://www.drupal.org/node/3053125".

  2. +++ b/core/modules/system/system.install
    @@ -235,8 +235,8 @@ function system_requirements($phase) {
    +    $requirements['php']['description'] = t('It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support.  See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', ['%recommended' => \Drupal::RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']);
    

    Can we change the link to the Drupal 9 version.

  3. +++ b/core/tests/Drupal/Tests/RequirementsPageTrait.php
    @@ -13,7 +13,7 @@ trait RequirementsPageTrait {
    -    if ($links && version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
    +    if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) {
    

    Why is the variable $links removed from the if-statement. It is not within the scope of this issue.

jungle’s picture

Status: Needs work » Needs review
FileSize
20.15 KB
3.24 KB

Thanks, @daffie for reviewing. Addressing #137

jungle’s picture

FileSize
20.18 KB
931 bytes

let the links be consistent, both having the anchor.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

For #135: I have looked at #2910070: Figure out better solution for PHP version check in install.php and my opinion is that the patch from this issue is in scope.
All the code changes look good to me.
The patch is for me RTBC.

xjm’s picture

Title: Deprecate some of the bootstrap.inc PHP-related constants » Move some of the bootstrap.inc PHP-related constants to \Drupal and deprecate the old versions
xjm’s picture

Couple questions.

  1. +++ b/core/install.php
    @@ -21,18 +21,15 @@
    +// Initialize the autoloader.
    +$class_loader = require_once $root_path . '/autoload.php';
    +
     // Exit early if running an incompatible PHP version to avoid fatal errors.
    -// The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not
    -// yet available. It is defined in bootstrap.inc, but it is not possible to
    -// load that file yet as it would cause a fatal error on older versions of PHP.
    -if (version_compare(PHP_VERSION, '7.3.0') < 0) {
    -  print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0. See the <a href="https://www.drupal.org/requirements">system requirements</a> page for more information.';
    +if (version_compare(PHP_VERSION, \Drupal::MINIMUM_PHP) < 0) {
    +  print 'Your PHP installation is too old. Drupal requires at least PHP ' . \Drupal::MINIMUM_PHP . '. See the <a href="https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/environment-requirements-of-drupal-9#s-php-version-requirement">Environment requirements of Drupal 9</a> page for more information.';
       exit;
     }
     
    -// Initialize the autoloader.
    -$class_loader = require_once $root_path . '/autoload.php';
    -
    

    So, back in the day, the reason we exited early here (before the autoloader was available) was that namespaces weren't supported until PHP 5.3, so on PHP 5.2 and earlier, the installer would whitescreen with a fatal error / no explanation.

    We would get into that situation again here if the autoloader contained any PHP syntax that wasn't compatible with the user's installed version of PHP.

    How will we ensure that the autoloader continues to work on old PHP versions, even if the rest of Drupal doesn't?

  2. +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php
    @@ -156,6 +156,6 @@ public function testValidateTwoThemeDependencies() {
    -if (!defined('DRUPAL_MINIMUM_PHP')) {
    -  define('DRUPAL_MINIMUM_PHP', '7.3.0');
    +if (!defined('\Drupal::MINIMUM_PHP')) {
    +  define('\Drupal::MINIMUM_PHP', '7.3.0');
    

    How are we going to ensure that this hunk doesn't get out of sync again next time?

xjm’s picture

Status: Reviewed & tested by the community » Needs review
xjm’s picture

An alternative approach to moving the autoloader would be to put documentation both on the \Drupal constant and on the exit line in the installer reminding the developer to keep the two in sync.

I don't mean to say moving the autoloader is a no-go -- it might be alright. We should just make sure we're comfortable with the impact it could have if the autoloader's PHP version compatibility changes in the future.

jungle’s picture

Re #142.1 Do not understand, index.php requires the autoload.php at the very first line, if the autoaloader in install.php can go wrong, we should ensure it works in index.php too, but index.php does not do anything for that purpose.

use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

Re #142.2, removed them completely, as it's inside a test file, if the class constant does not present, the test itself should not be detected too, because we are using autoloader. It's redundant to me. Removed them from the following two files:

  1. core/tests/Drupal/Tests/Core/Asset/LibrariesDirectoryFileFinderTest.php
  2. core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php
jungle’s picture

FileSize
20.18 KB
651 bytes
// Variable naming in install.php
$class_loader = require_once $root_path . '/autoload.php';
// Variable naming in index.php.
$autoloader = require_once 'autoload.php';

Keep the variable naming of autoloader in install.php be consistent with which in index.php, rebuild.php, update.php and authorize.php

daffie’s picture

Status: Needs review » Needs work

If I understand @xjm correctly, what she wants is that when somebody who wants to install Drupal with an older version of PHP gets a nice error message instead of a WSOD. When that user is using a PHP version that is lower then 5.3, the that person will get a WSOD when you try to do $class_loader = require_once $root_path . '/autoload.php';. The code change @xjm is looking for is something like:

// Exit early if running an incompatible PHP version to avoid fatal errors.
// The minimum version is specified explicitly, as \Drupal::MINIMUM_PHP is not
// yet available. It is defined in core/lib/Drupal.php, but it is not possible
// to load that file yet as it would cause a fatal error on older versions of
// PHP.
if (version_compare(PHP_VERSION, '7.3.0') < 0) {
  print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0. See the <a href="https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/environment-requirements-of-drupal-9#s-php-version-requirement">Environment requirements of Drupal 9</a> page for more information.';
  exit;
}

// Initialize the autoloader.
$class_loader = require_once $root_path . '/autoload.php';

All the other changes look good to me.

jungle’s picture

@daffie. thanks for your review and explanation!

Addressing #147

daffie’s picture

Status: Needs review » Needs work
  1. +++ b/core/install.php
    @@ -22,16 +22,13 @@
    -  print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0. See the <a href="https://www.drupal.org/requirements">system requirements</a> page for more information.';
    

    The change by replacing "7.3.0" to "\Drupal::MINIMUM_PHP" is wrong, because we have not done the autoload part.

  2. +++ b/core/install.php
    @@ -22,16 +22,13 @@
    -// The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not
    -// yet available. It is defined in bootstrap.inc, but it is not possible to
    -// load that file yet as it would cause a fatal error on older versions of PHP.
    

    You only removing this code. It is the explanation of why we are doing the next couple of lines the way we do it. We need that explanation to be there and it needs to be updated for the change that this issue brings. See my suggestion in comment #147.

jungle’s picture

Thanks again @daffie!

Sorry, missed #149.1.

#149.2, I am adding it back.

jungle’s picture

Please ignore the files uploaded in #150. The comment of this patch in #151, is copied from #147, in case you think it's still better than the improved version in #152 coming next.

jungle’s picture

So, back in the day, the reason we exited early here (before the autoloader was available) was that namespaces weren't supported until PHP 5.3, so on PHP 5.2 and earlier, the installer would whitescreen with a fatal error / no explanation.

The comment in this patch combined the original comment with @xjm's comment in #142

jungle’s picture

Status: Needs work » Needs review
daffie’s picture

Status: Needs review » Reviewed & tested by the community

All the code changes look good to me.
All @xjm's points are addressed.
Back to RTBC.

Tiny nitpick: The dot after "7.3.0" is missing. We are ending a sentence. Can be fixed on commit.

+++ b/core/install.php
@@ -22,16 +22,18 @@
+  print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0 See the <a href="https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/environment-requirements-of-drupal-9#s-php-version-requirement">Environment requirements of Drupal 9</a> page for more information.';

@jungle: Thank you for all your work on this issue!

jungle’s picture

Eagle eyes! @daffie, Thank you!

Adding the missing dot/full stop. meanwhile, adjusted the indentations of the comment.

jungle’s picture

Forgot to upload the patch 🤦

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Thanks @daffie for helping explain what I was asking for. :)

This is looking really close. Only two more pieces of feedback:

  1. +++ b/core/install.php
    @@ -21,17 +21,19 @@
    +// Exit early if running an incompatible PHP version to avoid fatal errors. The
    +// minimum version is specified explicitly, as \Drupal::MINIMUM_PHP is not yet
    +// available. It is defined in core/lib/Drupal.php and it is not possible to
    +// load that file yet because namespaces weren't supported until PHP 5.3, on PHP
    +// 5.2 and earlier, the installer would whitescreen with a fatal error without
    +// explanation.
    
    +++ b/core/lib/Drupal.php
    @@ -92,6 +92,47 @@ class Drupal {
    +  /**
    +   * Minimum allowed version of PHP.
    +   *
    +   * Below this version:
    +   * - The installer cannot be run.
    +   * - Updates cannot be run.
    +   * - Modules and themes cannot be enabled.
    +   * - If a site managed to bypass all of the above, then an error is shown in
    +   *   the status report and various fatal errors occur on various pages.
    +   */
    +  const MINIMUM_PHP = '7.3.0';
    

    We need to add docs in both these places reminding the developer to update the installer requirement here whenever \Drupal::MINIMUM_PHP is updated and vice versa.

  2. +++ b/core/install.php
    @@ -21,17 +21,19 @@
    -$class_loader = require_once $root_path . '/autoload.php';
    +$autoloader = require_once $root_path . '/autoload.php';
    
    @@ -41,4 +43,4 @@
    -install_drupal($class_loader);
    +install_drupal($autoloader);
    

    This change is out of scope.

jungle’s picture

Thanks, @xjm.

Addressing #157

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All points of @xjm are addressed.
All code changes look good.
Back to RTBC.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Thanks, this is almost there. Just a couple grammar fixes:

  1. +++ b/core/install.php
    @@ -27,13 +27,16 @@
     // explanation.
    +//
    +// Note: remember updating the 2 hardcoded PHP minimum version values below once
    +// \Drupal::MINIMUM_PHP gets updated.
    

    I don't think we need to have a second paragraph here; let's continue the paragraph after explanation. "Two" should also be spelled out as a word according to our content standards.

    The grammar also needs a little work. "Remember updating..." would mean the reader had already done it in the past, like "Remember traveling before this pandemic?" "Remember to update" will instruct the reader to do it in the future. :)

    So, all together, I suggest rewriting it like this for clarity:

    ...explanation. Note: Remember to update the hardcoded minimum PHP version below (both in the version_compare() call and in the printed message to the user).

  2. +++ b/core/lib/Drupal.php
    @@ -112,6 +112,11 @@ class Drupal {
    +   * Note: this constant value is hardcoded twice in core/install.php to prevent
    +   * installer running from old PHP versions. One usage is as the parameter of
    +   * version_compare(), the other is in the error message following. Remember
    +   * keeping them in synchronization with here.
    

    Couple small grammar corrections here as well. It should say:

    ...to prevent the installer from running on old PHP versions.

    That said, though, I'd suggest rewriting it a little more for clarity, like this:

    Note: To prevent the installer from having fatal errors on older versions of PHP, the value of this constant is hardcoded twice in core/install.php:
    - Once as a parameter of version_compare()
    - Once in the error message printed to the user immediately after.
    Remember to update both whenever this constant is updated.

Thanks @jungle and @daffie!

jungle’s picture

FileSize
20.35 KB
2.03 KB

Xiexie @xjm!

How I wish that I were a native English speaker :p

jungle’s picture

Status: Needs work » Needs review
daffie’s picture

Status: Needs review » Reviewed & tested by the community

The changes look good to me.
All points of @xjm are addressed.
Back to RTBC.

Sorry @xjm: Both @jungle and me are not native English speakers.

xjm’s picture

:D All good; you both speak English better than I speak any second language. :)

The docblock for the installer still wasn't quite clear enough when I read the whole thing together, so I took a stab at rewriting it myself (attached).

I also clarified the one-line summary for \Drupal::MINIMUM_PHP because the difference between it and \Drupal::MINIMUM_SUPPORTED_PHP was still confusing even with all this added information. It's maybe on the edge of the scope, but if we did it in a followup the docblocks for the new API and the deprecated one would end up out of sync., and it affects how someone might understand the bit in the installer.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

Look fine to me.
Back to RTBC.

jungle’s picture

Based on the fact that DRUPAL_MINIMUM_PHP and DRUPAL_MINIMUM_SUPPORTED_PHP( \Drupal::MINIMUM_PHP and \Drupal::MINIMUM_SUPPORTED_PHP) are identical in the 8.8.x and 9.1.x.

  1. My question is when will they be different? If no key difference, why not merge them into one?
  2. I read the docblock comments, MINIMUM_SUPPORTED_PHP is involved in upgrade. Maybe that's the key difference. But I'm confusing still

Thanks!

xjm’s picture

Thanks @jungle. The constants are the same at the moment, but they weren't in 8.7. This was our way of solving a problem we had for dropping support for PHP 5:

  • A PHP version lower than DRUPAL_MINIMUM_PHP prevents update.php from being run.
  • We needed to drop support for PHP 5 in a minor release, rather than a major release as most people would have expected.
  • About 1/3 of sites update only when there is a new security release.
  • Many sites, especially lower-tier sites where users couldn't control the site hosting environment, were likely to stop updating Drupal rather than try to upgrade their PHP version. That would mean more Drupal sites vulnerable to security issues.
  • And even for sites that might try to update PHP, if they didn't closely follow Drupal news, they might not know about the new PHP version requirement until they needed a security update... and then their site still would be vulnerable until they managed to update PHP.

So, we came up with a plan to phase out PHP 5 support gradually: First, with a warning on the status report (starting in 8.4), second, with a warning in the installer (starting in 8.5), third, with a warning on update.php and an error on the status report and the installer (starting in 8.7), and third, with a hard error on update.php (starting in 8.8). So, we introduced DRUPAL_RECOMMENDED_PHP and DRUPAL_MINIMUM_SUPPORTED_PHP for the first three phases of that.

We also needed to allow Drupal's test suite to continue running without errors on PHP 5.5 and 5.6 during the transition, so we introduced conditional logic in the install and update tests that checked the values of those constants and clicked past the warnings when they were expected on test environments with that PHP version.

We don't need the constants for now, but we might need them again in the future when we want to phase out support for an older PHP version.

This reminds me also that we should increase the value of DRUPAL_RECOMMENDED_PHP to 7.4 for 8.9, since it's going to be supported until 2021.

xjm’s picture

I posted #3135250: [8.9 only] Increase recommended PHP version to 7.3 prior to release which will require a simple reroll here (or vice versa).

jungle’s picture

Issue tags: +Needs reroll

@xjm, many thanks for your detailed explanation, putting a needs reroll against 8.9.x as #3135250: [8.9 only] Increase recommended PHP version to 7.3 prior to release landed.

jungle’s picture

Rerolled a patch from #164 against 9.1.x. Removing the "Needs reroll" tag, to do it after the 9.1.x patch gets committed.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php
@@ -167,7 +167,7 @@ public function testPhpRequirement() {
-    $this->assertStringContainsString(DRUPAL_MINIMUM_SUPPORTED_PHP, $error_output);
+    $this->assertContains(\Drupal::MINIMUM_SUPPORTED_PHP, $error_output);

We should still be using $this->assertStringContainsString() - this is reverting another change.

jungle’s picture

daffie’s picture

Status: Needs review » Reviewed & tested by the community

Addressed the point from @alexpott.
No other occurrences of that kind.
Back to RTBC.

jungle’s picture

Needs re-roll if #3151118: Include bootstrap.inc using composer lands first. Or this is won't fix?

alexpott’s picture

Well if #3151118: Include bootstrap.inc using composer lands we could debate whether do this deprecation is actually worth it. I'm not sure it is.

  • xjm committed 29b2451 on 9.1.x
    Issue #2908079 by jungle, voleger, mpdonadio, zahord, andypost, RoSk0,...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 9.1.x, thanks! (My only contribution to the patch directly was some English grammar rewriting stuff, so still seems fine for me to commit it.)

xjm’s picture

Also published the CR.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.