Skip to content

Commit 71edcc9

Browse files
authored
Merge pull request #6327 from kenjis/fix-php-version-check
fix: Parse error occurs before PHP version check
2 parents 4df89ed + 6ac3a7b commit 71edcc9

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

public/index.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
<?php
22

3+
// Check PHP version.
4+
$minPhpVersion = '7.4'; // If you update this, don't forget to update `spark`.
5+
if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
6+
$message = sprintf(
7+
'Your PHP version must be %s or higher to run CodeIgniter. Current version: %s',
8+
$minPhpVersion,
9+
PHP_VERSION
10+
);
11+
12+
exit($message);
13+
}
14+
315
// Path to the front controller (this file)
416
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);
517

spark

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ if (strpos(PHP_SAPI, 'cgi') === 0) {
2626
exit("The cli tool is not supported when running php-cgi. It needs php-cli to function!\n\n");
2727
}
2828

29+
// Check PHP version.
30+
$minPhpVersion = '7.4'; // If you update this, don't forget to update `public/index.php`.
31+
if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
32+
$message = sprintf(
33+
'Your PHP version must be %s or higher to run CodeIgniter. Current version: %s',
34+
$minPhpVersion,
35+
PHP_VERSION
36+
);
37+
38+
exit($message);
39+
}
40+
2941
// We want errors to be shown when using it from the CLI.
3042
error_reporting(-1);
3143
ini_set('display_errors', '1');

system/CodeIgniter.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ class CodeIgniter
4949
*/
5050
public const CI_VERSION = '4.2.1';
5151

52-
private const MIN_PHP_VERSION = '7.4';
53-
5452
/**
5553
* App startup time.
5654
*
@@ -158,16 +156,6 @@ class CodeIgniter
158156
*/
159157
public function __construct(App $config)
160158
{
161-
if (version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '<')) {
162-
// @codeCoverageIgnoreStart
163-
$message = extension_loaded('intl')
164-
? lang('Core.invalidPhpVersion', [self::MIN_PHP_VERSION, PHP_VERSION])
165-
: sprintf('Your PHP version must be %s or higher to run CodeIgniter. Current version: %s', self::MIN_PHP_VERSION, PHP_VERSION);
166-
167-
exit($message);
168-
// @codeCoverageIgnoreEnd
169-
}
170-
171159
$this->startTime = microtime(true);
172160
$this->config = $config;
173161
}
@@ -962,6 +950,7 @@ protected function display404errors(PageNotFoundException $e)
962950
ob_end_flush(); // @codeCoverageIgnore
963951
}
964952

953+
// Throws new PageNotFoundException and remove exception message on production.
965954
throw PageNotFoundException::forPageNotFound(
966955
(ENVIRONMENT !== 'production' || ! $this->isWeb()) ? $e->getMessage() : null
967956
);

0 commit comments

Comments
 (0)