Re: [RFC] Support for <func>::function syntax
| From: | Rowan Tommins | Date: | Sun, 08 Nov 2020 17:42:53 +0000 |
| Subject: | Re: [RFC] Support for <func>::function syntax | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112212@lists.php.net to get a copy of this message | ||
On 08/11/2020 02:12, Larry Garfield wrote:
There was some discussion earlier this year, although if memory serves it was in a thread whose name would not be helpful for searching.Here it is: https://externals.io/message/108459 Some of the key points (not an exhaustive summary): - Looking up a function's fully-qualified name would need to check at run-time for the function's existence, since there are two possibilities for any name that's not already fully-qualified ('foo' and 'current\namespace\foo'). This is different from ::class which (in most cases) resolves the expression to a name at compile-time based on current imports, and can resolve to a completely non-existent name. There are cases where it resolves at run-time [see https://wiki.php.net/rfc/class_name_literal_on_object] but none have the case of "valid name but no such class defined", which would need to be handled for functions. - There was some discussion about the usefulness of returning the name, or a callable object, or some way of providing both. Suggestions included adding two new syntaxes, ::function and ::closure; simplifying the creation of a callable object from a string; or returning an object from which the name could be retrieved. - Should (and could) the new syntax work with methods as well, e.g. Foo::bar::function and $foo->bar::function. If foo::function returns a string, these would logically need to return ['Fully\Qualified\Name\Of\Foo', 'bar'] and [$foo, 'bar'] respectively; if it (or a variant of it) returns a Closure, it would be the (optimized) equivalent of passing those to Closure::fromCallable. Regards, -- Rowan Tommins (né Collins) [IMSoP]