From cc00e0eb7897ced1ac54e2f806a8228dcfa30277 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Tue, 16 Feb 2021 08:35:30 +0100 Subject: [PATCH] [String] Check if function exists before declaring it --- .../Component/String/Resources/functions.php | 32 +++++++++++-------- .../Translation/Resources/functions.php | 14 ++++---- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Component/String/Resources/functions.php b/src/Symfony/Component/String/Resources/functions.php index a60e2ce08c..c950894f39 100644 --- a/src/Symfony/Component/String/Resources/functions.php +++ b/src/Symfony/Component/String/Resources/functions.php @@ -11,22 +11,28 @@ namespace Symfony\Component\String; -function u(?string $string = ''): UnicodeString -{ - return new UnicodeString($string ?? ''); +if (!\function_exists(u::class)) { + function u(?string $string = ''): UnicodeString + { + return new UnicodeString($string ?? ''); + } } -function b(?string $string = ''): ByteString -{ - return new ByteString($string ?? ''); +if (!\function_exists(b::class)) { + function b(?string $string = ''): ByteString + { + return new ByteString($string ?? ''); + } } -/** - * @return UnicodeString|ByteString - */ -function s(?string $string = ''): AbstractString -{ - $string = $string ?? ''; +if (!\function_exists(s::class)) { + /** + * @return UnicodeString|ByteString + */ + function s(?string $string = ''): AbstractString + { + $string = $string ?? ''; - return preg_match('//u', $string) ? new UnicodeString($string) : new ByteString($string); + return preg_match('//u', $string) ? new UnicodeString($string) : new ByteString($string); + } } diff --git a/src/Symfony/Component/Translation/Resources/functions.php b/src/Symfony/Component/Translation/Resources/functions.php index 7ce806b7d1..901d2f87ef 100644 --- a/src/Symfony/Component/Translation/Resources/functions.php +++ b/src/Symfony/Component/Translation/Resources/functions.php @@ -11,10 +11,12 @@ namespace Symfony\Component\Translation; -/** - * @author Nate Wiebe - */ -function t(string $message, array $parameters = [], string $domain = null): TranslatableMessage -{ - return new TranslatableMessage($message, $parameters, $domain); +if (!\function_exists(t::class)) { + /** + * @author Nate Wiebe + */ + function t(string $message, array $parameters = [], string $domain = null): TranslatableMessage + { + return new TranslatableMessage($message, $parameters, $domain); + } }