PHP - Fonction Hash copy ()

Définition et utilisation

le hash_copy() La fonction est utilisée pour copier le contexte de hachage généré à partir de hash_init ().

Syntaxe

hash_copy ( HashContext $context ) : HashContext

Paramètres

Sr. Non Paramètre et description
1

HashContext context

Le contexte de hachage que vous obtenez en utilisant hash_init ().

Valeurs de retour

La fonction hash_copy () renvoie une copie du contexte de hachage. Le contexte de hachage peut être utilisé avec d'autres fonctions de hachage comme hash_update (), hash_update_stream (), hash_update_file () et hash_final ().

Version PHP

Cette fonction fonctionnera à partir de la version PHP supérieure à 5.3.0.

Exemple 1

Fonctionnement de hash_copy () et hash_init () -

<?php
   $hash_context = hash_init("md5");
   hash_update($hash_context, "Welcome To Tutorialspoint");
   $hash_copy= hash_copy($hash_context);
   echo hash_final($hash_context);
   echo "<br/>";
   hash_update($hash_copy,  "Welcome To Tutorialspoint");
   echo hash_final($hash_copy);
?>

Production

Cela produira le résultat suivant -

6211420491a571f89f970683221d4480<br/>d0b25da996bf035057aba79082c53b30

Exemple 2

Fonctionnement de hash_copy () avec sha256 -

<?php
   $hash_context = hash_init("sha256");
   hash_update($hash_context, "Welcome To Tutorialspoint");
   $hash_copy = hash_copy($hash_context);
   hash_update($hash_copy,  "Welcome To Tutorialspoint");
   echo hash_final($hash_copy);
?>

Production

Cela produira le résultat suivant -

5fc2dcb68e98dee511cd5bc72667a1acaaf769c737f094672ab9072e5543f587