Skip to content

strpos/stripos with an offset past the end must throw ValueError, not return false. #316

Closed

Description

@blacktrs

Summary

strpos/stripos with an offset past the end must throw ValueError, not return false.

Repro

<?php
try { var_dump(strpos('abc', 'a', 4)); } catch (ValueError $e) { echo $e->getMessage(), "\n"; }
try { var_dump(stripos('abc', 'a', -4)); } catch (ValueError $e) { echo $e->getMessage(), "\n"; }

Expected (php)

strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)

Actual (manticore 3cc57ad3, Darwin arm64)

bool(false)
int(0)

Tracking

Known-bug repro: tests/aot/repro/wrong/strpos_offset_out_of_range.php — bash tests/aot/xfail.sh -k strpos_offset_out_of_range reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions