@@ -104,20 +104,35 @@ Use the ``wrap()`` static method to instantiate more than one string object::
104
104
new UnicodeString('hello'), new UnicodeString('world'),
105
105
]); // $contents = ['hello', 'world']
106
106
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 ::
109
109
110
- // ...
110
+ // the b() function creates byte strings
111
111
use function Symfony\Component\String\b;
112
- use function Symfony\Component\String\u;
113
112
114
- // both are equivalent
113
+ // both lines are equivalent
115
114
$foo = new ByteString('hello');
116
115
$foo = b('hello');
117
116
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.
121
136
122
137
There are also some specialized constructors::
123
138
0 commit comments