Skip to content
Merged
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 @@ -110,6 +110,11 @@ public function testExecuteWhenParamsAsPrimitives()
(new Mysql($this->adapterMock, $query))->_execute($params);
}

/**
* Test execute method when params are passed as Parameter objects.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function testExecuteWhenParamsAsParameterObject()
{
$param1 = $this->createMock(Parameter::class);
Expand Down Expand Up @@ -189,10 +194,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;
}
}