1. Go to this page and download the library: Download mistralys/variable-hasher library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mistralys / variable-hasher example snippets
use Mistralys\VariableHasher\VariableHasher;
$intHash = VariableHasher::create(123)->getHash();
$multiHash = VariableHasher::create(123, 'string', 45.67, new stdClass())->getHash();
$array = array(
'key' => 'value',
'another_key' => 123,
'object' => new stdClass()
);
$arrayHash = VariableHasher::create($array)->getHash();
use Mistralys\VariableHasher\VariableHasher;
class MyObjectFactory
{
private array $instances = array();
public function create(array $params) : MyObject
{
$hash = VariableHasher::create($params)->getHash();
if(isset($this->instances[$hash])) {
return $this->instances[$hash];
}
$instance = new MyObject($params);
$this->instances[$hash] = $instance;
return $instance;
}
}