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

Adds polyfills for PHP 7.4-8.1 #2946

Merged
merged 1 commit into from
Jan 16, 2023
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
110 changes: 0 additions & 110 deletions app/code/core/Mage/Core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,113 +327,3 @@ function is_dir_writeable($dir)
}
return false;
}

if (!function_exists('sys_get_temp_dir')) {
// Based on http://www.phpit.net/
// article/creating-zip-tar-archives-dynamically-php/2/
/**
* @return bool|string
*/
function sys_get_temp_dir()
{
// Try to get from environment variable
if (!empty($_ENV['TMP'])) {
return realpath($_ENV['TMP']);
} elseif (!empty($_ENV['TMPDIR'])) {
return realpath($_ENV['TMPDIR']);
} elseif (!empty($_ENV['TEMP'])) {
return realpath($_ENV['TEMP']);
} else {
// Try to use system's temporary directory
// as random name shouldn't exist
$temp_file = tempnam(md5(uniqid(rand(), true)), '');
if ($temp_file) {
$temp_dir = realpath(dirname($temp_file));
unlink($temp_file);
return $temp_dir;
} else {
return false;
}
}
}
}

if (!function_exists('hash_equals')) {
/**
* Compares two strings using the same time whether they're equal or not.
* A difference in length will leak
*
* @param string $known_string
* @param string $user_string
* @return bool Returns true when the two strings are equal, false otherwise.
*/
function hash_equals($known_string, $user_string)
{
$result = 0;

if (!is_string($known_string)) {
trigger_error("hash_equals(): Expected known_string to be a string", E_USER_WARNING);
return false;
}

if (!is_string($user_string)) {
trigger_error("hash_equals(): Expected user_string to be a string", E_USER_WARNING);
return false;
}

if (strlen($known_string) != strlen($user_string)) {
return false;
}

for ($i = 0; $i < strlen($known_string); $i++) {
$result |= (ord($known_string[$i]) ^ ord($user_string[$i]));
}

return $result === 0;
}
}

/**
* polyfill for PHP 8.0 function "str_contains"
*/
if (!function_exists('str_contains')) {
/**
* @param string $haystack
* @param string $needle
* @return bool
*/
function str_contains($haystack, $needle)
{
return $needle === '' || strpos($haystack, $needle) !== false;
}
}

/**
* polyfill for PHP 8.0 function "str_starts_with"
*/
if (!function_exists('str_starts_with')) {
/**
* @param string $haystack
* @param string $needle
* @return bool
*/
function str_starts_with($haystack, $needle)
{
return strncmp($haystack, $needle, \strlen($needle)) === 0;
}
}

/**
* polyfill for PHP 8.0 function "str_ends_with"
*/
if (!function_exists('str_ends_with')) {
/**
* @param string $haystack
* @param string $needle
* @return bool
*/
function str_ends_with($haystack, $needle)
{
return $needle === '' || ($haystack !== '' && substr_compare($haystack, $needle, -\strlen($needle)) === 0);
}
}
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
"pelago/emogrifier": "^7.0",
"phpseclib/mcrypt_compat": "^2.0.3",
"phpseclib/phpseclib": "^3.0.14",
"shardj/zf1-future": "^1.21"
"shardj/zf1-future": "^1.21",
"symfony/polyfill-php74": "^1.27",
"symfony/polyfill-php80": "^1.27",
"symfony/polyfill-php81": "^1.27"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
Expand Down
82 changes: 81 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.