Skip to content

A Stringable object held as mixed passed to a string function does not call __toString #63

Closed

Description

@blacktrs

Summary

A Stringable object held as mixed passed to a string function does not call __toString.

Repro

<?php
final class S { public function __toString(): string { return 'ab'; } }
function t(mixed $v): void {
    echo str_repeat($v, 2), '|', str_pad($v, 4, '-'), '|', strtoupper($v), '|', ucfirst($v), '|', strlen($v), "\n";
    var_dump(in_array($v, ['ab']));
}
t(new S());

Expected (php 8.5)

abab|ab--|AB|Ab|2
bool(true)

Actual (manticore 10affa68, macOS arm64)

|----|||0
bool(false)

Tracking

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