Skip to content

Commit 4e78d7d

Browse files
Nyholmnicolas-grekas
authored andcommitted
[String] Check if function exists before declaring it
1 parent c954688 commit 4e78d7d

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

Resources/functions.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,28 @@
1111

1212
namespace Symfony\Component\String;
1313

14-
function u(?string $string = ''): UnicodeString
15-
{
16-
return new UnicodeString($string ?? '');
14+
if (!\function_exists(u::class)) {
15+
function u(?string $string = ''): UnicodeString
16+
{
17+
return new UnicodeString($string ?? '');
18+
}
1719
}
1820

19-
function b(?string $string = ''): ByteString
20-
{
21-
return new ByteString($string ?? '');
21+
if (!\function_exists(b::class)) {
22+
function b(?string $string = ''): ByteString
23+
{
24+
return new ByteString($string ?? '');
25+
}
2226
}
2327

24-
/**
25-
* @return UnicodeString|ByteString
26-
*/
27-
function s(?string $string = ''): AbstractString
28-
{
29-
$string = $string ?? '';
28+
if (!\function_exists(s::class)) {
29+
/**
30+
* @return UnicodeString|ByteString
31+
*/
32+
function s(?string $string = ''): AbstractString
33+
{
34+
$string = $string ?? '';
3035

31-
return preg_match('//u', $string) ? new UnicodeString($string) : new ByteString($string);
36+
return preg_match('//u', $string) ? new UnicodeString($string) : new ByteString($string);
37+
}
3238
}

0 commit comments

Comments
 (0)