8000 bug #34011 [String] Add AbstractString::toString() method (simPod) · symfony/symfony@e28bc78 · GitHub
[go: up one dir, main page]

Skip to content

Commit e28bc78

Browse files
bug #34011 [String] Add AbstractString::toString() method (simPod)
This PR was merged into the 5.0-dev branch. Discussion ---------- [String] Add AbstractString::toString() method | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Deprecations? | no | License | MIT Adds a way to use String in an objective way, without typecasting -> calling magical `__toString()`. Before ```php $value = (string) (new UnicodeString('foobar')) ->repeat(2) ->lower(); ``` After also possible ```php $value = (new UnicodeString('foobar')) ->repeat(2) ->lower() ->toString(); ``` Commits ------- 5540bc7 Add toString() method for String
2 parents 27a2d8a + 5540bc7 commit e28bc78

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Symfony/Component/String/AbstractString.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ public function toCodePointString(): CodePointString
589589
return new CodePointString($this->string);
590590
}
591591

592+
public function toString(): string
593+
{
594+
return $this->string;
595+
}
596+
592597
public function toUnicodeString(): UnicodeString
593598
{
594599
return new UnicodeString($this->string);

src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,4 +1370,11 @@ public static function provideTruncate()
13701370
['fo...', 'foobar', 5, '...'],
13711371
];
13721372
}
1373+
1374+
public function testToString()
1375+
{
1376+
$instance = static::createFromString('foobar');
1377+
1378+
self::assertSame('foobar', $instance->toString());
1379+
}
13731380
}

0 commit comments

Comments
 (0)
0