Getting a unique id for a function object in PHP 5.3 [closed]
質問
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
所属していません StackOverflow