Re: Introduce the abiltiy to use the first-call-callable syntax on non-static methods, statically
| From: | Ollie Read | Date: | Tue, 24 Jan 2023 11:05:29 +0000 |
| Subject: | Re: Introduce the abiltiy to use the first-call-callable syntax on non-static methods, statically | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119413@lists.php.net to get a copy of this message | ||
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*