PHP Version on Status Report Shows Potentially Misleading Information

Created on 25 August 2019, almost 6 years ago
Updated 28 May 2025, 1 day ago

Problem/Motivation

The status report general information should show system information but instead shows module runtime requirements, which can be misleading for PHP version if a module defines a minimum requirement.

In core/modules/system/system.routing.yml:

system.status:
 path: '/admin/reports/status'
 defaults:
   _controller: '\Drupal\system\Controller\SystemInfoController::status'
   _title: 'Status report'
 requirements:
   _permission: 'administer site configuration'

status() in core/modules/system/src/Controller/SystemInfoController.php:

 /**
  * Displays the site status report.
  *
  * @return array
  *   A render array containing a list of system requirements for the Drupal
  *   installation and whether this installation meets the requirements.
  */
 public function status() {
   $requirements = $this->systemManager->listRequirements();
   return ['#type' => 'status_report_page', '#requirements' => $requirements];
 }

listRequirements() in core/modules/system/src/SystemManager.php:

 /**
  * Displays the site status report. Can also be used as a pure check.
  *
  * @return array
  *   An array of system requirements.
  */
 public function listRequirements() {
   // Load .install files
   include_once DRUPAL_ROOT . '/core/includes/install.inc';
   drupal_load_updates();

   // Check run-time requirements and status information.
   $requirements = $this->moduleHandler->invokeAll('requirements', ['runtime']);
   uasort($requirements, function ($a, $b) {
     if (!isset($a['weight'])) {
       if (!isset($b['weight'])) {
         return strcasecmp($a['title'], $b['title']);
       }
       return -$b['weight'];
     }
     return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
   });

   return $requirements;
 }

If a given module requires a specific version of PHP, such as in https://www.drupal.org/project/trailing_slash/issues/3016988 β†’ , then the status report will show 7.1 even if 7.2+ is actively running.

In trailing_slash/trailing_slash.install:

/**
* Implements hook_requirements().
*/
function trailing_slash_requirements($phase) {
 $requirements = [];
 $requirements['php'] = [
   'title' => t('PHP'),
   'value' => TRAILING_SLASH_MINIMUM_PHP,
 ];

 if (version_compare(phpversion(), TRAILING_SLASH_MINIMUM_PHP) < 0) {
   $requirements['php']['description'] = t('Your PHP installation is too old. This module requires at least PHP %version.', [
     '%version' => TRAILING_SLASH_MINIMUM_PHP,
   ]);
   $requirements['php']['severity'] = REQUIREMENT_ERROR;
 }
 return $requirements;
}

In trailing_slash/trailing_slash.module:

<?php

use Drupal\Core\Routing\RouteMatchInterface;

define('TRAILING_SLASH_MINIMUM_PHP', '7.1');

In trailing_slash/trailing_slash.info.yml:

name: Trailing Slash
description: Adds trailing slashes to Drupal URLs.
type: module
# core: 8.x
dependencies:
  - drupal:language
php: 7.1

# Information added by Drupal.org packaging script on 2018-09-07
version: '8.x-1.0'
core: '8.x'
project: 'trailing_slash'
datestamp: 1536320883

Proposed resolution

Could this check be switched to pull information from another source, perhaps from the phpinfo() function as output in /admin/reports/status/php?

Remaining tasks

  • Determine if this behavior is intended/preferred
  • Adjust the source of the PHP version check
  • Write tests
πŸ› Bug report
Status

Closed: works as designed

Version

11.0 πŸ”₯

Component

system.module

Created by

πŸ‡ΊπŸ‡ΈUnited States dan612 Portland, Maine

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    I think the issue is that the trailing slash module is overriding the core requirements. The $requirements['php'] value set by system.module sets the requirement for Drupal core. The trailing slash module should define its own requirement, or should change the description to mention that it's required for that particular module.

Production build 0.71.5 2024