質問

I have tried using spl_object_hash, however it apparently doesn't work with function objects.

So how can this best be done?

役に立ちましたか?

解決

A function object is an object like any other. spl_object_hash should work for them as well. I also cannot find any reference in the documentation about this not working.

I actually tried it, and it seems to work just fine:

<?php
class x
{
    function __invoke()
    {
        return 'Test';
    }
}

$x = new x;
echo $x(); // Test
echo spl_object_hash($x); // The hash
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top