From e66d964c7d767c3b2722f66a76a690a0625a2075 Mon Sep 17 00:00:00 2001 From: GabrielBragaGit <65824599+GabrielBragaGit@users.noreply.github.com> Date: Mon, 30 Dec 2024 00:01:59 -0300 Subject: [PATCH] Modernization: Replace Deprecated `each()` Function #### Description Updated `tln_fixatts` method to use modern PHP iteration syntax, removing deprecated `each()` function. #### Details - Replaced `each()` with `foreach` loop - Added type safety for input array - Maintained original method logic - Ensures compatibility with PHP 7.2+ and PHP 8.0+ - Improved loop control with `continue 2` #### Code Change ```php // Before while ([$attname, $attvalue] = each($attary)) { // Processing logic } // After foreach ($attary as $attname => $attvalue) { // Processing logic with continue 2 } ### Rationale - each() function is deprecated and removed in newer PHP versions - foreach provides a more modern and readable way to iterate arrays - continue 2 ensures proper loop control when removing attributes - Immediately exits both inner and outer loops - Prevents unnecessary iteration after attribute removal - Improves code maintainability and compatibility ### Loop Control Explanation - Simple continue would only exit the inner loop - continue 2 completely exits nested loops - Ensures we move to the next attribute after removal - Prevents potential side effects of partial loop execution --- packages/Webkul/Email/src/Helpers/Htmlfilter.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/Webkul/Email/src/Helpers/Htmlfilter.php b/packages/Webkul/Email/src/Helpers/Htmlfilter.php index 76404b722..73bd48afc 100644 --- a/packages/Webkul/Email/src/Helpers/Htmlfilter.php +++ b/packages/Webkul/Email/src/Helpers/Htmlfilter.php @@ -560,7 +560,12 @@ public function tln_fixatts( $trans_image_path, $block_external_images ) { - while ([$attname, $attvalue] = each($attary)) { + /** + * Convert to array if is not + */ + $attary = is_array($attary) ? $attary : []; + + foreach ($attary as $attname => $attvalue) { /** * See if this attribute should be removed. */ @@ -570,7 +575,7 @@ public function tln_fixatts( if (preg_match($matchattr, $attname)) { unset($attary[$attname]); - continue; + continue 2; } } }