You're absolutely correct, the problem I was trying to solve was the ability to 
reference a method without throwing around magic strings, apologies if that 
wasn't clear.

The whole idea, or rather, need/want for it came about because of time spent 
with Javas functional side, though I understand that's safer to do because of 
the way Java handles type safety.

The ::class pseudo type is great for providing a classes FQN, and class-string 
is great for ensuring values are valid class strings when using static 
analysis, but we don't have anything for methods, outside of IDE completion.

The solution wouldn't even need to generate a closure, TBH, it would generate 
something that could then be used in the same manner.

Using the current features of PHP, I'd probably imagine something that does 
just about the same as this:

$method = new ReflectionMethod(MyClass::class, 'method');

$collection->filter($method);

Where the filter method does:

foreach ($items as $item) {
    if ($method->invoke($item)) {
        //
    }
}

Although reflection doesn't have the overhead that everyone thinks it does, 
this is a less than ideal solution, but I think it accurately portrays what I'm 
looking for.

---
Best Regards,
*Ollie Read*

Reply via email to