Hi, what about resolving directly to Closure? strtoupper::function === \Closure::fromCallable('strtoupper'). $this->method::function === \Closure::fromCallable([$this, 'method']).
With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem,

Michael Voříšek

On 8 Nov 2020 00:41, a...@php.net wrote:

Hello internals,

Looking for feedback on the idea of supporting `::function` syntax (or
`::fn`) for consistency with existing `::class` syntax:

$arr = ['apple'];
print_r(array_map(strtoupper::function, $arr));

(Apologies if this has already been discussed. Hard to search for
colon-colon-function.)

Benefits in my view are readability and potential use in static analysis.
Downsides (as implemented in proof-of-concept) are that it can be
needlessly littered in a lot of places, and that it breaks class consts
named `function`. I'd vote against it in its current state, but if people
like the general idea maybe the drawbacks can be addressed with a better
implementation.

Examples:
https://gist.github.com/adsr/2c0b9243986418af3cecf8046657304b

Proof-of-concept:
https://github.com/adsr/php-src/commit/07bb24243022ccef5823f6977d231f3535a48a07.patch

Adam

Reply via email to