Frage

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

So how can this best be done?

War es hilfreich?

Lösung

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top