Skip to content

Commit 17a0fe7

Browse files
committed
feature #13119 [String] Documented the s() function (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- [String] Documented the s() function Fixes #13068. Commits ------- 850c347 [String] Documented the s() function
2 parents 51f8477 + 850c347 commit 17a0fe7

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

components/string.rst

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,35 @@ Use the ``wrap()`` static method to instantiate more than one string object::
9999
new UnicodeString('hello'), new UnicodeString('world'),
100100
]); // $contents = ['hello', 'world']
101101

102-
There are two shortcut functions called ``b()`` and ``u()`` to create
103-
``ByteString`` and ``UnicodeString`` objects::
102+
If you work with lots of String objects, consider using the shortcut functions
103+
to make your code more concise::
104104

105-
// ...
105+
// the b() function creates byte strings
106106
use function Symfony\Component\String\b;
107-
use function Symfony\Component\String\u;
108107

109-
// both are equivalent
108+
// both lines are equivalent
110109
$foo = new ByteString('hello');
111110
$foo = b('hello');
112111

113-
// both are equivalent
114-
$baz = new UnicodeString('hello');
115-
$baz = u('hello');
112+
// the u() function creates Unicode strings
113+
use function Symfony\Component\String\u;
114+
115+
// both lines are equivalent
116+
$foo = new UnicodeString('hello');
117+
$foo = u('hello');
118+
119+
// the s() function creates a byte string or Unicode string
120+
// depending on the given contents
121+
use function Symfony\Component\String\u;
122+
123+
// creates a ByteString object
124+
$foo = s('\xfe\xff');
125+
// creates a UnicodeString object
126+
$foo = s('अनुच्छेद');
127+
128+
.. versionadded:: 5.1
129+
130+
The ``s()`` function was introduced in Symfony 5.1.
116131

117132
There are also some specialized constructors::
118133

0 commit comments

Comments
 (0)