Skip to content

Stdlib: bindec()/hexdec()/octdec() — enum case operands must TypeError (ext/standard/string.c, php-src-strict) #8863

Description

@PurHur

Category

stdlib · php-src-strict

Problem

bindec(), hexdec(), and octdec() accept backed enum cases as numeric-string operands via implicit coercion. Zend rejects them with TypeError via Z_PARAM_STR.

Distinct from #8782 (dechex()/decbin()/decoct() output coercion) — this issue covers input operands to base-decoding builtins.

php-src reference

Repro (verified 2026-06-16)

<?php
enum Es: string { case A = 'ff'; }
foreach (['bindec', 'hexdec', 'octdec'] as $fn) {
    try {
        $fn(Es::A);
        echo "{$fn} ok\n";
    } catch (Throwable $e) {
        echo $fn, ' ', $e::class, ': ', $e->getMessage(), "\n";
    }
}
docker info >/dev/null
./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_bindec_hexdec_enum.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_bindec_hexdec_enum.php'
Runtime Output
Zend PHP 8.2 TypeError for all three
VM (today) all succeed (bindec ok, hexdec ok, octdec ok) ❌

Scope (PHP-in-PHP)

Layer Path
VM ext/standard/bindec.php, hexdec.php, octdec.php — VmString::coerceStringBuiltinArg()
JIT matching lowerers
Tests test/compliance/cases/stdlib/bindec_hexdec_octdec_enum_typeerror.phpt

Done when

  • VM TypeError matching Zend for enum operands
  • ./script/ci-fast.sh --filter bindec_hexdec_enum 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