Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Parse error occurs before PHP version check #6327

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

// Check PHP version.
$minPhpVersion = '7.4'; // If you update this, don't forget to update `spark`.
if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
$message = sprintf(
'Your PHP version must be %s or higher to run CodeIgniter. Current version: %s',
$minPhpVersion,
PHP_VERSION
);

exit($message);
}

// Path to the front controller (this file)
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);

Expand Down
12 changes: 12 additions & 0 deletions spark
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ if (strpos(PHP_SAPI, 'cgi') === 0) {
exit("The cli tool is not supported when running php-cgi. It needs php-cli to function!\n\n");
}

// Check PHP version.
$minPhpVersion = '7.4'; // If you update this, don't forget to update `public/index.php`.
if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
$message = sprintf(
'Your PHP version must be %s or higher to run CodeIgniter. Current version: %s',
$minPhpVersion,
PHP_VERSION
);

exit($message);
}

// We want errors to be shown when using it from the CLI.
error_reporting(-1);
ini_set('display_errors', '1');
Expand Down
13 changes: 1 addition & 12 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class CodeIgniter
*/
public const CI_VERSION = '4.2.1';

private const MIN_PHP_VERSION = '7.4';

/**
* App startup time.
*
Expand Down Expand Up @@ -158,16 +156,6 @@ class CodeIgniter
*/
public function __construct(App $config)
{
if (version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '<')) {
// @codeCoverageIgnoreStart
$message = extension_loaded('intl')
? lang('Core.invalidPhpVersion', [self::MIN_PHP_VERSION, PHP_VERSION])
: sprintf('Your PHP version must be %s or higher to run CodeIgniter. Current version: %s', self::MIN_PHP_VERSION, PHP_VERSION);

exit($message);
// @codeCoverageIgnoreEnd
}

$this->startTime = microtime(true);
$this->config = $config;
}
Expand Down Expand Up @@ -962,6 +950,7 @@ protected function display404errors(PageNotFoundException $e)
ob_end_flush(); // @codeCoverageIgnore
}

// Throws new PageNotFoundException and remove exception message on production.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this got scooped up by mistake?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes. It is not related to this PR.

throw PageNotFoundException::forPageNotFound(
(ENVIRONMENT !== 'production' || ! $this->isWeb()) ? $e->getMessage() : null
);
Expand Down