Для передачи ссылкой с помощью call_user_func_array()
параметр в массиве должен быть ссылкой - это не зависит от функционального определения, передается ли это ссылкой. Например, это работало бы:
function toBeCalled( &$parameter ) {
//...Do Something...
}
$changingVar = 'passThis';
$parameters = array( &$changingVar );
call_user_func_array( 'toBeCalled', $parameters );
См. примечания по call_user_func_array()
функциональная документация для получения дополнительной информации.
Yes. You do it like this:
def method(**kwargs):
print kwargs
keywords = {'keyword1': 'foo', 'keyword2': 'bar'}
method(keyword1='foo', keyword2='bar')
method(**keywords)
Running this in Python confirms these produce identical results:
{'keyword2': 'bar', 'keyword1': 'foo'}
{'keyword2': 'bar', 'keyword1': 'foo'}
As others have pointed out, you can do what you want by passing a dict. There are various ways to construct a dict. One that preserves the keyword=value
style you attempted is to use the dict built-in:
keywords = dict(keyword1 = 'foo', keyword2 = 'bar')
Note the versatility of dict
; all of these produce the same result:
>>> kw1 = dict(keyword1 = 'foo', keyword2 = 'bar')
>>> kw2 = dict({'keyword1':'foo', 'keyword2':'bar'})
>>> kw3 = dict([['keyword1', 'foo'], ['keyword2', 'bar']])
>>> kw4 = dict(zip(('keyword1', 'keyword2'), ('foo', 'bar')))
>>> assert kw1 == kw2 == kw3 == kw4
>>>
Do you mean a dict? Sure you can:
def method(**kwargs):
#do something
keywords = {keyword1: 'foo', keyword2: 'bar'}
method(**keywords)