Skip to content

Stdlib: hash_init()/hash_update()/hash_final()/hash_copy() — VmHashContext incremental handlers (phase 1 of #3357) #7174

Description

@PurHur

Category

stdlib | php-in-php

Problem

#6937 (closed) registered ext/hash skeleton stubs so function_exists('hash_init') is true, but hash_init() still throws Error: … not implemented in this compiler build (issue #3357). Streaming/incremental hashing and hash_copy() fork semantics are blocked for frameworks, file digest loops, and self-host paths that expect ext/hash parity.

Verified 2026-06-06:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_export(function_exists(\"hash_init\")); echo PHP_EOL; hash_init(\"sha256\");" 2>&1 | head -4
'
# true
# Fatal: hash_init() is not implemented in this compiler build (issue #3357)

php-src reference

Repro

<?php
$ctx = hash_init('sha256');
hash_update($ctx, 'hello ');
hash_update($ctx, 'world');
echo hash_final($ctx), "\n";

$ctx2 = hash_copy($ctx);
echo hash_final($ctx2), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_hash_context.php
php bin/vm.php repro_hash_context.php 2>&1 | head -5
'
Runtime Result
Zend Two identical SHA-256 hex lines for hello world
VM today hash_init() Error fatal

Scope (PHP-in-PHP first)

Path Work
ext/hash/VmHashContext.php (new) Context state object; reuse digest backends from ext/standard/VmHashNative.php / VmHash.php
ext/hash/hash_init.php et al. Replace stub throws with real handlers
ext/hash/Module.php Wire HashContext builtin class (pairs #7084 __debugInfo)
JIT/AOT Defer after VM green; reuse #5989 digest lowering when ready
C runtime Do not extend lib/AOT/runtime/hash_crypto.c — shrink per #5989

php-src-strict

Done when

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 8, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 8, 2026

    @PurHur
    OwnerAuthor

    Merged via #7666.

    Verification (green):

    • php bin/vm.php test/repro/hash_context_incremental.php → two identical SHA-256 lines for hello world
    • vendor/bin/phpunit --filter "hash_context|hash_init_value|hash_update_enum|hash_final_finalized|HashModuleTest" → OK (10 tests, 16 assertions)

    Implementation: ext/hash/VmHashContext.php + incremental API on ext/standard/VmHashNative.php (md5/sha1/sha256). php-src ref: ext/hash/hash.c. No C runtime growth.

    Follow-up: JIT/AOT lowering for incremental hash builtins (issue scope phase 1 was VM-only).

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