Skip to content

Stdlib: strlen() Stringable object — TypeError not __toString length (ext/standard/string.c) #13468

Closed

Description

@PurHur

Category

stdlib · php-src-strict

Problem

strlen($obj) on a Stringable object throws TypeError: strlen(): Argument #1 ($string) must be of type string, C given. Zend returns the byte length of the __toString() result (3 for 'obj').

Sibling builtins trim() / ltrim() / rtrim() / chop() / strtoupper() already coerce Stringable objects on VM — only strlen() rejects.

php-src reference

Repro (verified 2026-06-29)

./script/docker-exec.sh -- bash -lc '
php test/repro/maintainer-parity-probes/probe_strlen_stringable.php; echo ---;
php bin/vm.php test/repro/maintainer-parity-probes/probe_strlen_stringable.php
php test/repro/maintainer-parity-probes/probe_string_builtin_stringable.php; echo ---;
php bin/vm.php test/repro/maintainer-parity-probes/probe_string_builtin_stringable.php
'
Call Zend VM
strlen($stringable) 3 TypeError ❌
trim($stringable) 'obj' 'obj' ✓

Scope (PHP-in-PHP first)

Layer Path
Builtin ext/standard/strlen_.php — align with trim_.php coercion via VmString::coerceStringBuiltinArg
JIT lib/JIT/Builtin/ strlen handler
Tests test/compliance/cases/stdlib/strlen_stringable.phpt

Done when (php-src-strict)

  • strlen(Stringable) returns strlen((string)$obj) result
  • Object without string conversion throws Error / TypeError matching Zend
  • trim family unchanged
  • No new C in runtime/

Verification

./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer-parity-probes/probe_strlen_stringable.php

Links

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

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — batch (issues #13468 #13467)

  3. PurHur commented on Jun 29, 2026

    @PurHur
    OwnerAuthor

    Merged via #13480 — VM/JIT strlen(Stringable) returns __toString byte length; compliance strlen_stringable.phpt green.

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