kphp icon indicating copy to clipboard operation
kphp copied to clipboard

[php7.1] Add support for the negative parameter `offset` for `strpos`

Open Tsygankov-Slava opened this issue 2 years ago • 0 comments

In PHP 7.1, function strpos can accept the negative parameter offset.

Link: https://www.php.net/manual/ru/function.strpos.php

PHP function

strpos(string $haystack, string $needle, int $offset = 0): int|false

Current behavior

In the implementation, php_warning is caused when passing a negative number to offset:

  if (offset < 0) {
    php_warning("Wrong offset = %" PRIi64 " in function strpos", offset);
    return false;
  }

Expected behavior

If offset takes a negative number, then the position of the beginning of the search will be counted from the end of the string.

Tsygankov-Slava avatar Jan 01 '23 16:01 Tsygankov-Slava