Skip to content

Stdlib: HashContext::__debugInfo() — PHP 8.4 var_dump must hide hash state (ext/hash/hash.c, pairs #3357) #7084

Description

@PurHur

Category

stdlib · php-src-strict · PHP 8.4 · ext/hash phase 2

Problem

PHP 8.4 added HashContext::__debugInfo() so var_dump(hash_init('sha256')) prints a safe summary instead of leaking internal hash state. This compiler has no HashContext class at all today (class_exists('HashContext') === false; incremental hashing tracked in #3357 / #6937).

Even after hash_init() lands, parity requires the debug hook.

php-src reference

Repro (failure today)

<?php
declare(strict_types=1);

var_dump(class_exists('HashContext', false));
if (!function_exists('hash_init')) {
    echo "hash_init: no\n";
    exit(0);
}
$ctx = hash_init('sha256');
var_dump($ctx->__debugInfo());
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_dump(class_exists(\"HashContext\", false));"'
Check Zend PHP 8.4 bin/vm.php
class_exists('HashContext') true false
->__debugInfo() keys ['algo' => 'sha256'] (no secret state) not reached

Scope (PHP-in-PHP first)

Layer Path
Prerequisite #3357 / #6937 — hash_init() returns HashContext object
VM class register HashContext in lib/VM/BuiltinClasses.php
Method __debugInfo(): array in PHP (ext/hash/HashContext.php or ext/standard/VmHash.php) — expose algorithm name only
Tests test/compliance/cases/stdlib/hash_context_debug_info.phpt

Done when

  • HashContext exists after hash_init()
  • var_dump($ctx) / $ctx->__debugInfo() matches Zend output shape (no raw digest state)
  • ./script/ci-fast.sh --filter hash_context_debug_info green

Verification

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

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

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 9, 2026

    @PurHur
    OwnerAuthor

    Merged via #7816.

    Verification (green):

    • vendor/bin/phpunit --filter hash_context_debug_info → VM + JIT compliance pass (3 tests)
    • vendor/bin/phpunit --filter HashModuleTest → 4 tests pass

    Implementation: HashContext::__debugInfo() returns ['algo' => 'sha256'] (algorithm name only, no digest state). php-src ref: ext/hash/hash.c ZEND_METHOD(HashContext, __debugInfo). PHP path: ext/hash/HashContextDebugInfo.php.

    Incremental hash API remains VM-only (#7174); no C runtime added.

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