|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80129 Various grapheme functions throw new and bogus exceptions
Submitted: 2020-09-21 17:31 UTC Modified: 2021-02-12 14:51 UTC
From: Assigned: kocsismate (profile)
Status: Closed Package: intl (PECL)
PHP Version: 8.0.0beta4 OS:
Private report: No CVE-ID: None
 [2020-09-21 17:31 UTC]
Various grapheme functions throw exceptions depending on input values.
This was introduced in PHP 8 beta 4.
It is a big BC break and renders some of the functions hard to use.

The test whether start/length/etc. parameters are within the haystack as well as disallowing searching for an empty string with grapheme_strpos($string, "") was changed. 

The pull request seems harmful as it creates a big difference between grapheme_* and the * or mb_* counterparts.

Something as simple as truncating a string to length 20 now has to be written as
  $truncated = grapheme_strlen($string) > 0 ? grapheme_substr($string, 0, 20) : "";
instead of
  $truncated = grapheme_substr($string, 0, 20)l
which seems unnecessarily complicated and different from substr/mb_substr.

Obvious examples are grapheme_substr, grapheme_strpos but I guess all grapheme_-functions should be reexamined and if they are changed the change should be in line with substr, strpos etc.

Test script:
grapheme_substr("", 0, 1);

Expected result:
Either false (like pre-beta4) or empty string "" (like substr and mb_substr)

Actual result:
Fatal error: Uncaught ValueError: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-21 19:05 UTC]
-Assigned To: +Assigned To: kocsismate
 [2020-09-21 19:06 UTC]
The following pull request has been associated:

Patch Name: Fix inconsistency between grapheme_substr() and substr()
On GitHub:
 [2021-02-12 14:51 UTC]
-Status: Assigned +Status: Closed
 [2021-02-12 14:51 UTC]
This has been fixed in the meantime.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 25 19:01:28 2024 UTC