Skip to content

Stdlib: similar_text() must TypeError on int operands — VM coerces to string (ext/standard/string.c) #9519

Description

@PurHur

Category

stdlib · php-src-strict

Problem

With declare(strict_types=1), Zend similar_text() requires string operands and throws TypeError when argument #1 is an int. This compiler coerces scalars to string (prints match count 3 for similar_text(123, '123')), diverging from php-src convert_to_string guards on internal string functions.

Distinct from enum-case operand bugs tracked in #8797 — this issue is scalar int/float coercion, not enum objects.

php-src reference

Repro

In-tree: test/repro/issue_4543_similar_text.php

<?php
declare(strict_types=1);
echo similar_text(123, '123'), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/issue_4543_similar_text.php 2>&1 | head -3
php bin/vm.php test/repro/issue_4543_similar_text.php 2>&1 | head -3
'
Engine similar_text(123, '123')
Zend PHP 8.2 TypeError: similar_text(): Argument #1 ($string1) must be of type string, int given
VM today 3 (coerced) ❌

Scope (this repo)

Path Work
ext/standard/similar_text.php Use shared VmString::coerceStringBuiltinArg / strict Z_PARAM_STR parity
lib/JIT/Builtin/ Align JIT lowering with VM TypeError (reuse string builtin arg helpers)
Tests Extend test/compliance/cases/stdlib/similar_text*.phpt

PHP-in-PHP: fix in ext/standard + JIT arg helpers — no new runtime/*.c.

Done when

  • Repro throws Zend-equivalent TypeError on VM
  • similar_text('hello', 'hello world', $p) percent-by-ref path still works (rest of issue_4543_similar_text.php)
  • JIT/AOT match VM for int operand (or document VM-only v1 with issue link)
  • ./script/ci-fast.sh --filter similar_text green

Ref: #8797 (enum operands) · #1492

Activity

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