Last active
January 11, 2016 16:41
-
-
Save dunglas/a4d8fa31fb04cc42eaaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function generateHash($value, $namespace = '') | |
{ | |
$hash = hash_init('sha256'); | |
$queue = array(array($namespace => $value)); | |
for ($i = 0; isset($queue[$i]); ++$i) { | |
foreach ($queue[$i] as $k => $v) { | |
if (is_object($v)) { | |
hash_update($hash, $k.'=>'.spl_object_hash($v).','; | |
} elseif (is_array($v)) { | |
$queue[] = $v; | |
} else { | |
hash_update($hash, $k.'=>'.$v.','); | |
} | |
} | |
unset($queue[$i]); | |
hash_update($hash, "\n"); | |
} | |
return hash_final($hash); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function generateHash($value, $namespace = '') | |
{ | |
$queue = array(array($namespace => $value)); | |
for ($i = 0; isset($queue[$i]); ++$i) { | |
foreach ($queue[$i] as $k => $v) { | |
if (is_object($v)) { | |
$queue[$i][$k] = spl_object_hash($v); | |
} elseif (is_array($v)) { | |
unset($queue[$i][$k]); | |
$queue[] = $v; | |
} | |
} | |
} | |
return hash('sha256', serialize($queue)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment