Skip to content

Stdlib: mb_trim()/mb_ltrim()/mb_rtrim() named parameters rejected — LogicException not trimmed string (ext/mbstring/mbstring.c) #9839

Description

@PurHur

Category

stdlib · php-src-strict

Problem

PHP 8.4 mb_trim(), mb_ltrim(), and mb_rtrim() accept named parameters characters: and encoding: per php-src stubs. Positional calls work; named characters: (and encoding:) throw LogicException: Too many arguments to function call instead of trimming.

Root cause: Internal builtin metadata does not expose php-src parameter names to lib/VM/NamedArgs.php, so named slots are treated as excess arguments.

php-src reference

Repro (failure today)

<?php
$s = '--héllo--';
var_dump(mb_trim($s, '-'));              // OK: string(6) "héllo"
var_dump(mb_trim($s, characters: '-'));  // FAIL: LogicException

Also in repo: test/repro/maintainer_gap_mb_trim_named_characters.php

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/maintainer_gap_mb_trim_named_characters.php'

Implementation hints (PHP-in-PHP)

  • Register php-src parameter names on mb_trim / mb_ltrim / mb_rtrim Internal builtins (same pattern as other named-arg-aware stdlib)
  • ext/mbstring/VmMbstring.php — runTrimBuiltin() already handles positional characters / encoding; wire named resolution before arg count check
  • Mirror in ext/mbstring/JitMbTrim.php for JIT/AOT when in scope
  • No new C runtime

Scope

  • ext/mbstring/mb_trim.php, mb_ltrim.php, mb_rtrim.php
  • ext/mbstring/VmMbstring.php, JitMbTrim.php
  • lib/VM/NamedArgs.php (if shared Internal metadata fix)

Done when

  • mb_trim($s, characters: '-') returns trimmed string under VM (php-src-strict)
  • encoding: named arg works; mb_ltrim / mb_rtrim agree
  • Positional calls unchanged
  • Smallest compliance guard or repro script green

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/maintainer_gap_mb_trim_named_characters.php'

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