@@ -189,11 +189,15 @@ public static function replaceCallbackArray(array $pattern, $subject, $limit = -
189
189
* @param string $pattern
190
190
* @param string $subject
191
191
* @param int $limit
192
- * @param int $flags
192
+ * @param int $flags PREG_SPLIT_NO_EMPTY or PREG_SPLIT_DELIM_CAPTURE
193
193
* @return list<string>
194
194
*/
195
195
public static function split ($ pattern , $ subject , $ limit = -1 , $ flags = 0 )
196
196
{
197
+ if (($ flags & PREG_SPLIT_OFFSET_CAPTURE ) !== 0 ) {
198
+ throw new \InvalidArgumentException ('PREG_SPLIT_OFFSET_CAPTURE is not supported as it changes the type of $matches, use splitWithOffset() instead ' );
199
+ }
200
+
197
201
$ result = preg_split ($ pattern , $ subject , $ limit , $ flags );
198
202
if ($ result === false ) {
199
203
throw PcreException::fromFunction ('preg_split ' , $ pattern );
@@ -202,6 +206,24 @@ public static function split($pattern, $subject, $limit = -1, $flags = 0)
202
206
return $ result ;
203
207
}
204
208
209
+ /**
210
+ * @param string $pattern
211
+ * @param string $subject
212
+ * @param int $limit
213
+ * @param int $flags PREG_SPLIT_NO_EMPTY or PREG_SPLIT_DELIM_CAPTURE
214
+ * @return list<array{string, int}>
215
+ * @phpstan-return list<array{string, int<0, max>}>
216
+ */
217
+ public static function splitWithOffset ($ pattern , $ subject , $ limit = -1 , $ flags = 0 )
218
+ {
219
+ $ result = preg_split ($ pattern , $ subject , $ limit , $ flags | PREG_SPLIT_OFFSET_CAPTURE );
220
+ if ($ result === false ) {
221
+ throw PcreException::fromFunction ('preg_split ' , $ pattern );
222
+ }
223
+
224
+ return $ result ;
225
+ }
226
+
205
227
/**
206
228
* @template T of string|\Stringable
207
229
* @param string $pattern
0 commit comments