doc-en icon indicating copy to clipboard operation
doc-en copied to clipboard

Where should I document Closure and ==?

Open chx opened this issue 5 months ago • 3 comments

I have commit rights to the repo so I just need guidance where should I document two closures made from the same callable are equal but not identical:

$x = new class {
    function test() {}
};
$a = [$x, 'test'];
$b = Closure::fromCallable($a);
$c = Closure::fromCallable($a);
var_dump($b == $c);  // TRUE
var_dump($b === $c); // FALSE

This is used in Symfony eventdispatcher: if ($v === $listener || ($listener instanceof \Closure && $v == $listener)) { I guess because this makes removeListener($foo(..)) work

I really have no idea where is it best to document this. https://www.php.net/manual/en/language.oop5.object-comparison.php ? Closure::fromCallable ? first class functions?

chx avatar Aug 02 '25 00:08 chx