php / php/php-src

grapheme_extract() returns false instead of empty string when the offset is equal to the length of the haystack

Open
#18,031 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: intl Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php
var_dump(grapheme_extract('', 42));
var_dump(grapheme_extract('ab', 42, offset: 2));

Resulted in this output:

bool(false)
bool(false)

But I expected this output instead:

string(0) ""
string(0) ""

Per documentation, the offset ought to be less then or equal to the length of the string (which I consider an appropriate range).

PHP Version

PHP 8.3

Operating System

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two grapheme_extract() calls from the report, then locate the function's implementation and related tests in php-src. Verify that an offset equal to the haystack length returns an empty string for both cases, while behavior for other offsets remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.