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
Ref: #8797 (enum operands) · #1492
Category
stdlib· php-src-strictProblem
With
declare(strict_types=1), Zendsimilar_text()requiresstringoperands and throwsTypeErrorwhen argument #1 is anint. This compiler coerces scalars to string (prints match count3forsimilar_text(123, '123')), diverging from php-srcconvert_to_stringguards 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
ext/standard/string.c—PHP_FUNCTION(similar_text),_php_similar_textZend/zend_operators.c—zend_parse_parameters/Z_PARAM_STRstrict pathsRepro
In-tree:
test/repro/issue_4543_similar_text.phpsimilar_text(123, '123')TypeError: similar_text(): Argument #1 ($string1) must be of type string, int given3(coerced) ❌Scope (this repo)
ext/standard/similar_text.phpVmString::coerceStringBuiltinArg/ strictZ_PARAM_STRparitylib/JIT/Builtin/test/compliance/cases/stdlib/similar_text*.phptPHP-in-PHP: fix in
ext/standard+ JIT arg helpers — no newruntime/*.c.Done when
TypeErroron VMsimilar_text('hello', 'hello world', $p)percent-by-ref path still works (rest ofissue_4543_similar_text.php)./script/ci-fast.sh --filter similar_textgreenRef: #8797 (enum operands) · #1492