Skip to content

Fix strlen() Stringable __toString coercion (closes #13468) - #13480

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-13468-strlen-stringable
Jun 29, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-13468-strlen-stringable

Conversation

@PurHur

@PurHur PurHur commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • VM strlen() now uses VmString::coerceStringBuiltinArg (same as trim() family) so Stringable objects return strlen((string)$obj).
  • JIT JitStrlen coerces objects via JitNativeString / JitStringBuiltinArg::lowerCoercible when caller is not strict.

php-src reference

  • ext/standard/string.c — _php_string_arg object coercion

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "class C implements Stringable { public function __toString(): string { return \"obj\"; } } echo strlen(new C()), \"\n\";"
php bin/vm.php -r "class C implements Stringable { public function __toString(): string { return \"obj\"; } } echo strlen(new C()), \"\n\";"
php bin/jit.php -r "class C implements Stringable { public function __toString(): string { return \"obj\"; } } echo strlen(new C()), \"\n\";"
'
# Expected: 3 on all three

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter strlen_stringable'
# OK (1 test)

Closes #13468

Made with Cursor

Use VmString::coerceStringBuiltinArg on the VM path and JitNativeString/JitStringBuiltinArg::lowerCoercible on JIT so __toString objects get byte length like trim() family builtins.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant