-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grapheme_extract() returns false instead of empty string when the offset is equal to the length of the haystack #18031
Comments
<?php
var_dump(grapheme_extract('', 42));
var_dump(intl_get_error_message());
var_dump(grapheme_extract('ab', 42, offset: 2));
var_dump(intl_get_error_message()); Result is below:
Because it does not point to a string. Therefore, returns false. php-src/ext/intl/grapheme/grapheme_string.c Lines 731 to 734 in 517d7d9
|
@youkidearitai do you think it only needs documentation changes ? |
This may be considered as a documentation issue as grapheme_extract() has “always” worked that way. Although the current behaviour is counterintuitive when just extracting a valid prefix from a utf-8-encoded string, it has the property to always return a nonempty string or false provided that $size is positive, so that “looping until the result is false” may be part of a valid algorithm. However, if documentation is changed, I plea that a big red warning is placed at the top of the man page. |
@devnexen Hmm... There doesn't seem to be a contradiction in document. |
@devnexen The documentation says explicitly that In short, the problem is not in what is documented, but in what is not documented. The documentation ought to specify when failure occurs, specially in cases where it contradicts user intuition. |
I do think a error section is a fair demand in this case, but that's just a personal opinion :) |
Description
The following code:
Resulted in this output:
But I expected this output instead:
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
The text was updated successfully, but these errors were encountered: