On Tue, 11 Feb 2020 at 15:51, Chase Peeler <chasepee...@gmail.com> wrote: > > > > On Tue, Feb 11, 2020 at 8:19 AM Nikita Popov <nikita....@gmail.com> wrote: >> >> On Tue, Feb 11, 2020 at 1:43 PM Manuel Canga <manuelca...@gmail.com> wrote: >> >> > On Tue, 11 Feb 2020 at 13:16, Nicolas Grekas >> > <nicolas.grekas+...@gmail.com> wrote: >> > > >> > > >> > > >> > > Le mar. 11 févr. 2020 à 12:52, Diogo Galvao <diog...@gmail.com> a écrit >> > : >> > >> >> > >> On Tue, Feb 11, 2020 at 8:14 AM Manuel Canga <manuelca...@gmail.com> >> > wrote: >> > >> > >> > >> > Hi internals, >> > >> > I Would like to present a possible new "::func resolution" for your >> > >> > consideration. >> > >> ... >> > >> > use function \My\I18N\i18n_translate; >> > >> > >> > >> > $mapped_array = array_map(i18n_translate::func, $array); >> > >> ... >> > >> > What is your opinion ? Do you see it useful ? >> > >> >> > >> I've wished for this on many occasions and think it'd be really useful, >> > as long >> > >> as it could work with methods as well: >> > >> >> > >> $mapped_array = array_map(I18N::translate::function, $array); >> > >> >> > >> For what it's worth I guess it could just return [I18N::class, >> > 'translate']. >> > > >> > > >> > > I wish this would return a Closure instead, making $foo::function the >> > equivalent of Closure::fromCallable($foo). >> > >> > Hi, Nicolas, >> > >> > Currently, when <class_name>::class is used, class with <class_name> >> > can or cannot exists in that moment. >> > Using <function_name>::func( or <function_name>::function ), I think >> > should keep the same behavior. >> > >> > Using ::func as alias of "Closure::fromCallable" check if function >> > exists in that moment. It is certainly useful, but, I think it's more >> > important be consistent >> > >> >> Checking whether the function exists is really unavoidable for functions, >> because you don't know whether >> >> namespace Foo; >> var_dump(strlen::function); >> >> refers to 'Foo\strlen' or 'strlen', without first trying to look up the >> former. >> >> I agree with Nicolas that this kind of feature would provide the most value >> if it created a Closure. This would circumvent all the issues outlined in >> https://wiki.php.net/rfc/consistent_callables. >> >> Regards, >> Nikita > > > Can anyone thing 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. > > If not, then I think it makes sense to return a callable. It might not be > entirely consistent with the behavior of ::class, but, a class isn't entirely > consistent with a method/function either, so I think there is some latitude > for small differences. > > As for the ::func vs ::function. I think ::function is safer, since it's a > reserved word. Otherwise you might run into issues with something like this: > > class foo { > const func = "bar"; > } > > function foo(){} > > echo foo::func; > > Probably not something that happens very often, but, I think the 4 extra > characters to prevent it would be worth it. > > -- > Chase Peeler > chasepee...@gmail.com
Hi, Chase, Yes, '::function' is better. I don't know because I thought 'func' was used with short functions. One case which string can be useful but a callable would not be acceptable is: array_map([I18N::class, translate::function] ); Although it's true that can have side effects. Thanks, Chase, -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php