Skip to content

Stdlib: mb_substr()/mb_strimwidth()/mb_strcut()/mb_strpos() float int params under strict_types — TypeError missing (ext/mbstring/mbstring.c) #13849

Closed

Description

@PurHur

Category

stdlib · php-src-strict · mbstring int parameters under caller strict_types

Problem

With declare(strict_types=1) at the call site, Zend rejects float offsets/lengths to mb_substr(), mb_strimwidth(), mb_strcut(), and mb_strpos() with TypeError. This compiler truncates floats and returns string results.

php-src reference

  • ext/mbstring/mbstring.c — php_mb_substr, php_mb_strimwidth, php_mb_strcut, php_mb_strpos; int params checked against caller strict_types

Repro (verified 2026-06-29)

test/repro/maintainer_gap_mb_substr_float_offset.php

./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_mb_substr_float_offset.php; php bin/vm.php test/repro/maintainer_gap_mb_substr_float_offset.php'
Builtin Zend VM
mb_substr('hello', 1.9, 2.7) TypeError exit 0 ('el')
mb_strimwidth('hello world', 1.9, 4.7) TypeError exit 0
mb_strcut('hello', 1.9, 2.7) TypeError exit 0
mb_strpos('hello', 'l', 1.9) TypeError exit 0

Scope (PHP-in-PHP first)

Layer Path
VM ext/mbstring/*.php — strict_types int-arg checks
JIT mbstring JIT lowering after VM green

Done when (php-src-strict)

  • Repro exits 0 on VM (all four builtins throw TypeError under strict_types)
  • Non-strict call sites still truncate like Zend
  • JIT agrees when in scope

Verification

php bin/vm.php test/repro/maintainer_gap_mb_substr_float_offset.php

Links

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 29, 2026
  2. PurHur commented on Jun 30, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — batch (issue #13849)

  3. PurHur commented on Jun 30, 2026

    @PurHur
    OwnerAuthor

    Merged via #13879. VM repro + compliance green; coercive truncation preserved outside strict_types.

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