symfony / polyfill

PHP polyfills

Home Page:https://symfony.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`iconv_substr` and `grapheme_substr` changes in PHP 8

Ayesh opened this issue · comments

PHP 8 returns an empty string ("") on iconv_substr and grapheme_substr functions if the $start parameter exceeds the size of the provided string ($s). https://php.watch/versions/8.0/substr-out-of-bounds

PHP 5 through 7 native functions and Symfony polyfills for iconv (Symfony\Polyfill\Iconv\Iconv::iconv_substr) and Intl (Symfony\Polyfill\Intl\Grapheme\Grapheme::grapheme_substr) currently return false in this case. This is the correct behavior for PHP < 8.0, but I think it will be more complete if we were to mimic this behavior for iconv_substr and grapheme_substr if the runtime is PHP 8 or later.

I can submit PRs, but I thought it will be better to ask maintainers thoughts on this. Should we always return an empty string (which makes the polyfill not exactly compatible), or return an empty string only on PHP 8?

Tasks

Let's return conditionally based on the runtime version, this will reduce the BC breaking potential.

Thank you @nicolas-grekas. I updated the issue so we can track iconv_substr, mb_susbtr, and grapheme_substr functions all from one issue. I sent #289 for iconv, and will send another for grapheme.

There are some changes in sub(i)str and str(i)str too, which I will open another issue to track.