Skip to content

Stdlib: hash_pbkdf2() — enum case operands must TypeError not LogicException (ext/hash/hash_pbkdf2.c, php-src-strict) #5972

Closed

Description

@PurHur

Category

stdlib · php-src-strict

Problem

hash_pbkdf2() string parameters ($algo, $password, $salt) must follow php-src TypeError on backed enum case operands (Z_PARAM_STR). Zend rejects enum objects; this compiler throws LogicException with a compiler-build message — wrong exception class and wrong coercion path.

php-src-strict: do not pass backed-enum backing scalars where Zend passes enum case objects to Z_PARAM_STR (rejects with TypeError).

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_hash_pbkdf2_enum_typeerror.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_hash_pbkdf2_enum_typeerror.php'

Minimal script (test/repro/maintainer_hash_pbkdf2_enum_typeerror.php):

<?php
enum E: string { case A = 'secret'; }
try {
    hash_pbkdf2('sha256', E::A, 'salt', 1000);
} catch (TypeError $e) {
    echo $e->getMessage(), "\n";
}
Runtime Exception Message shape
Zend PHP 8.x TypeError hash_pbkdf2(): Argument #2 ($password) must be of type string, E given
bin/vm.php LogicException hash_pbkdf2() requires string algorithm, password, salt...

Scope (this repo)

Area Path
VM ext/standard/hash_pbkdf2.php — shared guards via VmString::coerceStringBuiltinArg() / enum-case rejection
JIT lib/JIT/JitStringBuiltinArg.php in call() lowering for hash_pbkdf2
AOT same guards in native builtin wrapper
Tests test/compliance/cases/stdlib/hash_pbkdf2_enum_case.phpt

PHP-in-PHP: fix in ext/standard/ — do not add hash enum checks to lib/AOT/runtime/hash_crypto.c.

Done when

  • Repro throws catchable TypeError on VM with Zend message shape for enum $password
  • Enum operands on $algo and $salt also TypeError (not LogicException)
  • JIT/AOT compliance case green when required by filter
  • ./script/docker-exec.sh -- vendor/bin/phpunit --filter hash_pbkdf2_enum green

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter hash_pbkdf2_enum'

Related

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 4, 2026
  2. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#5972: hash_pbkdf2() enum operands must TypeError not LogicException).

  3. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    Merged via #7823.

    Fix: hash_pbkdf2() algo/password/salt args now use VmString::coerceStringBuiltinArg() (VM) and JitStringBuiltinArg::lower() (JIT) — enum case operands raise TypeError matching php-src ext/hash/hash_pbkdf2.c instead of LogicException.

    Verification (green):

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php test/repro/maintainer_hash_pbkdf2_enum_typeerror.php
    vendor/bin/phpunit --filter hash_pbkdf2_enum test/compliance/
    '

    → hash_pbkdf2(): Argument #2 ($password) must be of type string, E given
    → OK (4 tests, 4 assertions) VM + JIT compliance

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