0

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

So how can this best be done?

back2dos
  • 15,588
  • 34
  • 50

1 Answers1

1

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
GolezTrol
  • 114,394
  • 18
  • 182
  • 210