[php-src] Issue #22779: mb_strrpos() returns the wrong position for a negative offset in a non-UTF-8 encoding
| From: | eyupcanakman | Date: | Fri, 17 Jul 2026 01:22:37 +0000 |
| Subject: | [php-src] Issue #22779: mb_strrpos() returns the wrong position for a negative offset in a non-UTF-8 encoding | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-252442@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/22779
Author: eyupcanakman
### Description
The following code:
```php
<?php
var_dump(mb_strrpos("\xA9\xA9X", "\xA9", -2, "ISO-8859-1"));
var_dump(strrpos("\xA9\xA9X", "\xA9", -2));
```
Resulted in this output:
```
int(0)
int(1)
```
But I expected this output instead:
```
int(1)
int(1)
```
For a single-byte encoding one byte is one character, so
mb_strrpos() should agree with
strrpos() here. The result is wrong for a negative offset in any non-UTF-8 encoding. An
ISO-8859-1 needle byte in 0x80-0xBF gives a position that is too early, and an ASCII needle in
UTF-16 also returns the wrong position.
### PHP Version
PHP 8.4.25-dev (the same code is in 8.3, 8.5 and master)
### Operating System
macOS 27.0