Re: Introduce the abiltiy to use the first-call-callable syntax on non-static methods, statically
| From: | Larry Garfield | Date: | Mon, 23 Jan 2023 17:26:45 +0000 |
| Subject: | Re: Introduce the abiltiy to use the first-call-callable syntax on non-static methods, statically | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119403@lists.php.net to get a copy of this message | ||
On Mon, Jan 23, 2023, at 10:08 AM, Robert Landers wrote:
> In my mind, Test::Func(...) should be treated the same as ['Test',
> 'Func'] or 'Test::Func' until it is called and if some fancy framework
> wants to do something special with the closure, it can do so. FWIW, I
> didn't even know this syntax checked anything until today. I can think
> of a number of cases where delaying the error to actual execution is
> beneficial.
>
> 1. Just because the method/object doesn't exist, doesn't mean it won't
> exist by the time it is called -- this is PHP after all.
> 2. I can have a file with 100 million of these things without
> triggering any autoloading.
> 3. PHPStorm currently doesn't trigger this syntax as an error.
This ship has long since sailed. Test::func(...) produces a \Callable object, using the
Closure::fromCallable() mechanism internally. One important advantage (and why Nikita favored it
over most other callable syntaxes) is that it respects scope visibility better than passing around a
buncha strings.
Changing that at this point is a major API break that is not going to happen.
--Larry Garfield