Skip to content

Commit 850c347

Browse files
committed
[String] Documented the s() function
1 parent ec50b76 commit 850c347

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
@@ -104,20 +104,35 @@ Use the ``wrap()`` static method to instantiate more than one string object::
104104
new UnicodeString('hello'), new UnicodeString('world'),
105105
]); // $contents = ['hello', 'world']
106106

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

110-
// ...
110+
// the b() function creates byte strings
111111
use function Symfony\Component\String\b;
112-
use function Symfony\Component\String\u;
113112

114-
// both are equivalent
113+
// both lines are equivalent
115114
$foo = new ByteString('hello');
116115
$foo = b('hello');
117116

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

122137
There are also some specialized constructors::
123138

0 commit comments

Comments
 (0)