@@ -353,51 +353,51 @@ public static function reverse(string $s): string
353
353
354
354
/**
355
355
* Returns part of $haystack before $nth occurence of $needle (negative value means searching from the end).
356
- * @return string|FALSE returns FALSE if the needle was not found
356
+ * @return string|NULL returns NULL if the needle was not found
357
357
*/
358
358
public static function before (string $ haystack , string $ needle , int $ nth = 1 )
359
359
{
360
360
$ pos = self ::pos ($ haystack , $ needle , $ nth );
361
- return $ pos === FALSE
362
- ? FALSE
361
+ return $ pos === NULL
362
+ ? NULL
363
363
: substr ($ haystack , 0 , $ pos );
364
364
}
365
365
366
366
367
367
/**
368
368
* Returns part of $haystack after $nth occurence of $needle (negative value means searching from the end).
369
- * @return string|FALSE returns FALSE if the needle was not found
369
+ * @return string|NULL returns NULL if the needle was not found
370
370
*/
371
371
public static function after (string $ haystack , string $ needle , int $ nth = 1 )
372
372
{
373
373
$ pos = self ::pos ($ haystack , $ needle , $ nth );
374
- return $ pos === FALSE
375
- ? FALSE
374
+ return $ pos === NULL
375
+ ? NULL
376
376
: substr ($ haystack , $ pos + strlen ($ needle ));
377
377
}
378
378
379
379
380
380
/**
381
381
* Returns position of $nth occurence of $needle in $haystack (negative value means searching from the end).
382
- * @return int|FALSE offset in characters or FALSE if the needle was not found
382
+ * @return int|NULL offset in characters or NULL if the needle was not found
383
383
*/
384
384
public static function indexOf (string $ haystack , string $ needle , int $ nth = 1 )
385
385
{
386
386
$ pos = self ::pos ($ haystack , $ needle , $ nth );
387
- return $ pos === FALSE
388
- ? FALSE
387
+ return $ pos === NULL
388
+ ? NULL
389
389
: self ::length (substr ($ haystack , 0 , $ pos ));
390
390
}
391
391
392
392
393
393
/**
394
394
* Returns position of $nth occurence of $needle in $haystack.
395
- * @return int|FALSE offset in bytes or FALSE if the needle was not found
395
+ * @return int|NULL offset in bytes or NULL if the needle was not found
396
396
*/
397
397
private static function pos (string $ haystack , string $ needle , int $ nth = 1 )
398
398
{
399
399
if (!$ nth ) {
400
- return FALSE ;
400
+ return NULL ;
401
401
} elseif ($ nth > 0 ) {
402
402
if (strlen ($ needle ) === 0 ) {
403
403
return 0 ;
@@ -416,7 +416,7 @@ private static function pos(string $haystack, string $needle, int $nth = 1)
416
416
$ pos --;
417
417
}
418
418
}
419
- return $ pos ;
419
+ return $ pos === FALSE ? NULL : $ pos ;
420
420
}
421
421
422
422
0 commit comments