Skip to content

Stdlib: lcfirst() — enum case operand must TypeError not silent coerce (ext/standard/string.c, php-src-strict) #6003

Description

@PurHur

Category

stdlib

Problem

Under php-src-strict, string builtins must reject backed/unit enum case objects with TypeError (see #5780 hash family, #5861 ucfirst/nl2br sweep). lcfirst() still coerces enum cases via backing string on VM/JIT/AOT instead of raising:

TypeError: lcfirst(): Argument #1 ($string) must be of type string, E given

Sibling #5861 tracks ucfirst/nl2br/str_pad/addslashes; this issue is the lcfirst() gap verified independently.

php-src reference

Repro (verified 2026-06-05)

<?php
enum E: string { case A = 'hello'; }
try {
    lcfirst(E::A);
    echo "ok\n";
} catch (Throwable $t) {
    echo get_class($t), ': ', $t->getMessage(), "\n";
}
docker info >/dev/null
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php8.2 repro.php
php bin/vm.php repro.php
php bin/jit.php repro.php 2>/dev/null || true
'
Runtime Output
Zend PHP 8.2+ TypeError: lcfirst(): Argument #1 ($string) must be of type string, E given
vm.php today ok (silent coerce via backing string 'hello')

Scope (PHP-in-PHP)

Path Work
ext/standard/lcfirst.php VM: VmString::coerceStringBuiltinArg() / EnumCaseSupport::isEnumCaseVariable() guard
lib/JIT/JitStringBuiltinArg.php JIT/AOT: mirror VM guard (no C-only shortcut)
test/compliance/cases/stdlib/lcfirst_enum_type_error.phpt VM compliance
test/compliance/cases/stdlib/lcfirst_enum_type_error_jit.phpt JIT when LLVM available

Do not add logic to runtime/*.c. Delete any C fast-path that bypasses enum-case rejection.

Done when

  • Repro prints TypeError on VM (not ok)
  • JIT/AOT paths match VM (php-src-strict; no php-compiler-strict without proof)
  • ./script/ci-fast.sh --filter lcfirst_enum green
  • Compliance .phpt files added under test/compliance/cases/stdlib/

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