Skip to content

Regression: str_contains()/str_starts_with()/str_ends_with() — Stringable haystack TypeError, Zend __toString coerce (re-#11398, ext/standard/string.c) #15069

Closed

Description

@PurHur

Category

stdlib · php-src-strict · regression (closed #11398 / #14660 flip-flop)

Problem

For str_contains(), str_starts_with(), and str_ends_with(), Zend coerces Stringable object operands via __toString() when the declaring unit does not use declare(strict_types=1). VM throws TypeError on the haystack/needle object.

Call Zend 8.2 VM (today)
str_contains(new C(), 'obj') (C::__toString) true TypeError ❌
str_starts_with(new C(), 'obj') true TypeError ❌
str_ends_with(new C(), 'obj') true TypeError ❌

Non-Stringable objects must still TypeError (Zend parity).

php-src reference

PHP implementation target

Repro (verified 2026-07-02)

./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_str_contains_object_stringable.php
# TypeError: str_contains(): Argument #1 ($haystack) must be of type string, C given

./script/docker-exec.sh -- php test/repro/maintainer_gap_str_contains_object_stringable.php
# true
# true
# true

Done when

  • Stringable objects coerce to string for all three builtins (weak units)
  • declare(strict_types=1) still TypeErrors on object operands
  • Non-Stringable objects still TypeError
  • Compliance guard under test/compliance/cases/stdlib/

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 2, 2026
  2. PurHur commented on Jul 2, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — batch (issues #15069, #15067)

  3. PurHur commented on Jul 2, 2026

    @PurHur
    OwnerAuthor

    Merged via #15075. VM+JIT compliance str_contains_stringable_coerce green; AOT lint OK on Stringable repro.

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