Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7dcf156

Browse filesBrowse files
bug #40203 [String] Check if function exists before declaring it (Nyholm)
This PR was squashed before being merged into the 5.2 branch. Discussion ---------- [String] Check if function exists before declaring it | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | If you installed a command line tool like `psalm` with composer and then try to run it on a project that included the String component you will get an error like: > Fatal error: Cannot redeclare Symfony\Component\String\u() (previously declared in /Workspace/symfony/src/Symfony/Component/String/Resources/functions.php:14) in /user/.composer/vendor/symfony/string/Resources/functions.php on line 14 That is because we are loading two installations of the string component. Commits ------- cc00e0e [String] Check if function exists before declaring it
2 parents 00b4b76 + cc00e0e commit 7dcf156
Copy full SHA for 7dcf156

File tree

Expand file treeCollapse file tree

2 files changed

+27
-19
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-19
lines changed

‎src/Symfony/Component/String/Resources/functions.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/String/Resources/functions.php
+19-13Lines 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
}

‎src/Symfony/Component/Translation/Resources/functions.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Resources/functions.php
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
namespace Symfony\Component\Translation;
1313

14-
/**
15-
* @author Nate Wiebe <nate@northern.co>
16-
*/
17-
function t(string $message, array $parameters = [], string $domain = null): TranslatableMessage
18-
{
19-
return new TranslatableMessage($message, $parameters, $domain);
14+
if (!\function_exists(t::class)) {
15+
/**
16+
* @author Nate Wiebe <nate@northern.co>
17+
*/
18+
function t(string $message, array $parameters = [], string $domain = null): TranslatableMessage
19+
{
20+
return new TranslatableMessage($message, $parameters, $domain);
21+
}
2022
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.