A
A
ammorium2015-10-02 15:55:36
PHP
ammorium, 2015-10-02 15:55:36

How to find out the names of variables in a function?

How to know that the foo function requires exactly the variables "a" and "b", and not "x" and "y"

function foo($a, $b) {

}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Muhammad, 2015-10-02
@ammorium

If it is a class method, Reflection will do: php.net/manual/en/book.reflection.php , getParameters() method, if not, you can use this: https://github.com/nikic/PHP-Parser

S
Saboteur, 2015-10-02
@saboteur_kiev

The function does not require variable names, but parameters.
It will use variable names internally, denoting the data that you passed to it during execution.
In the example below, I am calling the foo function with x,y arguments. The function itself will be called and the values ​​stored in x and y will be interpreted as a, b, because it does not know what xy is
x=1
y=2
foo(x,y)
function foo (a, b)
{
print a, b
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question