On Thu, Jul 1, 2021, at 10:14 AM, Ralph Schindler wrote:
> (Jump to bottom for alternative suggestion that achieves same goals)
> 
> 
> 
> > Just to make sure I got this right: call_user_func_map() is the same as 
> > call_user_func_array(), but a) only accepts named params
> 
> Yes, only accepts named parameters (associative array),
> 
> > and b) silently ignores unknown named params?
> I would characterize this as "explicitly doesn't pass unrequested 
> parameters"
> 
> > I'm not really convinced by your use-case here. This seems like a rather 
> > odd way to design an API, which goes against commonplace assumptions. If 
> 
> I didn't invest a lot of thought in the use case to make the argument, ha.
> 
> That said, I disagree with "odd way to design an API" sentiment...
> 
> This is a common idiom in a few different places found inside 
> frameworks. Laravel and Symfony both do named argument mapping when 
> dispatching controller actions. Additionally, both containers do a 
> significant amount of work with Reflection to map named arguments with 
> potential parameters.
> 
> I am not discrediting the fact that they don't also do more complex 
> stuff, but I think this supports the argument that this method of 
> parameters mapping does not go against commonplace assumptions.
> 
> Eg:
> https://github.com/symfony/http-kernel/blob/5.3/HttpKernel.php#L149-L157
> https://github.com/symfony/dependency-injection/search?q=reflectionMethod
> https://github.com/laravel/framework/blob/8.x/src/Illuminate/Container/Container.php#L649

What I don't understand is what the issue with that is?

You can already build up a named array and splat it into a function call to 
pass by name.  It's a really neat trick.  It doesn't need a dedicated function.

About a month ago, I went through all of TYPO3 and removed all remaining 
call_user_func_array() calls in favor of just $function(...$args), because it 
does the same thing and is faster, and easier to read.  Named arguments already 
work exactly that way, too.

I don't see an advantage to adding a function that does what you can already do 
with less syntax:

$args['foo'] = 5;
$args['beep'] = get_value_from_db();
$args['narf'] = 'poink';

$callable(...$args);

That works today in 8.0.  We're good.

--Larry Garfield

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to