Skip to content

Stdlib: mb_strlen() — enum case operand must TypeError (ext/mbstring/mbstring.c) #5873

Description

@PurHur

Category

stdlib · php-src-strict

Problem

mb_strlen() rejects enum case operands with LogicException (mb_strlen() only supports strings in this compiler build) instead of Zend’s TypeError (Argument #1 ($string) must be of type string, … given). This is separate from #5524 (ext/standard string.c builtins).

php-src reference

Repro

test/repro/maintainer_mb_strlen_enum.php:

<?php
enum Es: string { case B = 'hi'; }
try {
    echo mb_strlen(Es::B);
} catch (Throwable $e) {
    echo get_class($e).': '.$e->getMessage();
}
docker info >/dev/null
./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_mb_strlen_enum.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_mb_strlen_enum.php'
Engine Result
Zend TypeError: mb_strlen(): Argument #1 ($string) must be of type string, Es given
VM LogicException: mb_strlen() only supports strings in this compiler build

Implementation hints

Done when

  • VM throws TypeError matching Zend for enum case operand (not LogicException)
  • JIT lowerer rejects enum cases with same TypeError when native path exists
  • Add test/compliance/cases/stdlib/mb_strlen_enum_typeerror.phpt
  • ./script/ci-fast.sh --filter mb_strlen_enum green
  • No enum backing-string coercion in runtime/*.c

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