Skip to content

Stdlib: array_splice()/substr_count()/array_change_key_case() — numeric-string int parameters (ext/standard parity) #4259

Description

@PurHur

Category

stdlib

Problem

Open #4176 tracks numeric-string coercion for fread/substr/array_slice. Several other builtins with $offset / $length / flag int parameters still require native int and throw LogicException when callers pass numeric strings — unlike Zend zend_parse_parameters long coercion.

Affected today (VM + JIT):

Function Parameter(s) Current error site
array_splice() $offset, $length ext/standard/array_splice.php
substr_count() $offset, $length ext/standard/substr_count.php
array_change_key_case() $case flag ext/standard/array_change_key_case.php

php-src reference

Repro (failure today)

<?php
declare(strict_types=1);
// test/repro-maintainer/numeric_string_int_params.php

$a = [10, 20, 30, 40];
var_export(array_splice($a, '1', '2'));
echo "\n";
echo substr_count('abababa', 'ab', '2', '4'), "\n";
var_export(array_change_key_case(['Foo' => 1], '0'));
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/numeric_string_int_params.php
php bin/vm.php test/repro-maintainer/numeric_string_int_params.php
'
Call Zend PHP 8.x This compiler VM (today)
array_splice($a,'1','2') removes [20,30] LogicException
substr_count('abababa','ab','2','4') 2 LogicException
array_change_key_case($a,'0') lower-case keys LogicException

Scope (this repo)

Module Path
Shared reuse JitLongArg / planned VmArg::coerceToInt() from #4176
VM ext/standard/array_splice.php, substr_count.php, array_change_key_case.php
JIT same files call() paths
Tests test/compliance/cases/stdlib/array_splice_numeric_string.phpt, etc.

Done when

  • Repro table matches Zend on VM/JIT for all three functions
  • Non-numeric strings still raise TypeError like Zend (array_splice($a, 'abc'))
  • ./script/ci-fast.sh --filter "array_splice|substr_count|array_change_key_case" green

Related

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 apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions