php.net |  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: 2020-09-21 19:05 UTC
From: cschneid@php.net Assigned: kocsismate (profile)
Status: Assigned Package: intl (PECL)
PHP Version: 8.0.0beta4 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-09-21 17:31 UTC] cschneid@php.net
Description:
------------
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 https://github.com/php/php-src/pull/5972 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)

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

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

Patch Name: Fix inconsistency between grapheme_substr() and substr()
On GitHub:  https://github.com/php/php-src/pull/6163
Patch:      https://github.com/php/php-src/pull/6163.patch
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Oct 25 03:01:24 2020 UTC