Skip to content

Regression: str_contains()/str_starts_with()/str_ends_with() — Stringable object operands coerced, Zend TypeError (ext/standard/string.c) #14660

Closed

Description

@PurHur

Category

stdlib · php-src-strict · regression

Problem

str_contains(), str_starts_with(), and str_ends_with() accept Stringable object operands on VM (via implicit __toString coercion) and return true. Zend PHP 8.2+ throws TypeError — these builtins use typed string parameters and do not coerce objects, even when __toString() is defined.

Distinct from #8825 (enum case operands) and from legacy builtins that still coerce __toString (see #14661 strcmp / #14662 str_replace family).

php-src reference

Repro

test/repro/maintainer_gap_str_contains_stringable_typeerror.php (also test/repro/maintainer_gap_str_contains_object_stringable.php):

php test/repro/maintainer_gap_str_contains_stringable_typeerror.php           # ok
php bin/vm.php test/repro/maintainer_gap_str_contains_stringable_typeerror.php # fail (coerces)

PHP implementation target

Done when (php-src-strict)

  • Stringable object haystack/needle throws TypeError with Zend-matching message shape
  • Maintainer repro prints ok on VM
  • Plain string behavior unchanged

Refs #8825, #4346, #1492

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 1, 2026
  2. PurHur commented on Jul 1, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — batch (issues #14660, #14661, #14662, #14663)

  3. PurHur commented on Jul 1, 2026

    @PurHur
    OwnerAuthor

    Merged via #14664 — str_contains/str_starts_with/str_ends_with VM+JIT now TypeError on Stringable operands; repro maintainer_gap_str_contains_stringable_typeerror.php prints ok.

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

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions