Example 1 — Branch One Context Two Ways
Share the start, then add different endings.
<?php
$ctx = hash_init('sha256');
hash_update($ctx, 'Hello, ');
$copy = hash_copy($ctx);
hash_update($ctx, 'World');
hash_update($copy, 'PHP');
echo hash_final($ctx), PHP_EOL;
echo hash_final($copy), PHP_EOL; How It Works
- Start a context. Add the shared text
Hello,. - Copy it. Both now hold the same state.
- Add different endings. One gets
World, the otherPHP. - Finish both. Each result is the hash of its full text.

