Skip to content

Remove legacy compatibility code for PHP versions < 8.1 #39882

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

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
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
15 changes: 2 additions & 13 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
}
#ini_set('display_errors', 1);

/* PHP version validation */
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 80100) {
if (PHP_SAPI == 'cli') {
if (PHP_VERSION_ID < 80100) {
if (PHP_SAPI === 'cli') {
echo 'Magento supports PHP 8.1.0 or later. ' .
'Please read https://experienceleague.adobe.com/docs/commerce-operations/installation-guide/system-requirements.html';
} else {
Expand All @@ -31,16 +30,6 @@
exit(1);
}

// PHP 8 compatibility. Define constants that are not present in PHP < 8.0
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 80000) {
if (!defined('T_NAME_QUALIFIED')) {
define('T_NAME_QUALIFIED', 24001);
}
if (!defined('T_NAME_FULLY_QUALIFIED')) {
define('T_NAME_FULLY_QUALIFIED', 24002);
}
}

require_once __DIR__ . '/autoload.php';
// Sets default autoload mappings, may be overridden in Bootstrap::create
\Magento\Framework\App\Bootstrap::populateAutoloader(BP, []);
Expand Down
9 changes: 0 additions & 9 deletions dev/tests/static/framework/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@
define('TESTS_TEMP_DIR', dirname(__DIR__) . '/tmp');
}

// PHP 8 compatibility. Define constants that are not present in PHP < 8.0
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 80000) {
if (!defined('T_NAME_QUALIFIED')) {
define('T_NAME_QUALIFIED', 24001);
}
if (!defined('T_NAME_FULLY_QUALIFIED')) {
define('T_NAME_FULLY_QUALIFIED', 24002);
}
}

setCustomErrorHandler();

Expand Down
12 changes: 1 addition & 11 deletions dev/tests/unit/framework/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@
define('TESTS_TEMP_DIR', dirname(__DIR__) . '/tmp');
}

// PHP 8 compatibility. Define constants that are not present in PHP < 8.0
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 80000) {
if (!defined('T_NAME_QUALIFIED')) {
define('T_NAME_QUALIFIED', 24001);
}
if (!defined('T_NAME_FULLY_QUALIFIED')) {
define('T_NAME_FULLY_QUALIFIED', 24002);
}
}

require_once __DIR__ . '/autoload.php';

setCustomErrorHandler();
Expand Down Expand Up @@ -59,7 +49,7 @@ function ($errNo, $errStr, $errFile, $errLine) {
E_USER_DEPRECATED => 'User Deprecated',
];

$errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
$errName = $errorNames[$errNo] ?? "";

throw new \PHPUnit\Framework\Exception(
sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2016 Adobe
* All rights reserved.
*/
namespace Magento\Framework\DB\DataConverter;

Expand Down Expand Up @@ -95,36 +95,21 @@ protected function unserializeValue($value)
/**
* Encode value with json encoder.
*
* In PHP version < 7.1.0 serialize() uses PG(serialize_precision) which set to 17 be default.
* Since json_encode() uses EG(precision) which set to 14 be default, json_encode() removes lower digits of
* fraction parts and destroys original value even if PHP's float could hold more precise float value.
* To prevent this issue EG(precision) is set to 17 to be equal with PG(serialize_precision) during
* data converting from serialized format to JSON.
*
* In PHP version >= 7.1.0 serialize() and json_encode() use PG(serialize_precision) which set to -1 be default.
* Setting -1 uses better algorithm for rounding float numbers.
* But for data consistency during converting process PG(serialize_precision) is set to 17.
* For data consistency during converting process PG(serialize_precision) is set to 17.
*
* @param string $value
* @return string
* @throws DataConversionException
*/
protected function encodeJson($value)
{
$storedPrecision = ini_get('precision');
$storedSerializePrecision = ini_get('serialize_precision');

if (PHP_VERSION_ID < 70100) {
// In PHP version < 7.1.0 json_encode() uses EG(precision).
ini_set('precision', 17);
} else {
// In PHP version >= 7.1.0 json_encode() uses PG(serialize_precision).
ini_set('serialize_precision', 17);
}
// In PHP 8.1+ json_encode() uses PG(serialize_precision)
ini_set('serialize_precision', 17);

$value = $this->json->serialize($value);

ini_set('precision', $storedPrecision);
ini_set('serialize_precision', $storedSerializePrecision);

if (json_last_error()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All rights reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -189,10 +189,7 @@ private function setQueryStringForPdoStmtMock(string $query): void
/*
* In PHP 8.1 $queryString is a Typed property, thus it should be initialized before the 1st call.
* But it's not automatically initialized in case of Mocking, so we do it here.
* Note: In PHP < 8.1 such assignment prohibited.
*/
if (PHP_VERSION_ID >= 80100) {
$this->pdoStatementMock->queryString = $query;
}
$this->pdoStatementMock->queryString = $query;
}
}