Skip to content

preg_match / preg_replace with /u on an invalid UTF-8 subject answer 0 / the subject with no error instead of false / null + PREG_BAD_UTF8_ERROR #372

Closed

Description

@blacktrs

Summary

preg_match / preg_replace with /u on an invalid UTF-8 subject answer 0 / the subject with no error instead of false / null + PREG_BAD_UTF8_ERROR.

Repro

<?php
$s = "a\x85b";
$r = preg_match('/\R/u', $s);
var_dump($r, preg_last_error());
$r = preg_replace('/x/u', 'y', $s);
var_dump($r === null, preg_last_error());

Expected (php)

bool(false)
int(4)
bool(true)
int(4)

Actual (manticore 9a3c0ef4, Darwin arm64)

int(0)
int(0)
bool(false)
int(4)

Tracking

Known-bug repro: tests/aot/repro/wrong/preg_utf8_invalid_subject.php — bash tests/aot/xfail.sh -k preg_utf8_invalid_subject 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 20, 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