Skip to content

Commit 1e6f5ef

Browse files
xurshudyanXurshudyan
andauthored
Ensure withLocale and withCurrency always restore previous state (#56234)
Co-authored-by: Xurshudyan <[email protected]>
1 parent 236b667 commit 1e6f5ef

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Illuminate/Support/Number.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@ public static function withLocale(string $locale, callable $callback)
353353

354354
static::useLocale($locale);
355355

356-
return tap($callback(), fn () => static::useLocale($previousLocale));
356+
try {
357+
return $callback();
358+
} finally {
359+
static::useLocale($previousLocale);
360+
}
357361
}
358362

359363
/**
@@ -369,7 +373,11 @@ public static function withCurrency(string $currency, callable $callback)
369373

370374
static::useCurrency($currency);
371375

372-
return tap($callback(), fn () => static::useCurrency($previousCurrency));
376+
try {
377+
return $callback();
378+
} finally {
379+
static::useCurrency($previousCurrency);
380+
}
373381
}
374382

375383
/**

0 commit comments

Comments
 (0)