So, how do you compare classes that contain Closure ? It looks like you can't.
class a {
protected $whatever;
function __construct() {
$this->whatever = function() {};
}
}
$b = new a();
$c = new a();
var_dump( $b == $c ); //false
Well you can't
serialize()closures straight on, but you can do a workaround, sinceserialize()invokes__sleep()when it's serializing objects, so it gives the object to option to clean things up! This what we're doing here:So now you can use
serialize()withmd5()to compare your objects like this:output: