Using Closures in OOP

Code
<?php

class Foo
{
    private 
$value;
    
    public function 
__construct($value)
    {
        
$this->value = (string) $value;
    }
    
    
/**
     * @param Closure $closure 
     * @return string the hash value
     */
    
public function getHash(Closure $closure)
    {
        
$closure $closure->bindTo($thisself::CLASS);
        return 
$closure();
    }
    
    
/**
     * @param Closure $closure
     * @return string the hash value
     */
    
public function getHash2(Closure $closure)
    {
        return 
$closure($this->value);
    }
}

$foo = new Foo('string');

// you need to know the inside of class
$c1 = function() {
    return 
md5($this->value);
};
$c2 = function() {
    return 
sha1($this->value);
};

echo 
'bindTo solution' PHP_EOL;
echo 
$foo->getHash($c1) . PHP_EOL;
echo 
$foo->getHash($c2) . PHP_EOL PHP_EOL;


// You need to know that your function
// gets a string
$c1 = function($value) {
    return 
md5($value);
};
$c2 = function($value) {
    return 
sha1($value);
};

echo 
'injection of value solution' PHP_EOL;
echo 
$foo->getHash2($c1) . PHP_EOL;
echo 
$foo->getHash2($c2);
Result
bindTo solution
b45cffe084dd3d20d928bee85e7b0f21
ecb252044b5ea0f679ee78ec1a12904739e2904d

injection of value solution
b45cffe084dd3d20d928bee85e7b0f21
ecb252044b5ea0f679ee78ec1a12904739e2904d
Used Versions
PHP 8.2, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8