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: 2021-02-12 14:51 UTC
From: cschneid@php.net Assigned: kocsismate (profile)
Status: Closed Package: intl (PECL)
PHP Version: 8.0.0beta4 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cschneid@php.net
New email:
PHP Version: OS:

 

 [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

Pull Requests

Pull requests:

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
 [2021-02-12 14:51 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2021-02-12 14:51 UTC] cmb@php.net
This has been fixed in the meantime.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 11 22:01:45 2024 UTC