Re: [RFC] Support for <func>::function syntax
| From: | Michael Voříšek - ČVUT FEL | Date: | Sun, 08 Nov 2020 08:38:15 +0000 |
| Subject: | Re: [RFC] Support for <func>::function syntax | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112204@lists.php.net to get a copy of this message | ||
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, as@php.net wrote:
Hello internals, Looking for feedback on the idea of supporting::functionsyntax (or::fn) for consistency with existing::classsyntax: $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 namedfunction. 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