Edit report at https://bugs.php.net/bug.php?id=64890&edit=1
ID: 64890 Updated by: larue...@php.net Reported by: me at rouvenwessling dot de Summary: strrpos with negative offset incorrect results -Status: Open +Status: Not a bug Type: Bug Package: Strings related Operating System: OS X PHP Version: 5.4.15 Block user comment: N Private report: N New Comment: I dont think it's a bug 'Internationalization' , then -1 , the cursor is at 'Internationalization', exactlly point to the 'n' ^ so, no matter what direction it try to find in, the "n" should be returned Previous Comments: ------------------------------------------------------------------------ [2013-05-21 23:25:18] cmbecker69 at gmx dot de The issue occurs for negative offsets, when the length of the needle is less than or equal to the absolute value of the offset. The cause seems to be in ext/standard/string.c line 1958: e = haystack + haystack_len + offset; This lets e reference one character further to the right than it actually should. Changing this line to: e = haystack + haystack_len + offset - 1; fixes the issue and gives the expected result for the test script. ------------------------------------------------------------------------ [2013-05-21 17:53:36] me at rouvenwessling dot de Description: ------------ Apparently the offset in strrpos doesn't work right if it's the same as the needle length. Test script: --------------- $result = strrpos('Internationalization', 'n', -1); var_dump($result); Expected result: ---------------- int(10) Actual result: -------------- int(19) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64890&edit=1