Today, I learnt named arguments in PHP but I have a question regarding how to use them dynamically. I mean generating the arguments object. Here is the example
function getVar(
String $a = null,
String $b = null,
String $c = null
){
///EXAMPLE FUNCTION
}
Then, if we want to call the function we should do
$this->getVar(a: 'test',b:'test',c: 'test');
So, I have question, how do we call the argument objects from creating object
$object = {
'a'=>'test',
'b'=>'test',
}
//Whenever I want to add 'c' it is possible to add dynamically
if($user=='admin') $object['c'] = 'test'
$this->getVar($object);
I want to achieve how the code above works. I have no idea is it possible or not because there are many condition and I need to generate the variable based on the needs of user input, I cannot make the way to call the function being static or creating many condition.
I am thinking the only way to do it is to separate it into a json object and send to function. Then, we decode and read the variable inside its function.