Re: [RFC]
| From: | Rowan Tommins | Date: | Thu, 13 Feb 2020 17:26:28 +0000 |
| Subject: | Re: [RFC] | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108546@lists.php.net to get a copy of this message | ||
On Thu, 13 Feb 2020 at 17:06, Mike Schinkel <mike@newclarity.net> wrote:
> 1. IF foo::function returns a name string THEN using
> Closure::fromCallable( foo::function ) can provide a closure.
>
> 2. IF foo::function returns a closure THEN how to we get the name string?
>
Right, I'm with you now. However, I think the answer people are suggesting
to "how do we get the name string?" is "why do we need to?"
Or as Chase Peeler more eloquently put it:
> Can anyone think of a use-case where you would want a string name of a
> function and a callable would not be acceptable, besides possibly
debugging
> code that said 'echo "I'm calling ".myfunction::function;'? Everything
that
> I can think of that accepts a function name, also accepts a callable
(e.g.
> array_map), but I could be forgetting something.
There's a Venn diagram, essentially, of:
a) use cases where a Closure would be useful, but a string wouldn't
b) use cases where a string would be useful, but a Closure wouldn't
c) use cases where either a string or a Closure would be useful
If (and it's a genuine open question) all the use cases fall into
categories (a) and (c), we can make the syntax for closures simpler by
skipping the "get name" step and making foo::fn return a closure straight
away.
So the question is, are there use cases that fall into category (b)?
Regards,
--
Rowan Tommins
[IMSoP]